Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
denise 2012-08-22 16:02:02 -04:00
commit 6fec9b0301
7 changed files with 133 additions and 55 deletions

View File

@ -7,9 +7,6 @@ require_once 'formatters/BitrateFormatter.php';
class LibraryController extends Zend_Controller_Action
{
protected $obj_sess = null;
protected $search_sess = null;
public function init()
{
$ajaxContext = $this->_helper->getHelper('AjaxContext');
@ -23,8 +20,6 @@ class LibraryController extends Zend_Controller_Action
->addActionContext('set-num-entries', 'json')
->initContext();
$this->obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
$this->search_sess = new Zend_Session_Namespace("search");
}
public function indexAction()
@ -59,32 +54,90 @@ class LibraryController extends Zend_Controller_Action
try {
if (isset($this->obj_sess->id)) {
Logging::info($this->obj_sess->type);
$obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
//Application_Model_Library::changePlaylist(null, null);
if (isset($obj_sess->id)) {
Logging::info($obj_sess->type);
$objInfo = Application_Model_Library::getObjInfo($this->obj_sess->type);
Logging::info($this->obj_sess->id);
$obj = new $objInfo['className']($this->obj_sess->id);
Logging::info($obj_sess->id);
$obj = new $objInfo['className']($obj_sess->id);
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new Application_Model_User($userInfo->id);
$isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
if ($isAdminOrPM || $obj->getCreatorId() == $userInfo->id) {
$this->view->obj = $obj;
if ($this->obj_sess->type == "block") {
if ($obj_sess->type == "block") {
$form = new Application_Form_SmartBlockCriteria();
$form->startForm($this->obj_sess->id);
$form->startForm($obj_sess->id);
$this->view->form = $form;
}
}
$formatter = new LengthFormatter($obj->getLength());
$this->view->length = $formatter->format();
$this->view->type = $this->obj_sess->type;
$this->view->type = $obj_sess->type;
}
} catch (PlaylistNotFoundException $e) {
$this->playlistNotFound($this->obj_sess->type);
$this->playlistNotFound($obj_sess->type);
} catch (Exception $e) {
$this->playlistUnknownError($e);
$this->playlistNotFound($obj_sess->type);
//$this->playlistUnknownError($e);
}
}
protected function playlistNotFound($p_type)
{
$this->view->error = "{$p_type} not found";
Logging::info("{$p_type} not found");
Application_Model_Library::changePlaylist(null, $p_type);
$this->createFullResponse(null);
}
protected function playlistUnknownError($e)
{
$this->view->error = "Something went wrong.";
Logging::info("{$e->getFile()}");
Logging::info("{$e->getLine()}");
Logging::info("{$e->getMessage()}");
}
protected function createFullResponse($obj = null, $isJson = false)
{
$isBlock = false;
$viewPath = 'playlist/playlist.phtml';
if ($obj instanceof Application_Model_Block) {
$isBlock = true;
$viewPath = 'playlist/smart-block.phtml';
}
if (isset($obj)) {
$formatter = new LengthFormatter($obj->getLength());
$this->view->length = $formatter->format();
if ($isBlock) {
$form = new Application_Form_SmartBlockCriteria();
$form->removeDecorator('DtDdWrapper');
$form->startForm($obj->getId());
$this->view->form = $form;
$this->view->obj = $obj;
$this->view->id = $obj->getId();
if ($isJson) {
return $this->view->render($viewPath);
} else {
$this->view->html = $this->view->render($viewPath);
}
} else {
$this->view->obj = $obj;
$this->view->id = $obj->getId();
$this->view->html = $this->view->render($viewPath);
unset($this->view->obj);
}
} else {
$this->view->html = $this->view->render($viewPath);
}
}
@ -111,17 +164,18 @@ class LibraryController extends Zend_Controller_Action
$file = Application_Model_StoredFile::Recall($id);
if (isset($this->obj_sess->id) && $screen == "playlist") {
$obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
if (isset($obj_sess->id) && $screen == "playlist") {
// if the user is not admin or pm, check the creator and see if this person owns the playlist or Block
if ($this->obj_sess->type == 'playlist') {
$obj = new Application_Model_Playlist($this->obj_sess->id);
if ($obj_sess->type == 'playlist') {
$obj = new Application_Model_Playlist($obj_sess->id);
} else {
$obj = new Application_Model_Block($this->obj_sess->id);
$obj = new Application_Model_Block($obj_sess->id);
}
if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
if ($this->obj_sess->type === "playlist") {
if ($obj_sess->type === "playlist") {
$menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "add-playlist", "icon" => "copy");
} else if ($this->obj_sess->type === "block") {
} else if ($obj_sess->type === "block") {
$menu["pl_add"] = array("name"=> "Add to Smart Block", "icon" => "add-playlist", "icon" => "copy");
}
}
@ -142,13 +196,13 @@ class LibraryController extends Zend_Controller_Action
unset($menu["play"]);
}
if (($isAdminOrPM || $obj->getCreatorId() == $user->getId()) && $screen == "playlist") {
if ($this->obj_sess->type === "playlist") {
if ($obj_sess->type === "playlist") {
$menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "add-playlist", "icon" => "copy");
}
}
}
if ($this->obj_sess->id !== $id && $screen == "playlist") {
if ($obj_sess->id !== $id && $screen == "playlist") {
if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
$menu["edit"] = array("name"=> "Edit", "icon" => "edit");
}
@ -160,9 +214,9 @@ class LibraryController extends Zend_Controller_Action
$webstream = CcWebstreamQuery::create()->findPK($id);
$obj = new Application_Model_Webstream($webstream);
if (isset($this->obj_sess->id) && $screen == "playlist") {
if (isset($obj_sess->id) && $screen == "playlist") {
if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
if ($this->obj_sess->type === "playlist") {
if ($obj_sess->type === "playlist") {
$menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "add-playlist", "icon" => "copy");
}
}

View File

@ -2,7 +2,6 @@
class PlaylistController extends Zend_Controller_Action
{
protected $obj_sess = null;
public function init()
{
@ -28,7 +27,6 @@ class PlaylistController extends Zend_Controller_Action
->addActionContext('get-block-info', 'json')
->initContext();
$this->obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
}
private function getPlaylist($p_type)
@ -36,8 +34,9 @@ class PlaylistController extends Zend_Controller_Action
$obj = null;
$objInfo = Application_Model_Library::getObjInfo($p_type);
if (isset($this->obj_sess->id)) {
$obj = new $objInfo['className']($this->obj_sess->id);
$obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
if (isset($obj_sess->id)) {
$obj = new $objInfo['className']($obj_sess->id);
$modified = $this->_getParam('modified', null);
if ($obj->getLastModified("U") !== $modified) {
@ -205,14 +204,17 @@ class PlaylistController extends Zend_Controller_Action
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new Application_Model_User($userInfo->id);
$obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
try {
Logging::info("Currently active {$type} {$this->obj_sess->id}");
if (in_array($this->obj_sess->id, $ids)) {
Logging::info("Currently active {$type} {$obj_sess->id}");
if (in_array($obj_sess->id, $ids)) {
Logging::info("Deleting currently active {$type}");
Application_Model_Library::changePlaylist(null, $type);
} else {
Logging::info("Not deleting currently active {$type}");
$obj = new $objInfo['className']($this->obj_sess->id);
$obj = new $objInfo['className']($obj_sess->id);
}
if (strcmp($objInfo['className'], 'Application_Model_Playlist')==0) {

View File

@ -238,7 +238,7 @@ class ScheduleController extends Zend_Controller_Action
}
$isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
$isDJ = $user->isHost($instance->getShowId());
$isDJ = $user->isHostOfShow($instance->getShowId());
$showStartLocalDT = Application_Common_DateHelper::ConvertToLocalDateTime($instance->getShowInstanceStart());
$showEndLocalDT = Application_Common_DateHelper::ConvertToLocalDateTime($instance->getShowInstanceEnd());
@ -338,7 +338,7 @@ class ScheduleController extends Zend_Controller_Action
return false;
}
if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST),$show->getShowId()))
if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER) && $user->isHostOfShow($show->getShowId())))
$show->clearShow();
}
@ -403,7 +403,7 @@ class ScheduleController extends Zend_Controller_Action
return false;
}
if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST),$show->getShowId())) {
if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER) && $user->isHostOfShow($show->getShowId()))) {
$show->removeGroupFromShow($group_id);
}
@ -543,7 +543,7 @@ class ScheduleController extends Zend_Controller_Action
}
$isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
$isDJ = $user->isHost($showInstance->getShowId());
$isDJ = $user->isHostOfShow($showInstance->getShowId());
if (!($isAdminOrPM || $isDJ)) {
return;

View File

@ -16,10 +16,15 @@ class WebstreamController extends Zend_Controller_Action
{
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
if (!$this->isAuthorized(-1)) {
header("Status: 401 Not Authorized");
return;
}
$webstream = new CcWebstream();
//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->setDbDescription("");
$webstream->setDbUrl("http://");
@ -28,8 +33,9 @@ class WebstreamController extends Zend_Controller_Action
$webstream->setDbCreatorId($userInfo->id);
$webstream->setDbUtime(new DateTime("now", new DateTimeZone('UTC')));
$webstream->setDbMtime(new DateTime("now", new DateTimeZone('UTC')));
$webstream->save();
//$webstream->save();
/*
$type = "stream";
$objInfo = Application_Model_Library::getObjInfo($type);
@ -39,6 +45,7 @@ class WebstreamController extends Zend_Controller_Action
$type = "stream";
Application_Model_Library::changePlaylist($obj->getId(), $type);
*/
$this->view->obj = new Application_Model_Webstream($webstream);
$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;
$user = Application_Model_User::getCurrentUser();
@ -89,15 +96,18 @@ class WebstreamController extends Zend_Controller_Action
$hasPermission = true;
}
if (!$hasPermission) {
if ($id != -1) {
$webstream = CcWebstreamQuery::create()->findPK($id);
if ($user->isHost()) {
if ($webstream_id != -1) {
$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.
$user = Application_Model_User::getCurrentUser();
if ($webstream->getDbCreatorId() == $user->getId()) {
$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();
$user = Application_Model_User::getCurrentUser();
$hasPermission = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST));
$id = $request->getParam("id");
$parameters = array();
@ -131,6 +137,9 @@ class WebstreamController extends Zend_Controller_Action
try {
if (Application_Model_Webstream::isValid($analysis)) {
$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->streamId = $streamId;
} else {

View File

@ -11,5 +11,13 @@ class RabbitMqPlugin extends Zend_Controller_Plugin_Abstract
Application_Model_RabbitMq::SendMessageToShowRecorder("update_recorder_schedule");
}
}
if (memory_get_peak_usage() > 25*pow(2, 20)) {
Logging::debug("Peak memory usage: "
.(memory_get_peak_usage()/1000000)
." MB while accessing URI ".$_SERVER['REQUEST_URI']);
Logging::debug("Should try to keep memory footprint under 25 MB");
}
}
}

View File

@ -32,9 +32,17 @@ class Application_Model_User
return $this->getType() == UTYPE_GUEST;
}
public function isHostOfShow($showId)
{
$userId = $this->_userInstance->getDbId();
return CcShowHostsQuery::create()
->filterByDbShow($showId)
->filterByDbHost($userId)->count() > 0;
}
public function isHost($showId)
{
return $this->isUserType(UTYPE_HOST, $showId);
return $this->isUserType(UTYPE_HOST);
}
public function isPM()
@ -61,7 +69,7 @@ class Application_Model_User
return $result;
}
public function isUserType($type, $showId='')
public function isUserType($type)
{
if (is_array($type)) {
$result = false;
@ -71,10 +79,7 @@ class Application_Model_User
$result = $this->_userInstance->getDbType() === 'A';
break;
case UTYPE_HOST:
$userId = $this->_userInstance->getDbId();
$result = CcShowHostsQuery::create()
->filterByDbShow($showId)
->filterByDbHost($userId)->count() > 0;
$result = $this->_userInstance->getDbType() === 'H';
break;
case UTYPE_PROGRAM_MANAGER:
$result = $this->_userInstance->getDbType() === 'P';
@ -89,9 +94,7 @@ class Application_Model_User
case UTYPE_ADMIN:
return $this->_userInstance->getDbType() === 'A';
case UTYPE_HOST:
$userId = $this->_userInstance->getDbId();
return CcShowHostsQuery::create()->filterByDbShow($showId)->filterByDbHost($userId)->count() > 0;
return $this->_userInstance->getDbId() === 'H';
case UTYPE_PROGRAM_MANAGER:
return $this->_userInstance->getDbType() === 'P';
}

View File

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