Merge branch 'saas-dev' into saas-dev-schedule-widget-angular

This commit is contained in:
drigato 2015-06-30 09:46:36 -04:00
commit 5f925f2f1f
103 changed files with 9339 additions and 2988 deletions

View file

@ -648,11 +648,6 @@ class ApiController extends Zend_Controller_Action
// fields
$file->setMetadataValue('MDATA_KEY_CREATOR', "Airtime Show Recorder");
$file->setMetadataValue('MDATA_KEY_TRACKNUMBER', $show_instance_id);
if (!$showCanceled && Application_Model_Preference::GetAutoUploadRecordedShowToSoundcloud()) {
$id = $file->getId();
Application_Model_Soundcloud::uploadSoundcloud($id);
}
}
public function mediaMonitorSetupAction()

View file

@ -265,29 +265,38 @@ class LibraryController extends Zend_Controller_Action
}
}
//SOUNDCLOUD MENU OPTIONS
if ($type === "audioclip" && Application_Model_Preference::GetUploadToSoundcloudOption()) {
// SOUNDCLOUD MENU OPTION
$ownerId = empty($obj) ? $file->getFileOwnerId() : $obj->getCreatorId();
if ($isAdminOrPM || $ownerId == $user->getId()) {
$soundcloudService = new SoundcloudService();
if ($type === "audioclip" && $soundcloudService->hasAccessToken()) {
//create a menu separator
$menu["sep1"] = "-----------";
//create a menu separator
$menu["sep1"] = "-----------";
//create a sub menu for Soundcloud actions.
$menu["soundcloud"] = array("name" => _("Soundcloud"), "icon" => "soundcloud", "items" => array());
//create a sub menu for Soundcloud actions.
$menu["soundcloud"] = array("name" => _("Soundcloud"), "icon" => "soundcloud", "items" => array());
$scid = $file->getSoundCloudId();
if ($scid > 0) {
$url = $file->getSoundCloudLinkToFile();
$menu["soundcloud"]["items"]["view"] = array("name" => _("View on Soundcloud"), "icon" => "soundcloud", "url" => $url);
$serviceId = $soundcloudService->getServiceId($id);
if (!is_null($file) && $serviceId != 0) {
$menu["soundcloud"]["items"]["view"] = array("name" => _("View track"), "icon" => "soundcloud", "url" => $baseUrl . "soundcloud/view-on-sound-cloud/id/{$id}");
$menu["soundcloud"]["items"]["remove"] = array("name" => _("Remove track"), "icon" => "soundcloud", "url" => $baseUrl . "soundcloud/delete/id/{$id}");
} else {
// If a reference exists for this file ID, that means the user has uploaded the track
// but we haven't yet gotten a response from Celery, so disable the menu item
if ($soundcloudService->referenceExists($id)) {
$menu["soundcloud"]["items"]["upload"] = array(
"name" => _("Upload track"), "icon" => "soundcloud",
"url" => $baseUrl . "soundcloud/upload/id/{$id}", "disabled" => true
);
} else {
$menu["soundcloud"]["items"]["upload"] = array(
"name" => _("Upload track"), "icon" => "soundcloud",
"url" => $baseUrl . "soundcloud/upload/id/{$id}"
);
}
}
}
if (!is_null($scid)) {
$text = _("Re-upload to SoundCloud");
} else {
$text = _("Upload to SoundCloud");
}
$menu["soundcloud"]["items"]["upload"] = array("name" => $text, "icon" => "soundcloud", "url" => $baseUrl."library/upload-file-soundcloud/id/{$id}");
}
if (empty($menu)) {
@ -525,33 +534,4 @@ class LibraryController extends Zend_Controller_Action
Logging::info($e->getMessage());
}
}
public function uploadFileSoundcloudAction()
{
$id = $this->_getParam('id');
Application_Model_Soundcloud::uploadSoundcloud($id);
// we should die with ui info
$this->_helper->json->sendJson(null);
}
public function getUploadToSoundcloudStatusAction()
{
$id = $this->_getParam('id');
$type = $this->_getParam('type');
if ($type == "show") {
$show_instance = new Application_Model_ShowInstance($id);
$this->view->sc_id = $show_instance->getSoundCloudFileId();
$file = $show_instance->getRecordedFile();
$this->view->error_code = $file->getSoundCloudErrorCode();
$this->view->error_msg = $file->getSoundCloudErrorMsg();
} elseif ($type == "file") {
$file = Application_Model_StoredFile::RecallById($id);
$this->view->sc_id = $file->getSoundCloudId();
$this->view->error_code = $file->getSoundCloudErrorCode();
$this->view->error_msg = $file->getSoundCloudErrorMsg();
} else {
Logging::warn("Trying to upload unknown type: $type with id: $id");
}
}
}

