CC-1665: Scheduled stream rebroadcasting and recording

-change behaviour so that the webstream is not saved as soon as it it created.
This commit is contained in:
Martin Konecny 2012-08-22 14:04:01 -04:00
parent 24988616b3
commit c8c257a330
2 changed files with 22 additions and 11 deletions

View file

@ -16,10 +16,15 @@ class WebstreamController extends Zend_Controller_Action
{ {
$userInfo = Zend_Auth::getInstance()->getStorage()->read(); $userInfo = Zend_Auth::getInstance()->getStorage()->read();
if (!$this->isAuthorized(-1)) {
header("Status: 401 Not Authorized");
return;
}
$webstream = new CcWebstream(); $webstream = new CcWebstream();
//we're not saving this primary key in the DB so it's OK //we're not saving this primary key in the DB so it's OK
//$webstream->setDbId(-1); $webstream->setDbId(-1);
$webstream->setDbName("Untitled Webstream"); $webstream->setDbName("Untitled Webstream");
$webstream->setDbDescription(""); $webstream->setDbDescription("");
$webstream->setDbUrl("http://"); $webstream->setDbUrl("http://");
@ -28,8 +33,9 @@ class WebstreamController extends Zend_Controller_Action
$webstream->setDbCreatorId($userInfo->id); $webstream->setDbCreatorId($userInfo->id);
$webstream->setDbUtime(new DateTime("now", new DateTimeZone('UTC'))); $webstream->setDbUtime(new DateTime("now", new DateTimeZone('UTC')));
$webstream->setDbMtime(new DateTime("now", new DateTimeZone('UTC'))); $webstream->setDbMtime(new DateTime("now", new DateTimeZone('UTC')));
$webstream->save(); //$webstream->save();
/*
$type = "stream"; $type = "stream";
$objInfo = Application_Model_Library::getObjInfo($type); $objInfo = Application_Model_Library::getObjInfo($type);
@ -39,6 +45,7 @@ class WebstreamController extends Zend_Controller_Action
$type = "stream"; $type = "stream";
Application_Model_Library::changePlaylist($obj->getId(), $type); Application_Model_Library::changePlaylist($obj->getId(), $type);
*/
$this->view->obj = new Application_Model_Webstream($webstream); $this->view->obj = new Application_Model_Webstream($webstream);
$this->view->action = "new"; $this->view->action = "new";
@ -81,7 +88,7 @@ class WebstreamController extends Zend_Controller_Action
} }
public function isAuthorized($id) public function isAuthorized($webstream_id)
{ {
$hasPermission = false; $hasPermission = false;
$user = Application_Model_User::getCurrentUser(); $user = Application_Model_User::getCurrentUser();
@ -89,15 +96,18 @@ class WebstreamController extends Zend_Controller_Action
$hasPermission = true; $hasPermission = true;
} }
if (!$hasPermission) { if ($user->isHost()) {
if ($id != -1) { if ($webstream_id != -1) {
$webstream = CcWebstreamQuery::create()->findPK($id); $webstream = CcWebstreamQuery::create()->findPK($webstream_id);
//we are updating a playlist. Ensure that if the user is a host/dj, that he has the correct permission. //we are updating a playlist. Ensure that if the user is a host/dj, that he has the correct permission.
$user = Application_Model_User::getCurrentUser(); $user = Application_Model_User::getCurrentUser();
if ($webstream->getDbCreatorId() == $user->getId()) { if ($webstream->getDbCreatorId() == $user->getId()) {
$hasPermission = true; $hasPermission = true;
} }
} else {
//we are creating a new stream. Don't need to check whether the DJ/Host owns the stream
$hasPermission = true;
} }
} }
@ -108,10 +118,6 @@ class WebstreamController extends Zend_Controller_Action
{ {
$request = $this->getRequest(); $request = $this->getRequest();
$user = Application_Model_User::getCurrentUser();
$hasPermission = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST));
$id = $request->getParam("id"); $id = $request->getParam("id");
$parameters = array(); $parameters = array();
@ -131,6 +137,9 @@ class WebstreamController extends Zend_Controller_Action
try { try {
if (Application_Model_Webstream::isValid($analysis)) { if (Application_Model_Webstream::isValid($analysis)) {
$streamId = Application_Model_Webstream::save($parameters, $mime, $di); $streamId = Application_Model_Webstream::save($parameters, $mime, $di);
Application_Model_Library::changePlaylist($streamId, "stream");
$this->view->statusMessage = "<div class='success'>Webstream saved.</div>"; $this->view->statusMessage = "<div class='success'>Webstream saved.</div>";
$this->view->streamId = $streamId; $this->view->streamId = $streamId;
} else { } else {

View file

@ -7,9 +7,11 @@ class Application_Model_Webstream implements Application_Model_LibraryEditable
public function __construct($webstream) public function __construct($webstream)
{ {
//TODO: hacky... //TODO: hacky...
Logging::info("x ".$webstream);
if (is_int($webstream)) { if (is_int($webstream)) {
$this->webstream = CcWebstreamQuery::create()->findPK($webstream); $this->webstream = CcWebstreamQuery::create()->findPK($webstream);
if (is_null($this->webstream)) {
throw new Exception();
}
} else { } else {
$this->webstream = $webstream; $this->webstream = $webstream;
} }