Merge branch 'saas' into cc-5709-airtime-analyzer-buy-now-saas

This commit is contained in:
drigato 2014-06-23 10:59:07 -04:00
commit f40cdbc8cd
70 changed files with 49423 additions and 46970 deletions

View file

@ -2,31 +2,37 @@
class Cache
{
private function createCacheKey($key, $isUserValue, $userId = null) {
$CC_CONFIG = Config::getConfig();
$a = $CC_CONFIG["apiKey"][0];
if ($isUserValue) {
$cacheKey = "{$key}{$userId}{$a}";
}
else {
$cacheKey = "{$key}{$a}";
}
private function createCacheKey($key, $isUserValue, $userId = null) {
$CC_CONFIG = Config::getConfig();
$a = $CC_CONFIG["apiKey"][0];
if ($isUserValue) {
$cacheKey = "{$key}{$userId}{$a}";
}
else {
$cacheKey = "{$key}{$a}";
}
return $cacheKey;
}
public function store($key, $value, $isUserValue, $userId = null) {
$cacheKey = self::createCacheKey($key, $userId);
return apc_store($cacheKey, $value);
}
public function fetch($key, $isUserValue, $userId = null) {
$cacheKey = self::createCacheKey($key, $isUserValue, $userId);
return apc_fetch($cacheKey);
}
}
return $cacheKey;
}
public function store($key, $value, $isUserValue, $userId = null) {
$cacheKey = self::createCacheKey($key, $userId);
//XXX: Disabling APC on SaaS because it turns out we have multiple webservers
// running, which means we have to use a distributed data cache like memcached.
//return apc_store($cacheKey, $value);
return false;
}
public function fetch($key, $isUserValue, $userId = null) {
$cacheKey = self::createCacheKey($key, $isUserValue, $userId);
//XXX: Disabling APC on SaaS because it turns out we have multiple webservers
// running, which means we have to use a distributed data cache like memcached.
//return apc_fetch($cacheKey);
return false;
}
}

View file

@ -733,11 +733,7 @@ class Application_Model_Preference
$outputArray['NUM_OF_PAST_SHOWS'] = Application_Model_ShowInstance::GetShowInstanceCount(gmdate("Y-m-d H:i:s"));
$outputArray['UNIQUE_ID'] = self::GetUniqueId();
$outputArray['SAAS'] = self::GetPlanLevel();
if ($outputArray['SAAS'] != 'disabled') {
$outputArray['TRIAL_END_DATE'] = self::GetTrialEndingDate();
} else {
$outputArray['TRIAL_END_DATE'] = NULL;
}
$outputArray['TRIAL_END_DATE'] = self::GetTrialEndingDate();
$outputArray['INSTALL_METHOD'] = self::GetInstallMethod();
$outputArray['NUM_OF_STREAMS'] = self::GetNumOfStreams();
$outputArray['STREAM_INFO'] = Application_Model_StreamSetting::getStreamInfoForDataCollection();
@ -763,9 +759,7 @@ class Application_Model_Preference
$outputString .= $key." : FALSE\n";
}
} elseif ($key == "SAAS") {
if (strcmp($out, 'disabled')!=0) {
$outputString .= $key.' : '.$out."\n";
}
$outputString .= $key.' : '.$out."\n";
} else {
$outputString .= $key.' : '.$out."\n";
}
@ -1023,6 +1017,24 @@ class Application_Model_Preference
Logging::warn("Attempting to set client_id to invalid value: $id");
}
}
public static function GetLiveChatEnabled()
{
$liveChat = self::getValue("live_chat", false);
if (is_null($liveChat) || $liveChat == "" || $liveChat == "1") { //Defaults to on
return true;
}
return false;
}
public static function SetLiveChatEnabled($toggle)
{
if (is_bool($toggle)) {
self::setValue("live_chat", $toggle ? "1" : "0");
} else {
Logging::warn("Attempting to set live_chat to invalid value: $toggle. Must be a bool.");
}
}
/* User specific preferences start */

View file