View file

@ -62,14 +62,9 @@ class PreferenceController extends Zend_Controller_Action
Application_Model_Preference::setTuneinPartnerKey($values["tunein_partner_key"]);
Application_Model_Preference::setTuneinPartnerId($values["tunein_partner_id"]);
/*Application_Model_Preference::SetUploadToSoundcloudOption($values["UploadToSoundcloudOption"]);
Application_Model_Preference::SetSoundCloudDownloadbleOption($values["SoundCloudDownloadbleOption"]);
Application_Model_Preference::SetSoundCloudUser($values["SoundCloudUser"]);
Application_Model_Preference::SetSoundCloudPassword($values["SoundCloudPassword"]);
Application_Model_Preference::SetSoundCloudTags($values["SoundCloudTags"]);
Application_Model_Preference::SetSoundCloudGenre($values["SoundCloudGenre"]);
Application_Model_Preference::SetSoundCloudTrackType($values["SoundCloudTrackType"]);
Application_Model_Preference::SetSoundCloudLicense($values["SoundCloudLicense"]);*/
// SoundCloud Preferences
Application_Model_Preference::setDefaultSoundCloudLicenseType($values["SoundCloudLicense"]);
Application_Model_Preference::setDefaultSoundCloudSharingType($values["SoundCloudSharing"]);
$this->view->statusMsg = "<div class='success'>". _("Preferences updated.")."</div>";
$form = new Application_Form_Preferences();

View file

