Merge branch '2.5.x'

This commit is contained in:
Naomi 2013-11-11 17:18:22 -05:00
commit 9d43f903fa
7 changed files with 143 additions and 84 deletions

View File

@ -70,7 +70,7 @@ class LoginController extends Zend_Controller_Action
$tempSess->referrer = 'login'; $tempSess->referrer = 'login';
//set the user locale in case user changed it in when logging in //set the user locale in case user changed it in when logging in
Application_Model_Preference::SetUserLocale($auth->getIdentity()->id, $locale); Application_Model_Preference::SetUserLocale($locale);
$this->_redirect('Showbuilder'); $this->_redirect('Showbuilder');
} else { } else {

View File

@ -72,8 +72,8 @@ class UserController extends Zend_Controller_Action
// Language and timezone settings are saved on a per-user basis // Language and timezone settings are saved on a per-user basis
// By default, the default language, and timezone setting on // By default, the default language, and timezone setting on
// preferences page is what gets assigned. // preferences page is what gets assigned.
Application_Model_Preference::SetUserLocale($user->getId()); Application_Model_Preference::SetUserLocale();
Application_Model_Preference::SetUserTimezone($user->getId()); Application_Model_Preference::SetUserTimezone();
$form->reset(); $form->reset();
$this->view->form = $form; $this->view->form = $form;
@ -143,8 +143,8 @@ class UserController extends Zend_Controller_Action
$user->setJabber($formData['cu_jabber']); $user->setJabber($formData['cu_jabber']);
$user->save(); $user->save();
Application_Model_Preference::SetUserLocale($user->getId(), $formData['cu_locale']); Application_Model_Preference::SetUserLocale($formData['cu_locale']);
Application_Model_Preference::SetUserTimezone($user->getId(), $formData['cu_timezone']); Application_Model_Preference::SetUserTimezone($formData['cu_timezone']);
//configure localization with new locale setting //configure localization with new locale setting
Application_Model_Locale::configureLocalization($formData['cu_locale']); Application_Model_Locale::configureLocalization($formData['cu_locale']);

View File

@ -0,0 +1,32 @@
<?php
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}";
}
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);
}
}

View File

