Merge branch 'saas-dev' into saas-installer-albert

Conflicts:
	python_apps/api_clients/api_clients/api_client.py
This commit is contained in:
Albert Santoni 2015-06-02 15:40:57 -04:00
commit 01ea6f27ae
11 changed files with 128 additions and 81 deletions

View file

@ -73,6 +73,7 @@ class ApiController extends Zend_Controller_Action
print _('You are not allowed to access this resource.');
exit;
}
return true;
}
public function versionAction()
@ -157,7 +158,7 @@ class ApiController extends Zend_Controller_Action
*/
public function liveInfoAction()
{
if (Application_Model_Preference::GetAllow3rdPartyApi()) {
if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
// disable the view and the layout
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
@ -252,7 +253,7 @@ class ApiController extends Zend_Controller_Action
*/
public function liveInfoV2Action()
{
if (Application_Model_Preference::GetAllow3rdPartyApi()) {
if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
// disable the view and the layout
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
@ -360,7 +361,7 @@ class ApiController extends Zend_Controller_Action
public function weekInfoAction()
{
if (Application_Model_Preference::GetAllow3rdPartyApi()) {
if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
// disable the view and the layout
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
@ -479,7 +480,7 @@ class ApiController extends Zend_Controller_Action
*/
public function showLogoAction()
{
if (Application_Model_Preference::GetAllow3rdPartyApi()) {
if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
$request = $this->getRequest();
$showId = $request->getParam('id');
@ -510,7 +511,7 @@ class ApiController extends Zend_Controller_Action
*/
public function stationMetadataAction()
{
if (Application_Model_Preference::GetAllow3rdPartyApi()) {
if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
// disable the view and the layout
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
@ -549,7 +550,7 @@ class ApiController extends Zend_Controller_Action
*/
public function stationLogoAction()
{
if (Application_Model_Preference::GetAllow3rdPartyApi()) {
if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
// disable the view and the layout
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
@ -1515,5 +1516,30 @@ class ApiController extends Zend_Controller_Action
$this->_helper->json($result);
}
/**
* This function is called from PYPO (pypofetch) every 2 minutes and updates
* metadata on TuneIn if we haven't done so in the last 4 minutes. We have
* to do this because TuneIn turns off metadata if it has not received a
* request within 5 minutes. This is necessary for long tracks > 5 minutes.
*/
public function updateMetadataOnTuneinAction()
{
if (!Application_Model_Preference::getTuneinEnabled()) {
$this->_helper->json->sendJson(array(0));
}
$lastTuneInMetadataUpdate = Application_Model_Preference::geLastTuneinMetadataUpdate();
if (time() - $lastTuneInMetadataUpdate >= 240) {
$metadata = $metadata = Application_Model_Schedule::getCurrentPlayingTrack();
if (!is_null($metadata)) {
Application_Common_TuneIn::sendMetadataToTunein(
$metadata["title"],
$metadata["artist"]
);
}
}
$this->_helper->json->sendJson(array(1));
}
}

View file

@ -72,6 +72,7 @@ class PreferenceController extends Zend_Controller_Action
Application_Model_Preference::SetSoundCloudLicense($values["SoundCloudLicense"]);*/
$this->view->statusMsg = "<div class='success'>". _("Preferences updated.")."</div>";
$form = new Application_Form_Preferences();
$this->view->form = $form;
//$this->_helper->json->sendJson(array("valid"=>"true", "html"=>$this->view->render('preference/index.phtml')));
} else {
@ -491,31 +492,42 @@ class PreferenceController extends Zend_Controller_Action
return;
}
$user = Application_Model_User::getCurrentUser();
$playlists = $blocks = $streams = [];
$this->deleteFutureScheduleItems();
$this->deleteCloudFiles();
$this->deleteStoredFiles();
$allPlaylists = CcPlaylistQuery::create()->find();
foreach ($allPlaylists as $p) {
$playlists[] = $p->getDbId();
$this->getResponse()
->setHttpResponseCode(200)
->appendBody("OK");
}
private function deleteFutureScheduleItems() {
$utcTimezone = new DateTimeZone("UTC");
$nowDateTime = new DateTime("now", $utcTimezone);
$scheduleItems = CcScheduleQuery::create()
->filterByDbEnds($nowDateTime->format("Y-m-d H:i:s"), Criteria::GREATER_THAN)
->find();
// Delete all the schedule items
foreach ($scheduleItems as $i) {
// If this is the currently playing track, cancel the current show
if ($i->isCurrentItem()) {
$instanceId = $i->getDbInstanceId();
$instance = CcShowInstancesQuery::create()->findPk($instanceId);
$showId = $instance->getDbShowId();
// From ScheduleController
$scheduler = new Application_Model_Scheduler();
$scheduler->cancelShow($showId);
Application_Model_StoredFile::updatePastFilesIsScheduled();
}
$i->delete();
}
}
$allBlocks = CcBlockQuery::create()->find();
foreach ($allBlocks as $b) {
$blocks[] = $b->getDbId();
}
$allStreams = CcWebstreamQuery::create()->find();
foreach ($allStreams as $s) {
$streams[] = $s->getDbId();
}
// Delete all playlists, blocks, and streams
Application_Model_Playlist::deletePlaylists($playlists, $user->getId());
Application_Model_Block::deleteBlocks($blocks, $user->getId());
Application_Model_Webstream::deleteStreams($streams, $user->getId());
private function deleteCloudFiles() {
try {
// Delete all the cloud files
$CC_CONFIG = Config::getConfig();
foreach ($CC_CONFIG["supportedStorageBackends"] as $storageBackend) {
@ -525,7 +537,9 @@ class PreferenceController extends Zend_Controller_Action
} catch(Exception $e) {
Logging::info($e->getMessage());
}
}
private function deleteStoredFiles() {
// Delete all files from the database
$files = CcFilesQuery::create()->find();
foreach ($files as $file) {
@ -534,10 +548,6 @@ class PreferenceController extends Zend_Controller_Action
// every S3 file we delete.
$storedFile->delete(true);
}
$this->getResponse()
->setHttpResponseCode(200)
->appendBody("OK");
}
}

View file

@ -315,13 +315,6 @@ class ScheduleController extends Zend_Controller_Action
{
$range = Application_Model_Schedule::GetPlayOrderRangeOld();
// If there is no current track playing update TuneIn so it doesn't
// display outdated metadata
//TODO: find a better solution for this so we don't spam the station on TuneIn
/*if (is_null($range["current"]) && Application_Model_Preference::getTuneinEnabled()) {
Application_Common_TuneIn::updateOfflineMetadata();
}*/
$show = Application_Model_Show::getCurrentShow();
/* Convert all UTC times to localtime before sending back to user. */

View file

@ -239,7 +239,7 @@ class WHMCS_Auth_Adapter implements Zend_Auth_Adapter_Interface {
}
else
{
if ($product["status"] === "Active") {
if (($product["status"] === "Active") || ($product["status"] === "Suspended")) {
$airtimeProduct = $product;
$subdomain = '';