Merge branch 'cc-5709-airtime-analyzer' into cc-5709-airtime-analyzer-cloud-storage

Conflicts:
	airtime_mvc/application/models/StoredFile.php
	airtime_mvc/application/modules/rest/controllers/MediaController.php
	python_apps/airtime_analyzer/airtime_analyzer/analyzer_pipeline.py
This commit is contained in:
drigato 2014-11-26 11:42:40 -05:00
commit 884a4c493d
103 changed files with 30564 additions and 20054 deletions

View file

@ -33,7 +33,8 @@ class Application_Model_Auth
$message = sprintf(_("Hi %s, \n\nClick this link to reset your password: "), $user->getDbLogin());
$message .= "{$e_link_protocol}://{$e_link_base}:{$e_link_port}{$e_link_path}";
$success = Application_Model_Email::send(_('Airtime Password Reset'), $message, $user->getDbEmail());
$str = sprintf(_('%s Password Reset'), PRODUCT_NAME);
$success = Application_Model_Email::send($str, $message, $user->getDbEmail());
return $success;
}

View file

@ -47,5 +47,22 @@ class Application_Model_Locale
textdomain($domain);
bind_textdomain_codeset($domain, $codeset);
}
/**
* We need this function for the case where a user has logged out, but
* has an airtime_locale cookie containing their locale setting.
*
* If the user does not have an airtime_locale cookie set, we default
* to the station locale.
*
* When the user logs in, the value set in the login form will be passed
* into the airtime_locale cookie. This cookie is also updated when
* a user updates their user settings.
*/
public static function getUserLocale() {
$request = Zend_Controller_Front::getInstance()->getRequest();
$locale = $request->getCookie('airtime_locale', Application_Model_Preference::GetLocale());
return $locale;
}
}

View file