@ -1,26 +1,43 @@
<?php <?php
require_once 'Cache.php';
class Application_Model_Preference class Application_Model_Preference
{ {
private static function getUserId()
{
//called from a daemon process
if (!class_exists("Zend_Auth", false) || !Zend_Auth::getInstance()->hasIdentity()) {
$userId = null;
}
else {
$auth = Zend_Auth::getInstance();
$userId = $auth->getIdentity()->id;
}
return $userId;
}
/** /**
* *
* @param integer $userId is not null when we are setting a locale for a specific user
* @param boolean $isUserValue is true when we are setting a value for the current user * @param boolean $isUserValue is true when we are setting a value for the current user
*/ */
private static function setValue($key, $value, $isUserValue = false, $userId = null) private static function setValue($key, $value, $isUserValue = false)
{ {
$cache = new Cache();
try { try {
$con = Propel::getConnection(CcPrefPeer::DATABASE_NAME); $con = Propel::getConnection(CcPrefPeer::DATABASE_NAME);
$con->beginTransaction(); $con->beginTransaction();
//called from a daemon process $userId = self::getUserId();
if (!class_exists("Zend_Auth", false) || !Zend_Auth::getInstance()->hasIdentity()) {
$id = NULL; if ($isUserValue && is_null($userId)) {
} else { throw new Exception("User id can't be null for a user preference {$key}.");
$auth = Zend_Auth::getInstance();
$id = $auth->getIdentity()->id;
} }
Application_Common_Database::prepareAndExecute("LOCK TABLE cc_pref");
//Check if key already exists //Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref" $sql = "SELECT COUNT(*) FROM cc_pref"
@ -30,15 +47,10 @@ class Application_Model_Preference
$paramMap[':key'] = $key; $paramMap[':key'] = $key;
//For user specific preference, check if id matches as well //For user specific preference, check if id matches as well
if ($isUserValue && is_null($userId)) { if ($isUserValue) {
$sql .= " AND subjid = :id"; $sql .= " AND subjid = :id";
$paramMap[':id'] = $id;
} else if (!is_null($userId)) {
$sql .= " AND subjid= :id";
$paramMap[':id'] = $userId; $paramMap[':id'] = $userId;
} }
Application_Common_Database::prepareAndExecute("LOCK TABLE cc_pref");
$result = Application_Common_Database::prepareAndExecute($sql, $result = Application_Common_Database::prepareAndExecute($sql,
$paramMap, $paramMap,
@ -51,39 +63,39 @@ class Application_Model_Preference
//this case should not happen. //this case should not happen.
throw new Exception("Invalid number of results returned. Should be ". throw new Exception("Invalid number of results returned. Should be ".
"0 or 1, but is '$result' instead"); "0 or 1, but is '$result' instead");
} elseif ($result == 1) { }
elseif ($result == 1) {
// result found // result found
if (is_null($id) || !$isUserValue) { if (is_null($userId)) {
// system pref // system pref
$sql = "UPDATE cc_pref" $sql = "UPDATE cc_pref"
." SET subjid = NULL, valstr = :value" ." SET subjid = NULL, valstr = :value"
." WHERE keystr = :key"; ." WHERE keystr = :key";
} else { }
else {
// user pref // user pref
$sql = "UPDATE cc_pref" $sql = "UPDATE cc_pref"
. " SET valstr = :value" . " SET valstr = :value"
. " WHERE keystr = :key AND subjid = :id"; . " WHERE keystr = :key AND subjid = :id";
if (is_null($userId)) {
$paramMap[':id'] = $id; $paramMap[':id'] = $userId;
} else {
$paramMap[':id'] = $userId;
}
} }
} else { }
else {
// result not found // result not found
if (is_null($id) || !$isUserValue) { if (is_null($userId)) {
// system pref // system pref
$sql = "INSERT INTO cc_pref (keystr, valstr)" $sql = "INSERT INTO cc_pref (keystr, valstr)"
." VALUES (:key, :value)"; ." VALUES (:key, :value)";
} else { }
else {
// user pref // user pref
$sql = "INSERT INTO cc_pref (subjid, keystr, valstr)" $sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
." VALUES (:id, :key, :value)"; ." VALUES (:id, :key, :value)";
if (is_null($userId)) {
$paramMap[':id'] = $id; $paramMap[':id'] = $userId;
} else {
$paramMap[':id'] = $userId;
}
} }
} }
$paramMap[':key'] = $key; $paramMap[':key'] = $key;
@ -96,18 +108,35 @@ class Application_Model_Preference
$con); $con);
$con->commit(); $con->commit();
} catch (Exception $e) { }
catch (Exception $e) {
$con->rollback(); $con->rollback();
header('HTTP/1.0 503 Service Unavailable'); header('HTTP/1.0 503 Service Unavailable');
Logging::info("Database error: ".$e->getMessage()); Logging::info("Database error: ".$e->getMessage());
exit; exit;
} }
$cache->store($key, $value, $isUserValue, $userId);
Logging::info("SAVING {$key} {$userId} into cache. = {$value}");
} }
private static function getValue($key, $isUserValue = false) private static function getValue($key, $isUserValue = false)
{ {
$cache = new Cache();
try { try {
$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;
}
//Check if key already exists //Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref" $sql = "SELECT COUNT(*) FROM cc_pref"
@ -117,20 +146,17 @@ class Application_Model_Preference
$paramMap[':key'] = $key; $paramMap[':key'] = $key;
//For user specific preference, check if id matches as well //For user specific preference, check if id matches as well
if ($isUserValue) { if (isset($userId)) {
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) { $sql .= " AND subjid = :id";
$id = $auth->getIdentity()->id; $paramMap[':id'] = $userId;
$sql .= " AND subjid = :id";
$paramMap[':id'] = $id;
}
} }
$result = Application_Common_Database::prepareAndExecute($sql, $paramMap, Application_Common_Database::COLUMN); $result = Application_Common_Database::prepareAndExecute($sql, $paramMap, Application_Common_Database::COLUMN);
//return an empty string if the result doesn't exist.
if ($result == 0) { if ($result == 0) {
return ""; $res = "";
} }
else { else {
$sql = "SELECT valstr FROM cc_pref" $sql = "SELECT valstr FROM cc_pref"
@ -140,16 +166,20 @@ class Application_Model_Preference
$paramMap[':key'] = $key; $paramMap[':key'] = $key;
//For user specific preference, check if id matches as well //For user specific preference, check if id matches as well
if ($isUserValue && $auth->hasIdentity()) { if (isset($userId)) {
$sql .= " AND subjid = :id"; $sql .= " AND subjid = :id";
$paramMap[':id'] = $id; $paramMap[':id'] = $userId;
} }
$result = Application_Common_Database::prepareAndExecute($sql, $paramMap, Application_Common_Database::COLUMN); $result = Application_Common_Database::prepareAndExecute($sql, $paramMap, Application_Common_Database::COLUMN);
return ($result !== false) ? $result : ""; $res = ($result !== false) ? $result : "";
} }
} catch (Exception $e) {
$cache->store($key, $res, $isUserValue, $userId);
return $res;
}
catch (Exception $e) {
header('HTTP/1.0 503 Service Unavailable'); header('HTTP/1.0 503 Service Unavailable');
Logging::info("Could not connect to database: ".$e->getMessage()); Logging::info("Could not connect to database: ".$e->getMessage());
exit; exit;
@ -509,6 +539,7 @@ class Application_Model_Preference
public static function SetDefaultTimezone($timezone) public static function SetDefaultTimezone($timezone)
{ {
self::setValue("timezone", $timezone); self::setValue("timezone", $timezone);
//TODO check this if setting value failes.
date_default_timezone_set($timezone); date_default_timezone_set($timezone);
} }
@ -518,22 +549,23 @@ class Application_Model_Preference
return self::getValue("timezone"); return self::getValue("timezone");
} }
public static function SetUserTimezone($userId, $timezone = null) public static function SetUserTimezone($timezone = null)
{ {
// When a new user is created they will get the default timezone // When a new user is created they will get the default timezone
// setting which the admin sets on preferences page // setting which the admin sets on preferences page
if (is_null($timezone)) { if (is_null($timezone)) {
$timezone = self::GetDefaultTimezone(); $timezone = self::GetDefaultTimezone();
} }
self::setValue("user_timezone", $timezone, true, $userId); self::setValue("user_timezone", $timezone, true);
} }
public static function GetUserTimezone($id) public static function GetUserTimezone()
{ {
$timezone = self::getValue("user_timezone", true); $timezone = self::getValue("user_timezone", true);
if (!$timezone) { if (!$timezone) {
return self::GetDefaultTimezone(); return self::GetDefaultTimezone();
} else { }
else {
return $timezone; return $timezone;
} }
} }
@ -541,11 +573,12 @@ class Application_Model_Preference
// Always attempts to returns the current user's personal timezone setting // Always attempts to returns the current user's personal timezone setting
public static function GetTimezone() public static function GetTimezone()
{ {
$auth = Zend_Auth::getInstance(); $userId = self::getUserId();
if ($auth->hasIdentity()) {
$id = $auth->getIdentity()->id; if (!is_null($userId)) {
return self::GetUserTimezone($id); return self::GetUserTimezone();
} else { }
else {
return self::GetDefaultTimezone(); return self::GetDefaultTimezone();
} }
} }
@ -561,33 +594,35 @@ class Application_Model_Preference
return self::getValue("locale"); return self::getValue("locale");
} }
public static function GetUserLocale($id) public static function GetUserLocale()
{ {
$locale = self::getValue("user_locale", true); $locale = self::getValue("user_locale", true);
if (!$locale) { if (!$locale) {
return self::GetDefaultLocale(); return self::GetDefaultLocale();
} else { }
else {
return $locale; return $locale;
} }
} }
public static function SetUserLocale($userId, $locale = null) public static function SetUserLocale($locale = null)
{ {
// When a new user is created they will get the default locale // When a new user is created they will get the default locale
// setting which the admin sets on preferences page // setting which the admin sets on preferences page
if (is_null($locale)) { if (is_null($locale)) {
$locale = self::GetDefaultLocale(); $locale = self::GetDefaultLocale();
} }
self::setValue("user_locale", $locale, true, $userId); self::setValue("user_locale", $locale, true);
} }
public static function GetLocale() public static function GetLocale()
{ {
$auth = Zend_Auth::getInstance(); $userId = self::getUserId();
if ($auth->hasIdentity()) {
$id = $auth->getIdentity()->id; if (!is_null($userId)) {
return self::GetUserLocale($id); return self::GetUserLocale();
} else { }
else {
return self::GetDefaultLocale(); return self::GetDefaultLocale();
} }
} }
@ -1295,15 +1330,8 @@ class Application_Model_Preference
public static function setCurrentLibraryTableSetting($settings) public static function setCurrentLibraryTableSetting($settings)
{ {
$num_columns = count(Application_Model_StoredFile::getLibraryColumns());
$new_columns_num = count($settings['abVisCols']);
/*if ($num_columns != $new_columns_num) {
throw new Exception("Trying to write a user column preference with incorrect number of columns!");
}*/
$data = serialize($settings); $data = serialize($settings);
$v = self::setValue("library_datatable", $data, true); self::setValue("library_datatable", $data, true);
} }
public static function getCurrentLibraryTableSetting() public static function getCurrentLibraryTableSetting()