@ -82,7 +82,24 @@ class Application_Model_RabbitMq
public static function SendMessageToAnalyzer($tmpFilePath, $importedStorageDirectory, $originalFilename,
$callbackUrl, $apiKey)
{
//Hack for Airtime Pro. The RabbitMQ settings for communicating with airtime_analyzer are global
//and shared between all instances on Airtime Pro.
$CC_CONFIG = Config::getConfig();
$devEnv = "production"; //Default
if (array_key_exists("dev_env", $CC_CONFIG)) {
$devEnv = $CC_CONFIG["dev_env"];
}
$config = parse_ini_file("/etc/airtime-saas/rabbitmq-analyzer-" . $devEnv . ".ini", true);
$conn = new AMQPConnection($config["rabbitmq"]["host"],
$config["rabbitmq"]["port"],
$config["rabbitmq"]["user"],
$config["rabbitmq"]["password"],
$config["rabbitmq"]["vhost"]);
$exchange = 'airtime-uploads';
$exchangeType = 'topic';
$queue = 'airtime-uploads';
$autoDeleteExchange = false;
$data['tmp_file_path'] = $tmpFilePath;
$data['import_directory'] = $importedStorageDirectory;
$data['original_filename'] = $originalFilename;
@ -90,6 +107,67 @@ class Application_Model_RabbitMq
$data['api_key'] = $apiKey;
$jsonData = json_encode($data);
self::sendMessage($exchange, 'topic', false, $jsonData, 'airtime-uploads');
//self::sendMessage($exchange, 'topic', false, $jsonData, 'airtime-uploads');
if (!isset($conn)) {
throw new Exception("Cannot connect to RabbitMQ server");
}
$channel = $conn->channel();
$channel->access_request($config["rabbitmq"]["vhost"], false, false,
true, true);
//I'm pretty sure we DON'T want to autodelete ANY exchanges but I'm keeping the code
//the way it is just so I don't accidentally break anything when I add the Analyzer code in. -- Albert, March 13, 2014
$channel->exchange_declare($exchange, $exchangeType, false, true, $autoDeleteExchange);
$msg = new AMQPMessage($jsonData, array('content_type' => 'text/plain'));
$channel->basic_publish($msg, $exchange);
$channel->close();
$conn->close();
}
public static function SendMessageToHaproxyConfigDaemon($md){
$config = parse_ini_file("/etc/airtime-saas/rabbitmq.ini", true);
$conn = new AMQPConnection($config["rabbitmq"]["host"],
$config["rabbitmq"]["port"],
$config["rabbitmq"]["user"],
$config["rabbitmq"]["password"],
$config["rabbitmq"]["vhost"]);
$exchange = $config["rabbitmq"]["queue"];
$queue = $config["rabbitmq"]["queue"];
$ch = $conn->channel();
/*
name: $queue
passive: false
durable: true // the queue will survive server restarts
exclusive: false // the queue can be accessed in other channels
auto_delete: false //the queue won't be deleted once the channel is closed.
*/
$ch->queue_declare($queue, false, true, false, false);
/*
name: $exchange
type: direct
passive: false
durable: true // the exchange will survive server restarts
auto_delete: false //the exchange won't be deleted once the channel is closed.
*/
$ch->exchange_declare($exchange, 'direct', false, true, false);
$ch->queue_bind($queue, $exchange);
$data = json_encode($md).PHP_EOL;
$msg = new AMQPMessage($data, array('content_type' => 'application/json'));
$ch->basic_publish($msg, $exchange);
$ch->close();
$conn->close();
}
}

View file