@ -4,45 +4,44 @@ require_once 'Cache.php';
class Application_Model_Preference
{
private static function getUserId()
{
//pass in true so the check is made with the autoloader
//we need this check because saas calls this function from outside Zend
if (!class_exists("Zend_Auth", true) || !Zend_Auth::getInstance()->hasIdentity()) {
$userId = null;
}
else {
$auth = Zend_Auth::getInstance();
$userId = $auth->getIdentity()->id;
}
return $userId;
}
private static function getUserId()
{
//pass in true so the check is made with the autoloader
//we need this check because saas calls this function from outside Zend
if (!class_exists("Zend_Auth", true) || !Zend_Auth::getInstance()->hasIdentity()) {
$userId = null;
} else {
$auth = Zend_Auth::getInstance();
$userId = $auth->getIdentity()->id;
}
return $userId;
}
/**
*
* @param boolean $isUserValue is true when we are setting a value for the current user
*/
private static function setValue($key, $value, $isUserValue = false)
{
$cache = new Cache();
$cache = new Cache();
try {
$con = Propel::getConnection(CcPrefPeer::DATABASE_NAME);
$con->beginTransaction();
$userId = self::getUserId();
if ($isUserValue && is_null($userId)) {
throw new Exception("User id can't be null for a user preference {$key}.");
}
if ($isUserValue && is_null($userId))
throw new Exception("User id can't be null for a user preference {$key}.");
Application_Common_Database::prepareAndExecute("LOCK TABLE cc_pref");
//Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref"
." WHERE keystr = :key";
." WHERE keystr = :key";
$paramMap = array();
$paramMap[':key'] = $key;
@ -64,37 +63,33 @@ class Application_Model_Preference
//this case should not happen.
throw new Exception("Invalid number of results returned. Should be ".
"0 or 1, but is '$result' instead");
}
elseif ($result == 1) {
} else if ($result == 1) {
// result found
if (!$isUserValue) {
// system pref
$sql = "UPDATE cc_pref"
." SET subjid = NULL, valstr = :value"
." WHERE keystr = :key";
}
else {
." SET subjid = NULL, valstr = :value"
." WHERE keystr = :key";
} else {
// user pref
$sql = "UPDATE cc_pref"
. " SET valstr = :value"
. " WHERE keystr = :key AND subjid = :id";
. " SET valstr = :value"
. " WHERE keystr = :key AND subjid = :id";
$paramMap[':id'] = $userId;
}
}
else {
} else {
// result not found
if (!$isUserValue) {
// system pref
$sql = "INSERT INTO cc_pref (keystr, valstr)"
." VALUES (:key, :value)";
}
else {
." VALUES (:key, :value)";
} else {
// user pref
$sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
." VALUES (:id, :key, :value)";
." VALUES (:id, :key, :value)";
$paramMap[':id'] = $userId;
}
@ -109,8 +104,7 @@ class Application_Model_Preference
$con);
$con->commit();
}
catch (Exception $e) {
} catch (Exception $e) {
$con->rollback();
header('HTTP/1.0 503 Service Unavailable');
Logging::info("Database error: ".$e->getMessage());
@ -118,26 +112,22 @@ class Application_Model_Preference
}
$cache->store($key, $value, $isUserValue, $userId);
//Logging::info("SAVING {$key} {$userId} into cache. = {$value}");
}
private static function getValue($key, $isUserValue = false)
{
$cache = new Cache();
$cache = new Cache();
try {
$userId = self::getUserId();
if ($isUserValue && is_null($userId)) {
throw new Exception("User id can't be null for a user preference.");
}
$userId = self::getUserId();
if ($isUserValue && is_null($userId))
throw new Exception("User id can't be null for a user preference.");
$res = $cache->fetch($key, $isUserValue, $userId);
if ($res !== false) {
//Logging::info("returning {$key} {$userId} from cache. = {$res}");
return $res;
}
// If the value is already cached, return it
$res = $cache->fetch($key, $isUserValue, $userId);
if ($res !== false) return $res;
//Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref"
@ -147,7 +137,7 @@ class Application_Model_Preference
$paramMap[':key'] = $key;
//For user specific preference, check if id matches as well
if ($isUserValue) {
if ($isUserValue) {
$sql .= " AND subjid = :id";
$paramMap[':id'] = $userId;
}
@ -157,8 +147,7 @@ class Application_Model_Preference
//return an empty string if the result doesn't exist.
if ($result == 0) {
$res = "";
}
else {
} else {
$sql = "SELECT valstr FROM cc_pref"
." WHERE keystr = :key";
@ -248,53 +237,53 @@ class Application_Model_Preference
public static function SetDefaultCrossfadeDuration($duration)
{
self::setValue("default_crossfade_duration", $duration);
self::setValue("default_crossfade_duration", $duration);
}
public static function GetDefaultCrossfadeDuration()
{
$duration = self::getValue("default_crossfade_duration");
$duration = self::getValue("default_crossfade_duration");
if ($duration === "") {
// the default value of the fade is 00.5
return "0";
}
if ($duration === "") {
// the default value of the fade is 00.5
return "0";
}
return $duration;
return $duration;
}
public static function SetDefaultFadeIn($fade)
{
self::setValue("default_fade_in", $fade);
self::setValue("default_fade_in", $fade);
}
public static function GetDefaultFadeIn()
{
$fade = self::getValue("default_fade_in");
$fade = self::getValue("default_fade_in");
if ($fade === "") {
// the default value of the fade is 00.5
return "00.5";
}
if ($fade === "") {
// the default value of the fade is 00.5
return "00.5";
}
return $fade;
return $fade;
}
public static function SetDefaultFadeOut($fade)
{
self::setValue("default_fade_out", $fade);
self::setValue("default_fade_out", $fade);
}
public static function GetDefaultFadeOut()
{
$fade = self::getValue("default_fade_out");
$fade = self::getValue("default_fade_out");
if ($fade === "") {
// the default value of the fade is 00.5
return "00.5";
}
if ($fade === "") {
// the default value of the fade is 00.5
return "00.5";
}
return $fade;
return $fade;
}
public static function SetDefaultFade($fade)
@ -556,9 +545,8 @@ class Application_Model_Preference
{
// When a new user is created they will get the default timezone
// setting which the admin sets on preferences page
if (is_null($timezone)) {
if (is_null($timezone))
$timezone = self::GetDefaultTimezone();
}
self::setValue("user_timezone", $timezone, true);
}
@ -567,8 +555,7 @@ class Application_Model_Preference
$timezone = self::getValue("user_timezone", true);
if (!$timezone) {
return self::GetDefaultTimezone();
}
else {
} else {
return $timezone;
}
}
@ -580,8 +567,7 @@ class Application_Model_Preference
if (!is_null($userId)) {
return self::GetUserTimezone();
}
else {
} else {
return self::GetDefaultTimezone();
}
}
@ -612,9 +598,8 @@ class Application_Model_Preference
{
// When a new user is created they will get the default locale
// setting which the admin sets on preferences page
if (is_null($locale)) {
if (is_null($locale))
$locale = self::GetDefaultLocale();
}
self::setValue("user_locale", $locale, true);
}
@ -624,8 +609,7 @@ class Application_Model_Preference
if (!is_null($userId)) {
return self::GetUserLocale();
}
else {
} else {
return self::GetDefaultLocale();
}
}
@ -648,7 +632,7 @@ class Application_Model_Preference
public static function SetUniqueId($id)
{
self::setValue("uniqueId", $id);
self::setValue("uniqueId", $id);
}
public static function GetUniqueId()
@ -908,7 +892,7 @@ class Application_Model_Preference
public static function SetAirtimeVersion($version)
{
self::setValue("system_version", $version);
self::setValue("system_version", $version);
}
public static function GetAirtimeVersion()
@ -1404,12 +1388,11 @@ class Application_Model_Preference
return self::getValue("enable_replay_gain", false);
}
public static function getReplayGainModifier(){
public static function getReplayGainModifier() {
$rg_modifier = self::getValue("replay_gain_modifier");
if ($rg_modifier === "") {
if ($rg_modifier === "")
return "0";
}
return $rg_modifier;
}
@ -1420,19 +1403,19 @@ class Application_Model_Preference
}
public static function SetHistoryItemTemplate($value) {
self::setValue("history_item_template", $value);
self::setValue("history_item_template", $value);
}
public static function GetHistoryItemTemplate() {
return self::getValue("history_item_template");
return self::getValue("history_item_template");
}
public static function SetHistoryFileTemplate($value) {
self::setValue("history_file_template", $value);
self::setValue("history_file_template", $value);
}
public static function GetHistoryFileTemplate() {
return self::getValue("history_file_template");
return self::getValue("history_file_template");
}
public static function getDiskUsage()

