diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index 5bd5949de..a1a4edd82 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -176,7 +176,7 @@ class LibraryController extends Zend_Controller_Action if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) { if ($obj_sess->type === "playlist") { $menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "add-playlist", "icon" => "copy"); - } elseif ($obj_sess->type === "block") { + } elseif ($obj_sess->type === "block" && $obj->isStatic()) { $menu["pl_add"] = array("name"=> "Add to Smart Block", "icon" => "add-playlist", "icon" => "copy"); } } diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php index 38dbd4fd2..0d2ead443 100644 --- a/airtime_mvc/application/controllers/PlaylistController.php +++ b/airtime_mvc/application/controllers/PlaylistController.php @@ -513,7 +513,7 @@ class PlaylistController extends Zend_Controller_Action } catch (BlockNotFoundException $e) { $this->playlistNotFound('block', true); } catch (Exception $e) { - //Logging::info($e); + Logging::info($e); $this->playlistUnknownError($e); } } diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php index 0f4188443..7ab568144 100644 --- a/airtime_mvc/application/controllers/PreferenceController.php +++ b/airtime_mvc/application/controllers/PreferenceController.php @@ -65,13 +65,12 @@ class PreferenceController extends Zend_Controller_Action $this->view->headScript()->appendFile($baseUrl.'/js/airtime/preferences/support-setting.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->statusMsg = ""; - $isSass = Application_Model_Preference::GetPlanLevel() == 'disabled'?false:true; $form = new Application_Form_SupportSettings(); if ($request->isPost()) { $values = $request->getPost(); if ($form->isValid($values)) { - if (!$isSass && $values["Publicise"] != 1) { + if ($values["Publicise"] != 1) { Application_Model_Preference::SetSupportFeedback($values["SupportFeedback"]); Application_Model_Preference::SetPublicise($values["Publicise"]); if (isset($values["Privacy"])) { @@ -82,10 +81,8 @@ class PreferenceController extends Zend_Controller_Action Application_Model_Preference::SetPhone($values["Phone"]); Application_Model_Preference::SetEmail($values["Email"]); Application_Model_Preference::SetStationWebSite($values["StationWebSite"]); - if (!$isSass) { Application_Model_Preference::SetSupportFeedback($values["SupportFeedback"]); Application_Model_Preference::SetPublicise($values["Publicise"]); - } $form->Logo->receive(); $imagePath = $form->Logo->getFileName(); @@ -94,7 +91,7 @@ class PreferenceController extends Zend_Controller_Action Application_Model_Preference::SetStationCity($values["City"]); Application_Model_Preference::SetStationDescription($values["Description"]); Application_Model_Preference::SetStationLogo($imagePath); - if (!$isSass && isset($values["Privacy"])) { + if (isset($values["Privacy"])) { Application_Model_Preference::SetPrivacyPolicyCheck($values["Privacy"]); } } diff --git a/airtime_mvc/application/forms/SupportSettings.php b/airtime_mvc/application/forms/SupportSettings.php index 0a9453c52..aeda6d7ed 100644 --- a/airtime_mvc/application/forms/SupportSettings.php +++ b/airtime_mvc/application/forms/SupportSettings.php @@ -105,7 +105,6 @@ class Application_Form_SupportSettings extends Zend_Form $upload->setAttrib('accept', 'image/*'); $this->addElement($upload); - if (!$isSass) { //enable support feedback $this->addElement('checkbox', 'SupportFeedback', array( 'label' => 'Send support feedback', @@ -146,7 +145,6 @@ class Application_Form_SupportSettings extends Zend_Form $checkboxPrivacy->setLabel("By checking this box, I agree to Sourcefabric's privacy policy.") ->setDecorators(array('ViewHelper')); $this->addElement($checkboxPrivacy); - } // submit button $submit = new Zend_Form_Element_Submit("submit"); @@ -161,7 +159,6 @@ class Application_Form_SupportSettings extends Zend_Form public function isValid ($data) { $isValid = parent::isValid($data); - if (!$this->isSass) { if ($data['Publicise'] != 1) { $isValid = true; } @@ -172,7 +169,6 @@ class Application_Form_SupportSettings extends Zend_Form $isValid = false; } } - } return $isValid; } diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php index 57018ad5f..c06b24cb8 100644 --- a/airtime_mvc/application/models/Block.php +++ b/airtime_mvc/application/models/Block.php @@ -210,10 +210,23 @@ FROM cc_blockcontents AS pc LEFT JOIN cc_files AS f ON pc.file_id=f.id LEFT JOIN cc_block AS bl ON pc.block_id = bl.id WHERE pc.block_id = :block_id -ORDER BY pc.position + SQL; - $rows = Application_Common_Database::prepareAndExecute($sql, array(':block_id'=>$this->id)); + if ($filterFiles) { + $sql .= <<$this->id); + if ($filterFiles) { + $params[':file_exists'] = $filterFiles; + } + $rows = Application_Common_Database::prepareAndExecute($sql, $params); $offset = 0; foreach ($rows as &$row) { @@ -310,6 +323,7 @@ SQL; $hour = "00"; $mins = "00"; if ($modifier == "minutes") { + $mins = $value; if ($value >59) { $hour = intval($value/60); $mins = $value%60; @@ -1177,7 +1191,7 @@ SQL; $sizeOfInsert = count($insertList); // if block is not full and reapeat_track is check, fill up more - while (!$isBlockFull && $repeat == 1) { + while (!$isBlockFull && $repeat == 1 && $sizeOfInsert > 0) { $randomEleKey = array_rand(array_slice($insertList, 0, $sizeOfInsert)); $insertList[] = $insertList[$randomEleKey]; $totalTime += $insertList[$randomEleKey]['length']; diff --git a/airtime_mvc/application/models/Playlist.php b/airtime_mvc/application/models/Playlist.php index c99fbb019..f70012b73 100644 --- a/airtime_mvc/application/models/Playlist.php +++ b/airtime_mvc/application/models/Playlist.php @@ -176,6 +176,14 @@ class Application_Model_Playlist implements Application_Model_LibraryEditable FROM cc_playlistcontents AS pc JOIN cc_files AS f ON pc.file_id=f.id WHERE pc.playlist_id = :playlist_id1 +SQL; + + if ($filterFiles) { + $sql .= <<$this->id, ':playlist_id2'=>$this->id, ':playlist_id3'=>$this->id)); + $params = array( + ':playlist_id1'=>$this->id, ':playlist_id2'=>$this->id, ':playlist_id3'=>$this->id); + if ($filterFiles) { + $params[':file_exists'] = $filterFiles; + } + + $rows = Application_Common_Database::prepareAndExecute($sql, $params); $offset = 0; foreach ($rows as &$row) { diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index 356210b74..80f7ded9e 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -193,7 +193,8 @@ class Application_Model_Scheduler } } else { $dynamicFiles = $bl->getListOfFilesUnderLimit(); - foreach ($dynamicFiles as $fileId=>$f) { + foreach ($dynamicFiles as $f) { + $fileId = $f['id']; $file = CcFilesQuery::create()->findPk($fileId); if (isset($file) && $file->getDbFileExists()) { $data["id"] = $file->getDbId(); @@ -250,7 +251,8 @@ class Application_Model_Scheduler } } else { $dynamicFiles = $bl->getListOfFilesUnderLimit(); - foreach ($dynamicFiles as $fileId=>$f) { + foreach ($dynamicFiles as $f) { + $fileId = $f['id']; $file = CcFilesQuery::create()->findPk($fileId); if (isset($file) && $file->getDbFileExists()) { $data["id"] = $file->getDbId(); @@ -445,7 +447,6 @@ class Application_Model_Scheduler } else { $sched = new CcSchedule(); } - Logging::info($file); $sched->setDbStarts($nextStartDT) ->setDbEnds($endTimeDT) ->setDbCueIn($file['cuein']) diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 51693f46d..fb924ac5c 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -359,9 +359,26 @@ SQL; Application_Model_RabbitMq::SendMessageToMediaMonitor("file_delete", $data); } - // set file_exists falg to false + // set file_exists flag to false $this->_file->setDbFileExists(false); $this->_file->save(); + + // need to explicitly update any playlist's and block's length + // that contains the file getting deleted + $fileId = $this->_file->getDbId(); + $plRows = CcPlaylistcontentsQuery::create()->filterByDbFileId()->find(); + foreach ($plRows as $row) { + $pl = CcPlaylistQuery::create()->filterByDbId($row->getDbPlaylistId($fileId))->findOne(); + $pl->setDbLength($pl->computeDbLength(Propel::getConnection(CcPlaylistPeer::DATABASE_NAME))); + $pl->save(); + } + + $blRows = CcBlockcontentsQuery::create()->filterByDbFileId($fileId)->find(); + foreach ($blRows as $row) { + $bl = CcBlockQuery::create()->filterByDbId($row->getDbBlockId())->findOne(); + $bl->setDbLength($bl->computeDbLength(Propel::getConnection(CcBlockPeer::DATABASE_NAME))); + $bl->save(); + } } /** diff --git a/airtime_mvc/application/models/airtime/CcBlock.php b/airtime_mvc/application/models/airtime/CcBlock.php index da43e76f0..84a3cb8c8 100644 --- a/airtime_mvc/application/models/airtime/CcBlock.php +++ b/airtime_mvc/application/models/airtime/CcBlock.php @@ -86,8 +86,14 @@ class CcBlock extends BaseCcBlock { */ public function computeDbLength(PropelPDO $con) { - $stmt = $con->prepare('SELECT SUM(cliplength) FROM "cc_blockcontents" WHERE cc_blockcontents.BLOCK_ID = :p1'); - $stmt->bindValue(':p1', $this->getDbId()); + $sql = <<prepare($sql); + $stmt->bindValue(':b1', $this->getDbId()); $stmt->execute(); $length = $stmt->fetchColumn(); diff --git a/airtime_mvc/application/models/airtime/CcPlaylist.php b/airtime_mvc/application/models/airtime/CcPlaylist.php index d152cf61f..bfa1e5354 100644 --- a/airtime_mvc/application/models/airtime/CcPlaylist.php +++ b/airtime_mvc/application/models/airtime/CcPlaylist.php @@ -87,7 +87,13 @@ class CcPlaylist extends BaseCcPlaylist { */ public function computeDbLength(PropelPDO $con) { - $stmt = $con->prepare('SELECT SUM(cliplength) FROM "cc_playlistcontents" WHERE cc_playlistcontents.PLAYLIST_ID = :p1'); + $sql = <<prepare($sql); $stmt->bindValue(':p1', $this->getDbId()); $stmt->execute(); $length = $stmt->fetchColumn(); diff --git a/airtime_mvc/application/views/scripts/form/preferences.phtml b/airtime_mvc/application/views/scripts/form/preferences.phtml index 1e0f7e606..3a0ec1135 100644 --- a/airtime_mvc/application/views/scripts/form/preferences.phtml +++ b/airtime_mvc/application/views/scripts/form/preferences.phtml @@ -4,7 +4,7 @@

SoundCloud Settings

- - + +obj)) : ?>
-obj)) : ?>
diff --git a/airtime_mvc/public/js/airtime/library/events/library_playlistbuilder.js b/airtime_mvc/public/js/airtime/library/events/library_playlistbuilder.js index fd9851f33..457b219b7 100644 --- a/airtime_mvc/public/js/airtime/library/events/library_playlistbuilder.js +++ b/airtime_mvc/public/js/airtime/library/events/library_playlistbuilder.js @@ -8,10 +8,16 @@ var AIRTIME = (function(AIRTIME) { mod = AIRTIME.library; mod.checkAddButton = function() { - var selected = mod.getChosenItemsLength(), sortable = $('#spl_sortable'), check = false; - // make sure audioclips are selected and a playlist is currently open. - if (selected !== 0 && sortable.length !== 0) { + var selected = mod.getChosenItemsLength(), + sortable = $('#spl_sortable:visible'), + check = false, + blockType = $('input[name=sp_type]:checked', '#smart-block-form').val(); + + // make sure audioclips are selected and a playlist or static block is currently open. + // static blocks have value of 0 + // dynamic blocks have value of 1 + if (selected !== 0 && (sortable.length !== 0 || blockType === "0")) { check = true; } @@ -96,6 +102,10 @@ var AIRTIME = (function(AIRTIME) { return container; }, cursor : 'pointer', + cursorAt: { + top: 30, + left: 100 + }, connectToSortable : '#spl_sortable' }); }; diff --git a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js index c33ccc351..94f40b4a8 100644 --- a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js +++ b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js @@ -201,7 +201,8 @@ function setSmartBlockEvents() { /********** CHANGE PLAYLIST TYPE **********/ form.find('dd[id="sp_type-element"]').live("change", function(){ - setupUI(); + setupUI(); + AIRTIME.library.checkAddButton(); }); /********** CRITERIA CHANGE **********/ diff --git a/python_apps/media-monitor2/media/monitor/events.py b/python_apps/media-monitor2/media/monitor/events.py index 761ffddb7..8fb373704 100644 --- a/python_apps/media-monitor2/media/monitor/events.py +++ b/python_apps/media-monitor2/media/monitor/events.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import os import abc +import re import media.monitor.pure as mmp import media.monitor.owners as owners from media.monitor.pure import LazyProperty @@ -101,6 +102,12 @@ class BaseEvent(Loggable): self.path = os.path.normpath(raw_event.pathname) else: self.path = raw_event self.owner = owners.get_owner(self.path) + owner_re = re.search('stor/imported/(?P\d+)/', self.path) + if owner_re: + self.logger.info("matched path: %s" % self.path) + self.owner = owner_re.group('owner') + else: + self.logger.info("did not match path: %s" % self.path) self._pack_hook = lambda: None # no op # into another event diff --git a/python_apps/media-monitor2/media/monitor/owners.py b/python_apps/media-monitor2/media/monitor/owners.py index 9d9c043bf..2d6c4be44 100644 --- a/python_apps/media-monitor2/media/monitor/owners.py +++ b/python_apps/media-monitor2/media/monitor/owners.py @@ -5,26 +5,22 @@ log = get_logger() owners = {} def reset_owners(): - """ - Wipes out all file => owner associations - """ + """ Wipes out all file => owner associations """ global owners owners = {} def get_owner(f): - """ - Get the owner id of the file 'f' - """ - return owners[f] if f in owners else -1 + """ Get the owner id of the file 'f' """ + o = owners[f] if f in owners else -1 + log.info("Received owner for %s. Owner: %s" % (f, o)) + return o def add_file_owner(f,owner): - """ - Associate file f with owner. If owner is -1 then do we will not record it - because -1 means there is no owner. Returns True if f is being stored after - the function. False otherwise. - """ + """ Associate file f with owner. If owner is -1 then do we will not record + it because -1 means there is no owner. Returns True if f is being stored + after the function. False otherwise. """ if owner == -1: return False if f in owners: if owner != owners[f]: # check for fishiness @@ -35,16 +31,12 @@ def add_file_owner(f,owner): return True def has_owner(f): - """ - True if f is owned by somebody. False otherwise. - """ + """ True if f is owned by somebody. False otherwise. """ return f in owners def remove_file_owner(f): - """ - Try and delete any association made with file f. Returns true if the the - association was actually deleted. False otherwise. - """ + """ Try and delete any association made with file f. Returns true if + the the association was actually deleted. False otherwise. """ if f in owners: del owners[f] return True diff --git a/python_apps/media-monitor2/media/monitor/request.py b/python_apps/media-monitor2/media/monitor/request.py index a2f3cdc8f..a49c6bb25 100644 --- a/python_apps/media-monitor2/media/monitor/request.py +++ b/python_apps/media-monitor2/media/monitor/request.py @@ -52,8 +52,6 @@ class RequestSync(Loggable): self.logger.info("ApiController.php probably crashed, we \ diagnose this from the fact that it did not return \ valid json") - self.logger.info("Trying again after %f seconds" % - self.request_wait) except Exception as e: self.unexpected_exception(e) else: self.logger.info("Request was successful") self.watcher.flag_done() # poor man's condition variable diff --git a/python_apps/media-monitor2/tests/test_owners.py b/python_apps/media-monitor2/tests/test_owners.py index 04788cf4c..8dfa6ad10 100644 --- a/python_apps/media-monitor2/tests/test_owners.py +++ b/python_apps/media-monitor2/tests/test_owners.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- import unittest -import media.monitor.owners as owners +from media.monitor import owners class TestMMP(unittest.TestCase): def setUp(self):