@ -253,25 +253,6 @@ class ScheduleController extends Zend_Controller_Action
$this->view->show_id = $showId;
}
public function uploadToSoundCloudAction()
{
$show_instance = $this->_getParam('id');
try {
$show_inst = new Application_Model_ShowInstance($show_instance);
} catch (Exception $e) {
$this->view->show_error = true;
return false;
}
$file = $show_inst->getRecordedFile();
$id = $file->getId();
Application_Model_Soundcloud::uploadSoundcloud($id);
// we should die with ui info
$this->_helper->json->sendJson(null);
}
public function makeContextMenuAction()
{
$instanceId = $this->_getParam('instanceId');

View file

@ -0,0 +1,41 @@
<?php
require_once "ThirdPartyController.php";
require_once "ise/php-soundcloud/src/Soundcloud/Service.php";
class SoundcloudController extends ThirdPartyController {
/**
* @var SoundcloudService
*/
protected $_service;
/**
* @var string Application_Model_Preference service request token accessor function name
*/
protected $_SERVICE_TOKEN_ACCESSOR = 'setSoundCloudRequestToken';
/**
* Set up SoundCloud access variables.
*/
public function init() {
parent::init();
$this->_service = new SoundcloudService();
}
/**
* Fetch the permalink to a file on SoundCloud and redirect to it.
*/
public function viewOnSoundCloudAction() {
$request = $this->getRequest();
$id = $request->getParam('id');
try {
$soundcloudLink = $this->_service->getLinkToFile($id);
header('Location: ' . $soundcloudLink);
} catch (Soundcloud\Exception\InvalidHttpResponseCodeException $e) {
// Redirect to a 404 so the user knows something went wrong
header('Location: ' . $this->_baseUrl . 'error/error-404');
}
}
}

View file

@ -0,0 +1,93 @@
<?php
/**
* Class ThirdPartyController abstract superclass for third-party service authorization
*/
abstract class ThirdPartyController extends Zend_Controller_Action {
/**
* @var string base url and port for redirection
*/
protected $_baseUrl;
/**
* @var ThirdPartyService third party service object
*/
protected $_service;
/**
* @var string Application_Model_Preference service request token accessor function name
*/
protected $_SERVICE_TOKEN_ACCESSOR;
/**
* Disable controller rendering and initialize
*/
public function init() {
$CC_CONFIG = Config::getConfig();
$this->_baseUrl = 'http://' . $CC_CONFIG['baseUrl'] . ":" . $CC_CONFIG['basePort'] . "/";
$this->view->layout()->disableLayout(); // Don't inject the standard Now Playing header.
$this->_helper->viewRenderer->setNoRender(true); // Don't use (phtml) templates
}
/**
* Send user to a third-party service to authorize before being redirected
*
* @return void
*/
public function authorizeAction() {
$auth_url = $this->_service->getAuthorizeUrl();
header('Location: ' . $auth_url);
}
/**
* Clear the previously saved request token from the preferences
*
* @return void
*/
public function deauthorizeAction() {
$function = $this->_SERVICE_TOKEN_ACCESSOR;
Application_Model_Preference::$function("");
header('Location: ' . $this->_baseUrl . 'Preference'); // Redirect back to the Preference page
}
/**
* Called when user successfully completes third-party authorization
* Store the returned request token for future requests
*
* @return void
*/
public function redirectAction() {
$code = $_GET['code'];
$this->_service->requestNewAccessToken($code);
header('Location: ' . $this->_baseUrl . 'Preference'); // Redirect back to the Preference page
}
/**
* Upload the file with the given id to a third-party service
*
* @return void
*
* @throws Zend_Controller_Response_Exception thrown if upload fails for any reason
*/
public function uploadAction() {
$request = $this->getRequest();
$id = $request->getParam('id');
$this->_service->upload($id);
}
/**
* Delete the file with the given id from a third-party service
*
* @return void
*
* @throws Zend_Controller_Response_Exception thrown if deletion fails for any reason
*/
public function deleteAction() {
$request = $this->getRequest();
$id = $request->getParam('id');
$this->_service->delete($id);
}
}

View file

@ -9,14 +9,13 @@ class UpgradeController extends Zend_Controller_Action
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
if (!$this->verifyAuth()) {
if (!RestAuth::verifyAuth(true, false, $this)) {
return;
}
try {
$upgradeManager = new UpgradeManager();
$didWePerformAnUpgrade = $upgradeManager->doUpgrade();
$didWePerformAnUpgrade = UpgradeManager::doUpgrade();
if (!$didWePerformAnUpgrade) {
$this->getResponse()
->setHttpResponseCode(200)
@ -35,27 +34,34 @@ class UpgradeController extends Zend_Controller_Action
}
}
private function verifyAuth()
{
//The API key is passed in via HTTP "basic authentication":
//http://en.wikipedia.org/wiki/Basic_access_authentication
$CC_CONFIG = Config::getConfig();
//Decode the API key that was passed to us in the HTTP request.
$authHeader = $this->getRequest()->getHeader("Authorization");
public function downgradeAction() {
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$encodedRequestApiKey = substr($authHeader, strlen("Basic "));
$encodedStoredApiKey = base64_encode($CC_CONFIG["apiKey"][0] . ":");
if ($encodedRequestApiKey !== $encodedStoredApiKey)
{
$this->getResponse()
->setHttpResponseCode(401)
->appendBody("Error: Incorrect API key.<br>");
return false;
if (!RestAuth::verifyAuth(true, false, $this)) {
return;
}
$request = $this->getRequest();
$toVersion = $request->getParam("version");
try {
$downgradePerformed = UpgradeManager::doDowngrade($toVersion);
if (!$downgradePerformed) {
$this->getResponse()
->setHttpResponseCode(200)
->appendBody("No downgrade was performed. The current schema version is " . Application_Model_Preference::GetSchemaVersion() . ".<br>");
} else {
$this->getResponse()
->setHttpResponseCode(200)
->appendBody("Downgrade to Airtime schema version " . Application_Model_Preference::GetSchemaVersion() . " OK<br>");
}
} catch (Exception $e) {
$this->getResponse()
->setHttpResponseCode(400)
->appendBody($e->getMessage());
}
return true;
}
}

View file

@ -0,0 +1,11 @@
-----------------------------------------------------------------------
-- third_party_track_references
-----------------------------------------------------------------------
DROP TABLE IF EXISTS "third_party_track_references" CASCADE;
-----------------------------------------------------------------------
-- celery_tasks
-----------------------------------------------------------------------
DROP TABLE IF EXISTS "celery_tasks" CASCADE;

View file

@ -0,0 +1,42 @@
-----------------------------------------------------------------------
-- third_party_track_references
-----------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS "third_party_track_references"
(
"id" serial NOT NULL,
"service" VARCHAR(256) NOT NULL,
"foreign_id" VARCHAR(256),
"file_id" INTEGER NOT NULL,
"upload_time" TIMESTAMP,
"status" VARCHAR(256),
PRIMARY KEY ("id"),
CONSTRAINT "foreign_id_unique" UNIQUE ("foreign_id")
);
-----------------------------------------------------------------------
-- celery_tasks
-----------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS "celery_tasks"
(
"id" serial NOT NULL,
"task_id" VARCHAR(256) NOT NULL,
"track_reference" INTEGER NOT NULL,
"name" VARCHAR(256),
"dispatch_time" TIMESTAMP,
"status" VARCHAR(256) NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "id_unique" UNIQUE ("id")
);
ALTER TABLE "third_party_track_references" ADD CONSTRAINT "track_reference_fkey"
FOREIGN KEY ("file_id")
REFERENCES "cc_files" ("id")
ON DELETE CASCADE;
ALTER TABLE "celery_tasks" ADD CONSTRAINT "celery_service_fkey"
FOREIGN KEY ("track_reference")
REFERENCES "third_party_track_references" ("id")
ON DELETE CASCADE;