View file

@ -1112,35 +1112,36 @@ class Application_Model_Scheduler
$removedItems = CcScheduleQuery::create()->findPks($scheduledIds);
//check to make sure all items selected are up to date
foreach ($removedItems as $removedItem) {
// This array is used to keep track of every show instance that was
// effected by the track deletion. It will be used later on to
// remove gaps in the schedule and adjust crossfade times.
$effectedInstanceIds = array();
foreach ($removedItems as $removedItem) {
$instance = $removedItem->getCcShowInstances($this->con);
$effectedInstanceIds[] = $instance->getDbId();
//check if instance is linked and if so get the schedule items
//for all linked instances so we can delete them too
if (!$cancelShow && $instance->getCcShow()->isLinked()) {
//returns all linked instances if linked
$ccShowInstances = $this->getInstances($instance->getDbId());
$instanceIds = array();
foreach ($ccShowInstances as $ccShowInstance) {
$instanceIds[] = $ccShowInstance->getDbId();
}
/*
* Find all the schedule items that are in the same position
* as the selected item by the user.
* The position of each track is the same across each linked instance
*/
$effectedInstanceIds = array_merge($effectedInstanceIds, $instanceIds);
// Delete the same track, represented by $removedItem, in
// each linked show instance.
$itemsToDelete = CcScheduleQuery::create()
->filterByDbPosition($removedItem->getDbPosition())
->filterByDbInstanceId($instanceIds, Criteria::IN)
->find();
foreach ($itemsToDelete as $item) {
if (!$removedItems->contains($item)) {
$removedItems->append($item);
}
}
->filterByDbId($removedItem->getDbId(), Criteria::NOT_EQUAL)
->delete($this->con);
}
//check to truncate the currently playing item instead of deleting it.
if ($removedItem->isCurrentItem($this->epochNow)) {
@ -1165,29 +1166,11 @@ class Application_Model_Scheduler
} else {
$removedItem->delete($this->con);
}
// update is_scheduled in cc_files but only if
// the file is not scheduled somewhere else
$fileId = $removedItem->getDbFileId();
// check if the removed item is scheduled somewhere else
$futureScheduledFiles = Application_Model_Schedule::getAllFutureScheduledFiles();
if (!is_null($fileId) && !in_array($fileId, $futureScheduledFiles)) {
$db_file = CcFilesQuery::create()->findPk($fileId, $this->con);
$db_file->setDbIsScheduled(false)->save($this->con);
}
}
Application_Model_StoredFile::updatePastFilesIsScheduled();
if ($adjustSched === true) {
//get the show instances of the shows we must adjust times for.
foreach ($removedItems as $item) {
$instance = $item->getDBInstanceId();
if (!in_array($instance, $showInstances)) {
$showInstances[] = $instance;
}
}
foreach ($showInstances as $instance) {
foreach ($effectedInstanceIds as $instance) {
$this->removeGaps($instance);
$this->calculateCrossfades($instance);
}
@ -1195,7 +1178,7 @@ class Application_Model_Scheduler
//update the status flag in cc_schedule.
$instances = CcShowInstancesQuery::create()
->filterByPrimaryKeys($showInstances)
->filterByPrimaryKeys($effectedInstanceIds)
->find($this->con);
foreach ($instances as $instance) {

View file

@ -1131,7 +1131,6 @@ SELECT s.name,
s.genre,
s.id,
si.id AS instance_id,
si.description AS instance_description,
si.record,
s.url,
s.image_path,
@ -1220,7 +1219,6 @@ SELECT si.starts AS start_timestamp,
s.description,
s.id,
si.id AS instance_id,
si.description AS instance_description,
si.record,
s.url,
s.image_path,
@ -1267,7 +1265,6 @@ SQL;
$results['previousShow'][0] = array(
"id" => $rows[$i-1]['id'],
"instance_id" => $rows[$i-1]['instance_id'],
"instance_description" => $rows[$i-1]['instance_description'],
"name" => $rows[$i-1]['name'],
"description" => $rows[$i-1]['description'],
"url" => $rows[$i-1]['url'],
@ -1286,7 +1283,6 @@ SQL;
$results['nextShow'][0] = array(
"id" => $rows[$i+1]['id'],
"instance_id" => $rows[$i+1]['instance_id'],
"instance_description" => $rows[$i+1]['instance_description'],
"name" => $rows[$i+1]['name'],
"description" => $rows[$i+1]['description'],
"url" => $rows[$i+1]['url'],
@ -1309,7 +1305,6 @@ SQL;
$results['nextShow'][0] = array(
"id" => $rows[$i]['id'],
"instance_id" => $rows[$i]['instance_id'],
"instance_description" => $rows[$i]['instance_description'],
"name" => $rows[$i]['name'],
"description" => $rows[$i]['description'],
"url" => $rows[$i]['url'],
@ -1329,7 +1324,6 @@ SQL;
$results['previousShow'][0] = array(
"id" => $rows[$previousShowIndex]['id'],
"instance_id" => $rows[$previousShowIndex]['instance_id'],
"instance_description" => $rows[$previousShowIndex]['instance_description'],
"name" => $rows[$previousShowIndex]['name'],
"description" => $rows[$previousShowIndex]['description'],
"start_timestamp" => $rows[$previousShowIndex]['start_timestamp'],

View file

@ -362,7 +362,8 @@ SQL;
{
$exists = false;
try {
$exists = file_exists($this->getFilePath());
$filePath = $this->getFilePath();
$exists = (file_exists($this->getFilePath()) && !is_dir($filePath));
} catch (Exception $e) {
return false;
}