View File

@ -173,6 +173,10 @@ class Application_Service_SchedulerService
* any other instances with content * any other instances with content
*/ */
$instanceIds = $ccShow->getInstanceIds(); $instanceIds = $ccShow->getInstanceIds();
if (count($instanceIds) == 0) {
return;
}
$schedule_sql = "SELECT * FROM cc_schedule ". $schedule_sql = "SELECT * FROM cc_schedule ".
"WHERE instance_id IN (".implode($instanceIds, ",").")"; "WHERE instance_id IN (".implode($instanceIds, ",").")";
$ccSchedules = Application_Common_Database::prepareAndExecute( $ccSchedules = Application_Common_Database::prepareAndExecute(
@ -427,4 +431,4 @@ class Application_Service_SchedulerService
return $redraw; return $redraw;
} }
} }

View File

@ -163,11 +163,6 @@ class Application_Service_ShowService
$this->storeOrigLocalShowInfo(); $this->storeOrigLocalShowInfo();
// updates cc_show_instances start/end times, and updates
// schedule start/end times
// **Not sure why this function is here. It seems unnecesssary
//$this->applyShowStartEndDifference($showData);
$this->deleteRebroadcastInstances(); $this->deleteRebroadcastInstances();
$this->deleteCcShowDays(); $this->deleteCcShowDays();

View File

@ -59,7 +59,7 @@ libtaglib-ocaml libao-ocaml libmad-ocaml ecasound \
libesd0 libportaudio2 libsamplerate0 rabbitmq-server patch \ libesd0 libportaudio2 libsamplerate0 rabbitmq-server patch \
php5-curl mpg123 monit python-virtualenv multitail libcamomile-ocaml-data \ php5-curl mpg123 monit python-virtualenv multitail libcamomile-ocaml-data \
libpulse0 vorbis-tools lsb-release lsof sudo mp3gain vorbisgain flac vorbis-tools \ libpulse0 vorbis-tools lsb-release lsof sudo mp3gain vorbisgain flac vorbis-tools \
pwgen libfaad2 pwgen libfaad2 php-apc
#install packages with --force-yes option (this is useful in the case #install packages with --force-yes option (this is useful in the case