@ -66,7 +66,7 @@ SQL;
public static function GetPlayOrderRange($p_prev = 1, $p_next = 1)
{
//Everything in this function must be done in UTC. You will get a swift kick in the pants if you mess that up.
if (!is_int($p_prev) || !is_int($p_next)) {
//must enter integers to specify ranges
Logging::info("Invalid range parameters: $p_prev or $p_next");
@ -75,7 +75,7 @@ SQL;
}
$utcNow = new DateTime("now", new DateTimeZone("UTC"));
$shows = Application_Model_Show::getPrevCurrentNext($utcNow);
$previousShowID = count($shows['previousShow'])>0?$shows['previousShow'][0]['instance_id']:null;
$currentShowID = count($shows['currentShow'])>0?$shows['currentShow'][0]['instance_id']:null;
@ -111,7 +111,7 @@ SQL;
$timeZone = new DateTimeZone("UTC"); //This function works entirely in UTC.
assert(get_class($utcNow) === "DateTime");
assert($utcNow->getTimeZone() == $timeZone);
if ($p_previousShowID == null && $p_currentShowID == null && $p_nextShowID == null) {
return;
}
@ -170,15 +170,15 @@ SQL;
$results['next'] = null;
for ($i = 0; $i < $numberOfRows; ++$i) {
// if the show is overbooked, then update the track end time to the end of the show time.
if ($rows[$i]['ends'] > $rows[$i]["show_ends"]) {
$rows[$i]['ends'] = $rows[$i]["show_ends"];
}
$curShowStartTime = new DateTime($rows[$i]['starts'], $timeZone);
$curShowEndTime = new DateTime($rows[$i]['ends'], $timeZone);
if (($curShowStartTime <= $utcNow) && ($curShowEndTime >= $utcNow)) {
if ($i - 1 >= 0) {
$results['previous'] = array("name"=>$rows[$i-1]["artist_name"]." - ".$rows[$i-1]["track_title"],
@ -830,7 +830,7 @@ SQL;
$CC_CONFIG = Config::getConfig();
$utcTimeZone = new DateTimeZone('UTC');
/* if $p_fromDateTime and $p_toDateTime function parameters are null,
then set range * from "now" to "now + 24 hours". */
if (is_null($p_fromDateTime)) {
@ -890,13 +890,13 @@ SQL;
$storedFile = Application_Model_StoredFile::RecallById($media_id);
$uri = $storedFile->getFilePath();
self::createFileScheduleEvent($data, $item, $media_id, $uri);
}
}
elseif (!is_null($item['stream_id'])) {
//row is type "webstream"
$media_id = $item['stream_id'];
$uri = $item['url'];
self::createStreamScheduleEvent($data, $item, $media_id, $uri);
}
}
else {
throw new Exception("Unknown schedule type: ".print_r($item, true));
}

View file

@ -401,7 +401,7 @@ SQL;
}
}
Logging::info("User ".$user->getLogin()." is deleting file: ".$this->_file->getDbTrackTitle()." - file id: ".$this->_file->getDbId());
Logging::info($_SERVER["HTTP_HOST"].": User ".$user->getLogin()." is deleting file: ".$this->_file->getDbTrackTitle()." - file id: ".$this->_file->getDbId());
// set hidden flag to true
//$this->_file->setDbHidden(true);
$this->_file->setDbFileExists(false);
@ -953,6 +953,8 @@ SQL;
// Did all the checks for real, now trying to copy
$audio_stor = Application_Common_OsPath::join($stor, "organize",
$originalFilename);
Logging::info($originalFilename);
Logging::info($audio_stor);
$user = Application_Model_User::getCurrentUser();
if (is_null($user)) {
$uid = Application_Model_User::getFirstAdminId();

View file

@ -215,23 +215,25 @@ class Application_Model_Systemstatus
{
$partitions = array();
/* First lets get all the watched directories. Then we can group them
* into the same partitions by comparing the partition sizes. */
$musicDirs = Application_Model_MusicDir::getWatchedDirs();
$musicDirs[] = Application_Model_MusicDir::getStorDir();
//connect to DB and find how much total space user has allocated.
$totalSpace = Application_Model_Preference::GetDiskQuota();
foreach ($musicDirs as $md) {
$totalSpace = disk_total_space($md->getDirectory());
if (!isset($partitions[$totalSpace])) {
$partitions[$totalSpace] = new StdClass;
$partitions[$totalSpace]->totalSpace = $totalSpace;
$partitions[$totalSpace]->totalFreeSpace = disk_free_space($md->getDirectory());
}
$partitions[$totalSpace]->dirs[] = $md->getDirectory();
$usedSpace = Application_Model_Preference::getDiskUsage();
if (empty($usedSpace)) {
$usedSpace = 0;
}
/* $path = $_SERVER['AIRTIME_BASE']."etc/airtime/num_bytes.ini";
$arr = parse_ini_file($path);
$usedSpace = 0;
if ($arr !== false) {
$usedSpace = $arr['num_bytes'];
} */
$partitions[$totalSpace] = new stdClass();
$partitions[$totalSpace]->totalSpace = $totalSpace;
$partitions[$totalSpace]->totalFreeSpace = $totalSpace - $usedSpace;
Logging::info($partitions[$totalSpace]->totalFreeSpace);
return array_values($partitions);
}
@ -241,7 +243,7 @@ class Application_Model_Systemstatus
$diskInfo = self::GetDiskInfo();
$diskInfo = $diskInfo[0];
$diskUsage = $diskInfo->totalSpace - $diskInfo->totalFreeSpace;
if ($diskUsage >= $diskInfo->totalSpace) {
if ($diskUsage > 0 && $diskUsage >= $diskInfo->totalSpace) {
return true;
}

View file

@ -330,16 +330,26 @@ class Application_Model_User
$res = Application_Model_Datatables::findEntries($con, $displayColumns, $fromTable, $datatables);
// mark record which is for the current user
foreach ($res['aaData'] as &$record) {
foreach($res['aaData'] as $key => &$record){
if ($record['login'] == $username) {
$record['delete'] = "self";
} else {
$record['delete'] = "";
}
if($record['login'] == 'sourcefabric_admin'){
//arrays in PHP are basically associative arrays that can be iterated in order.
//Deleting an earlier element does not change the keys of elements that come after it. --MK
unset($res['aaData'][$key]);
$res['iTotalDisplayRecords']--;
$res['iTotalRecords']--;
}
$record = array_map('htmlspecialchars', $record);
}
$res['aaData'] = array_values($res['aaData']);
return $res;
}