Merge branch 'saas-dev' into saas-landing-page

Conflicts:
	airtime_mvc/application/controllers/ApiController.php
	airtime_mvc/application/views/scripts/embed/player.phtml
This commit is contained in:
drigato 2015-05-28 13:25:18 -04:00
commit 8f8b0b7f4d
46 changed files with 1033 additions and 348 deletions

View file

@ -10,7 +10,7 @@ class ProvisioningHelper
// Parameter values
private $dbuser, $dbpass, $dbname, $dbhost, $dbowner, $apikey;
private $instanceId;
private $station_name, $description;
private $stationName, $description;
public function __construct($apikey)
{
@ -40,18 +40,14 @@ class ProvisioningHelper
if ($this->dbhost && !empty($this->dbhost)) {
$this->setNewDatabaseConnection();
//if ($this->checkDatabaseExists()) {
// throw new Exception("ERROR: Airtime database already exists");
//}
if (!$this->checkDatabaseExists()) {
throw new Exception("ERROR: $this->dbname database does not exist.");
throw new DatabaseDoesNotExistException("ERROR: $this->dbname database does not exist.");
}
//We really want to do this check because all the Propel-generated SQL starts with "DROP TABLE IF EXISTS".
//If we don't check, then a second call to this API endpoint would wipe all the tables!
if ($this->checkTablesExist()) {
throw new Exception("ERROR: airtime tables already exists");
throw new DatabaseAlreadyExistsException();
}
$this->createDatabaseTables();
@ -63,11 +59,19 @@ class ProvisioningHelper
//All we need to do is create the database tables.
$this->initializePrefs();
} catch (Exception $e) {
} catch (DatabaseDoesNotExistException $e) {
http_response_code(400);
Logging::error($e->getMessage());
echo $e->getMessage() . PHP_EOL;
return;
} catch (DatabaseAlreadyExistsException $e) {
// When we recreate a terminated instance, the process will fail
// if we return a 40x response here. In order to circumvent this,
// just return a 200; we still avoid dropping the existing tables
http_response_code(200);
Logging::info($e->getMessage());
echo $e->getMessage() . PHP_EOL;
return;
}
http_response_code(201);
@ -108,7 +112,7 @@ class ProvisioningHelper
$this->dbowner = $_POST['dbowner'];
$this->instanceId = $_POST['instanceid'];
$this->station_name = $_POST['station_name'];
$this->stationName = $_POST['station_name'];
$this->description = $_POST['description'];
}
@ -194,8 +198,8 @@ class ProvisioningHelper
* Initialize preference values passed from the dashboard (if any exist)
*/
private function initializePrefs() {
if ($this->station_name) {
Application_Model_Preference::SetStationName($this->station_name);
if ($this->stationName) {
Application_Model_Preference::SetStationName($this->stationName);
}
if ($this->description) {
Application_Model_Preference::SetStationDescription($this->description);
@ -203,3 +207,14 @@ class ProvisioningHelper
}
}
class DatabaseAlreadyExistsException extends Exception {
private static $_defaultMessage = "ERROR: airtime tables already exists";
public function __construct($message = null, $code = 0, Exception $previous = null) {
$message = _((is_null($message) ? self::$_defaultMessage : $message));
parent::__construct($message, $code, $previous);
}
}
class DatabaseDoesNotExistException extends Exception {}

View file

@ -0,0 +1,44 @@
<?php
class Application_Common_TuneIn
{
/**
* @param $title url encoded string
* @param $artist url encoded string
*/
public static function sendMetadataToTunein($title, $artist)
{
$credQryStr = self::getCredentialsQueryString();
$metadataQryStr = "&title=".$title."&artist=".$artist."&commercial=false";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, TUNEIN_API_URL . $credQryStr . $metadataQryStr);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$xmlResponse = curl_exec($ch);
if (curl_error($ch)) {
Logging::error("Failed to reach TuneIn: ". curl_errno($ch)." - ". curl_error($ch) . " - " . curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
}
curl_close($ch);
$xmlObj = new SimpleXMLElement($xmlResponse);
if (!$xmlObj || $xmlObj->head->status != "200") {
Logging::info("Error occurred pushing metadata to TuneIn:");
Logging::info($xmlResponse);
} else if ($xmlObj->head->status == "200") {
Application_Model_Preference::setLastTuneinMetadataUpdate(time());
}
}
private static function getCredentialsQueryString() {
$tuneInStationID = Application_Model_Preference::getTuneinStationId();
$tuneInPartnerID = Application_Model_Preference::getTuneinPartnerId();
$tuneInPartnerKey = Application_Model_Preference::getTuneinPartnerKey();
return "?partnerId=".$tuneInPartnerID."&partnerKey=".$tuneInPartnerKey."&id=".$tuneInStationID;
}
}