Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
denise 2012-05-07 10:22:41 -04:00
commit b5db91f0f4
21 changed files with 464 additions and 141 deletions

View file

@ -3,102 +3,109 @@
class Application_Model_Preference
{
public static function SetValue($key, $value, $isUserValue = false){
global $CC_CONFIG;
$con = Propel::getConnection();
//called from a daemon process
if(!class_exists("Zend_Auth", false) || !Zend_Auth::getInstance()->hasIdentity()) {
$id = NULL;
}
else {
$auth = Zend_Auth::getInstance();
$id = $auth->getIdentity()->id;
}
$key = pg_escape_string($key);
$value = pg_escape_string($value);
//Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref"
." WHERE keystr = '$key'";
//For user specific preference, check if id matches as well
if($isUserValue) {
$sql .= " AND subjid = '$id'";
}
$result = $con->query($sql)->fetchColumn(0);
if($value == "") {
$value = "NULL";
}else {
$value = "'$value'";
}
if($result == 1) {
// result found
if(is_null($id) || !$isUserValue) {
// system pref
$sql = "UPDATE cc_pref"
." SET subjid = NULL, valstr = $value"
." WHERE keystr = '$key'";
} else {
// user pref
$sql = "UPDATE cc_pref"
. " SET valstr = $value"
. " WHERE keystr = '$key' AND subjid = $id";
}
} else {
// result not found
if(is_null($id) || !$isUserValue) {
// system pref
$sql = "INSERT INTO cc_pref (keystr, valstr)"
." VALUES ('$key', $value)";
} else {
// user pref
$sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
." VALUES ($id, '$key', $value)";
}
}
public static function SetValue($key, $value, $isUserValue = false){
try {
$con->exec($sql);
} catch (Exception $e){
Logging::log("Could not connect to database.");
header('HTTP/1.0 503 Service Unavailable');
exit;
}
}
$con = Propel::getConnection();
public static function GetValue($key, $isUserValue = false){
global $CC_CONFIG;
$con = Propel::getConnection();
//called from a daemon process
if(!class_exists("Zend_Auth", false) || !Zend_Auth::getInstance()->hasIdentity()) {
$id = NULL;
}
else {
$auth = Zend_Auth::getInstance();
$id = $auth->getIdentity()->id;
}
//Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref"
." WHERE keystr = '$key'";
//For user specific preference, check if id matches as well
if ($isUserValue) {
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity()) {
$id = $auth->getIdentity()->id;
$sql .= " AND subjid = '$id'";
}
}
$result = $con->query($sql)->fetchColumn(0);
if ($result == 0)
return "";
else {
$sql = "SELECT valstr FROM cc_pref"
$key = pg_escape_string($key);
$value = pg_escape_string($value);
//Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref"
." WHERE keystr = '$key'";
//For user specific preference, check if id matches as well
if($isUserValue && $auth->hasIdentity()) {
$sql .= " AND subjid = '$id'";
}
//For user specific preference, check if id matches as well
if($isUserValue) {
$sql .= " AND subjid = '$id'";
}
$result = $con->query($sql)->fetchColumn(0);
return ($result !== false) ? $result : "";
if($value == "") {
$value = "NULL";
}else {
$value = "'$value'";
}
if($result == 1) {
// result found
if(is_null($id) || !$isUserValue) {
// system pref
$sql = "UPDATE cc_pref"
." SET subjid = NULL, valstr = $value"
." WHERE keystr = '$key'";
} else {
// user pref
$sql = "UPDATE cc_pref"
. " SET valstr = $value"
. " WHERE keystr = '$key' AND subjid = $id";
}
} else {
// result not found
if(is_null($id) || !$isUserValue) {
// system pref
$sql = "INSERT INTO cc_pref (keystr, valstr)"
." VALUES ('$key', $value)";
} else {
// user pref
$sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
." VALUES ($id, '$key', $value)";
}
}
$con->exec($sql);
} catch (Exception $e){
header('HTTP/1.0 503 Service Unavailable');
Logging::log("Could not connect to database.");
exit;
}
}
public static function GetValue($key, $isUserValue = false){
try {
$con = Propel::getConnection();
//Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref"
." WHERE keystr = '$key'";
//For user specific preference, check if id matches as well
if ($isUserValue) {
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity()) {
$id = $auth->getIdentity()->id;
$sql .= " AND subjid = '$id'";
}
}
$result = $con->query($sql)->fetchColumn(0);
if ($result == 0)
return "";
else {
$sql = "SELECT valstr FROM cc_pref"
." WHERE keystr = '$key'";
//For user specific preference, check if id matches as well
if($isUserValue && $auth->hasIdentity()) {
$sql .= " AND subjid = '$id'";
}
$result = $con->query($sql)->fetchColumn(0);
return ($result !== false) ? $result : "";
}
} catch (Exception $e) {
header('HTTP/1.0 503 Service Unavailable');
Logging::log("Could not connect to database.");
exit;
}
}
@ -567,10 +574,12 @@ class Application_Model_Preference
public static function GetAirtimeVersion(){
if (defined('APPLICATION_ENV') && APPLICATION_ENV == "development" && function_exists('exec')){
return self::GetValue("system_version")."+".exec("git rev-parse --short HEAD");
} else {
return self::GetValue("system_version");
$version = exec("git rev-parse --short HEAD 2>/dev/null", $out, $return_code);
if ($return_code == 0){
return self::GetValue("system_version")."+".$version;
}
}
return self::GetValue("system_version");
}
public static function GetLatestVersion(){

View file

@ -25,6 +25,12 @@ class Application_Model_Scheduler {
$this->epochNow = microtime(true);
$this->nowDT = DateTime::createFromFormat("U.u", $this->epochNow, new DateTimeZone("UTC"));
if ($this->nowDT === false){
// DateTime::createFromFormat does not support millisecond string formatting in PHP 5.3.2 (Ubuntu 10.04).
// In PHP 5.3.3 (Ubuntu 10.10), this has been fixed.
$this->nowDT = DateTime::createFromFormat("U", time(), new DateTimeZone("UTC"));
}
$this->user = Application_Model_User::GetCurrentUser();
}
@ -190,6 +196,12 @@ class Application_Model_Scheduler {
$endEpoch = bcadd($startEpoch , (string) $durationSeconds, 6);
$dt = DateTime::createFromFormat("U.u", $endEpoch, new DateTimeZone("UTC"));
if ($dt === false) {
//PHP 5.3.2 problem
$dt = DateTime::createFromFormat("U", intval($endEpoch), new DateTimeZone("UTC"));
}
return $dt;
}

View file

@ -250,6 +250,15 @@ class Application_Model_ShowBuilder {
//show is empty or is a special kind of show (recording etc)
else if (intval($p_item["si_record"]) === 1) {
$row["record"] = true;
$row["instance"] = intval($p_item["si_id"]);
$showStartDT = new DateTime($p_item["si_starts"], new DateTimeZone("UTC"));
$showEndDT = new DateTime($p_item["si_ends"], new DateTimeZone("UTC"));
$startsEpoch = floatval($showStartDT->format("U.u"));
$endsEpoch = floatval($showEndDT->format("U.u"));
$this->getScheduledStatus($startsEpoch, $endsEpoch, $row);
}
else {
$row["empty"] = true;
@ -261,7 +270,7 @@ class Application_Model_ShowBuilder {
$row["rebroadcast"] = true;
}
if ($this->currentShow = true) {
if ($this->currentShow === true) {
$row["currentShow"] = true;
}
@ -297,7 +306,7 @@ class Application_Model_ShowBuilder {
$row["refresh"] = floatval($showEndDT->format("U.u")) - $this->epoch_now;
if ($this->currentShow = true) {
if ($this->currentShow === true) {
$row["currentShow"] = true;
}

View file

@ -91,6 +91,27 @@ class Application_Model_StoredFile {
}
else {
$dbMd = array();
if (isset($p_md["MDATA_KEY_YEAR"])){
// We need to make sure to clean this value before inserting into database.
// If value is outside of range [-2^31, 2^31-1] then postgresl will throw error
// when trying to retrieve this value. We could make sure number is within these bounds,
// but simplest is to do substring to 4 digits (both values are garbage, but at least our
// new garbage value won't cause errors). If the value is 2012-01-01, then substring to
// 4 digits is an OK result.
// CC-3771
$year = $p_md["MDATA_KEY_YEAR"];
if (strlen($year) > 4){
$year = substr($year, 0, 4);
}
if (!is_numeric($year)){
$year = 0;
}
$p_md["MDATA_KEY_YEAR"] = $year;
}
foreach ($p_md as $mdConst => $mdValue) {
$dbMd[constant($mdConst)] = $mdValue;
}