CC-1927: Remove PEAR DB

First pass through the model classes to remove use of $CC_DBC.
Web application is working.
There are still other parts of the app that use PEAR DB.
This commit is contained in:
paul.baranowski 2012-04-01 15:51:03 -04:00 committed by Martin Konecny
parent f69a172ee1
commit 7f78a7f663
13 changed files with 630 additions and 565 deletions

View file

@ -10,7 +10,7 @@ require_once 'propel/runtime/lib/Propel.php';
Propel::init(__DIR__."/configs/airtime-conf-production.php"); Propel::init(__DIR__."/configs/airtime-conf-production.php");
require_once __DIR__."/configs/constants.php"; require_once __DIR__."/configs/constants.php";
require_once 'DB.php'; // require_once 'DB.php';
require_once 'Preference.php'; require_once 'Preference.php';
require_once "DateHelper.php"; require_once "DateHelper.php";
@ -20,12 +20,34 @@ require_once __DIR__.'/controllers/plugins/RabbitMqPlugin.php';
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$dsn = $CC_CONFIG['dsn']; $dsn = $CC_CONFIG['dsn'];
$CC_DBC = DB::connect($dsn, FALSE); // ******************************************************************
if (PEAR::isError($CC_DBC)) { // Differences between PEAR DB & Propel/PDO:
echo "ERROR: ".$CC_DBC->getMessage()." ".$CC_DBC->getUserInfo()."\n"; // When selecting a single value from a null return set,
exit(1); // PEAR returns NULL
} // PDO returns false
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC); // ******************************************************************
// $CC_DBC = DB::connect($dsn, FALSE);
// if (PEAR::isError($CC_DBC)) {
// echo "ERROR: ".$CC_DBC->getMessage()." ".$CC_DBC->getUserInfo()."\n";
// exit(1);
// }
// $CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
// $sql = "SELECT column_name, character_maximum_length FROM information_schema.columns"
// ." WHERE table_name = 'cc_show' AND character_maximum_length > 0 and table_name=''";
// // $sql = "SELECT * FROM cc_files WHERE id=1";
// // $result = $CC_DBC->GetAll($sql);
// $result = $CC_DBC->GetOne($sql);
// var_dump($result);
// $con = Propel::getConnection();
// $q = $con->query($sql);
// //var_dump($q);
// //var_dump($q->fetchAll());
// var_dump($q->fetchColumn(0));
// exit;
$CC_CONFIG['airtime_version'] = Application_Model_Preference::GetAirtimeVersion(); $CC_CONFIG['airtime_version'] = Application_Model_Preference::GetAirtimeVersion();

View file

@ -342,7 +342,7 @@ class ApiController extends Zend_Controller_Action
exit; exit;
} }
PEAR::setErrorHandling(PEAR_ERROR_RETURN); //PEAR::setErrorHandling(PEAR_ERROR_RETURN);
$data = Application_Model_Schedule::GetScheduledPlaylists(); $data = Application_Model_Schedule::GetScheduledPlaylists();
echo json_encode($data, JSON_FORCE_OBJECT); echo json_encode($data, JSON_FORCE_OBJECT);

View file

@ -5,41 +5,32 @@ class Application_Model_LoginAttempts {
} }
public static function increaseAttempts($ip){ public static function increaseAttempts($ip){
global $CC_DBC; $con = Propel::getConnection();
$sql = "select count(*) from cc_login_attempts WHERE ip='$ip'"; $sql = "select count(*) from cc_login_attempts WHERE ip='$ip'";
$res = $CC_DBC->GetOne($sql); $res = $con->query($sql)->fetchColumn(0);
if($res){ if ($res) {
$sql = "UPDATE cc_login_attempts SET attempts=attempts+1 WHERE ip='$ip'"; $sql = "UPDATE cc_login_attempts SET attempts=attempts+1 WHERE ip='$ip'";
$res = $CC_DBC->query($sql); $con->exec($sql);
if (PEAR::isError($res)) { } else {
return $res;
}
}else{
$sql = "INSERT INTO cc_login_attempts (ip, attempts) values ('$ip', '1')"; $sql = "INSERT INTO cc_login_attempts (ip, attempts) values ('$ip', '1')";
$res = $CC_DBC->query($sql); $con->exec($sql);
if (PEAR::isError($res)) {
return $res;
}
} }
} }
public static function getAttempts($ip){ public static function getAttempts($ip){
global $CC_DBC; $con = Propel::getConnection();
$sql = "select attempts from cc_login_attempts WHERE ip='$ip'"; $sql = "select attempts from cc_login_attempts WHERE ip='$ip'";
$res = $CC_DBC->GetOne($sql); $res = $con->query($sql)->fetchColumn(0);
return $res; return $res ? $res : 0;
} }
public static function resetAttempts($ip){ public static function resetAttempts($ip){
global $CC_DBC; $con = Propel::getConnection();
$sql = "select count(*) from cc_login_attempts WHERE ip='$ip'"; $sql = "select count(*) from cc_login_attempts WHERE ip='$ip'";
$res = $CC_DBC->GetOne($sql); $res = $con->query($sql)->fetchColumn(0);
if($res){ if ($res > 0) {
$sql = "DELETE FROM cc_login_attempts WHERE ip='$ip'"; $sql = "DELETE FROM cc_login_attempts WHERE ip='$ip'";
$res = $CC_DBC->query($sql); $con->exec($sql);
if (PEAR::isError($res)) {
return $res;
}
} }
} }
} }

View file

@ -58,7 +58,8 @@ class Application_Model_MusicDir {
return $this->_dir->getExists(); return $this->_dir->getExists();
} }
/** There are 2 cases where this function can be called. /**
* There are 2 cases where this function can be called.
* 1. When watched dir was removed * 1. When watched dir was removed
* 2. When some dir was watched, but it was unmounted * 2. When some dir was watched, but it was unmounted
* *
@ -67,24 +68,26 @@ class Application_Model_MusicDir {
* *
* When $userAddedWatchedDir is true, it will set "Watched" flag to false * When $userAddedWatchedDir is true, it will set "Watched" flag to false
* otherwise, it will set "Exists" flag to true * otherwise, it will set "Exists" flag to true
**/ */
public function remove($userAddedWatchedDir=true) public function remove($userAddedWatchedDir=true)
{ {
global $CC_DBC; $con = Propel::getConnection();
$music_dir_id = $this->getId(); $music_dir_id = $this->getId();
$sql = "SELECT DISTINCT s.instance_id from cc_music_dirs as md LEFT JOIN cc_files as f on f.directory = md.id $sql = "SELECT DISTINCT s.instance_id from cc_music_dirs as md "
RIGHT JOIN cc_schedule as s on s.file_id = f.id WHERE md.id = $music_dir_id"; ." LEFT JOIN cc_files as f on f.directory = md.id"
." RIGHT JOIN cc_schedule as s on s.file_id = f.id WHERE md.id = $music_dir_id";
$show_instances = $CC_DBC->GetAll($sql); $show_instances = $con->query($sql)->fetchAll();
// get all the files on this dir // get all the files on this dir
$sql = "SELECT f.id FROM cc_music_dirs as md LEFT JOIN cc_files as f on f.directory = md.id WHERE md.id = $music_dir_id"; $sql = "SELECT f.id FROM cc_music_dirs as md "
$files = $CC_DBC->GetAll($sql); ." LEFT JOIN cc_files as f on f.directory = md.id WHERE md.id = $music_dir_id";
$files = $con->query($sql)->fetchAll();
// set file_exist flag to false // set file_exist flag to false
foreach( $files as $file_row ){ foreach ($files as $file_row) {
$temp_file = Application_Model_StoredFile::Recall($file_row['id']); $temp_file = Application_Model_StoredFile::Recall($file_row['id']);
if($temp_file != null){ if($temp_file != null){
$temp_file->setFileExistsFlag(false); $temp_file->setFileExistsFlag(false);
@ -92,9 +95,9 @@ class Application_Model_MusicDir {
} }
// set RemovedFlag to true // set RemovedFlag to true
if($userAddedWatchedDir){ if ($userAddedWatchedDir) {
self::setWatchedFlag(false); self::setWatchedFlag(false);
}else{ } else {
self::setExistsFlag(false); self::setExistsFlag(false);
} }
//$res = $this->_dir->delete(); //$res = $this->_dir->delete();

View file

@ -769,10 +769,12 @@ class Application_Model_Playlist {
return $res; return $res;
} }
public static function getPlaylistCount(){ public static function getPlaylistCount()
global $CC_CONFIG, $CC_DBC; {
global $CC_CONFIG;
$con = Propel::getConnection();
$sql = 'SELECT count(*) as cnt FROM '.$CC_CONFIG["playListTable"]; $sql = 'SELECT count(*) as cnt FROM '.$CC_CONFIG["playListTable"];
return $CC_DBC->GetOne($sql); return $con->query($sql)->fetchColumn(0);
} }
/** /**

View file

@ -4,7 +4,8 @@ class Application_Model_Preference
{ {
public static function SetValue($key, $value, $isUserValue = false){ public static function SetValue($key, $value, $isUserValue = false){
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
//called from a daemon process //called from a daemon process
if(!class_exists("Zend_Auth", false) || !Zend_Auth::getInstance()->hasIdentity()) { if(!class_exists("Zend_Auth", false) || !Zend_Auth::getInstance()->hasIdentity()) {
@ -27,7 +28,7 @@ class Application_Model_Preference
$sql .= " AND subjid = '$id'"; $sql .= " AND subjid = '$id'";
} }
$result = $CC_DBC->GetOne($sql); $result = $con->query($sql)->fetchColumn(0);
if($result == 1) { if($result == 1) {
// result found // result found
@ -55,25 +56,25 @@ class Application_Model_Preference
} }
} }
return $CC_DBC->query($sql); return $con->exec($sql);
} }
public static function GetValue($key, $isUserValue = false){ public static function GetValue($key, $isUserValue = false){
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
//Check if key already exists //Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref" $sql = "SELECT COUNT(*) FROM cc_pref"
." WHERE keystr = '$key'"; ." WHERE keystr = '$key'";
//For user specific preference, check if id matches as well //For user specific preference, check if id matches as well
if($isUserValue) { if ($isUserValue) {
$auth = Zend_Auth::getInstance(); $auth = Zend_Auth::getInstance();
if($auth->hasIdentity()) { if($auth->hasIdentity()) {
$id = $auth->getIdentity()->id; $id = $auth->getIdentity()->id;
$sql .= " AND subjid = '$id'"; $sql .= " AND subjid = '$id'";
} }
} }
$result = $CC_DBC->GetOne($sql); $result = $con->query($sql)->fetchColumn(0);
if ($result == 0) if ($result == 0)
return ""; return "";
else { else {
@ -85,8 +86,8 @@ class Application_Model_Preference
$sql .= " AND subjid = '$id'"; $sql .= " AND subjid = '$id'";
} }
$result = $CC_DBC->GetOne($sql); $result = $con->query($sql)->fetchColumn(0);
return $result; return $result ? $result : "";
} }
} }
@ -365,10 +366,11 @@ class Application_Model_Preference
return self::GetValue("uniqueId"); return self::GetValue("uniqueId");
} }
public static function GetCountryList(){ public static function GetCountryList()
global $CC_DBC; {
$con = Propel::getConnection();
$sql = "SELECT * FROM cc_country"; $sql = "SELECT * FROM cc_country";
$res = $CC_DBC->GetAll($sql); $res = $con->query($sql)->fetchAll();
$out = array(); $out = array();
$out[""] = "Select Country"; $out[""] = "Select Country";
foreach($res as $r){ foreach($res as $r){

View file

@ -9,10 +9,11 @@ class Application_Model_Schedule {
*/ */
public function IsFileScheduledInTheFuture($p_fileId) public function IsFileScheduledInTheFuture($p_fileId)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT COUNT(*) FROM ".$CC_CONFIG["scheduleTable"] $sql = "SELECT COUNT(*) FROM ".$CC_CONFIG["scheduleTable"]
." WHERE file_id = {$p_fileId} AND starts > NOW()"; ." WHERE file_id = {$p_fileId} AND starts > NOW()";
$count = $CC_DBC->GetOne($sql); $count = $con->query($sql)->fetchColumn(0);
if (is_numeric($count) && ($count != '0')) { if (is_numeric($count) && ($count != '0')) {
return TRUE; return TRUE;
} else { } else {
@ -70,18 +71,19 @@ class Application_Model_Schedule {
if ($p_previousShowID == null && $p_currentShowID == null && $p_nextShowID == null) if ($p_previousShowID == null && $p_currentShowID == null && $p_nextShowID == null)
return; return;
global $CC_CONFIG, $CC_DBC;
$sql = 'Select ft.artist_name, global $CC_CONFIG;
ft.track_title, $con = Propel::getConnection();
st.starts as starts, $sql = 'Select ft.artist_name, ft.track_title, st.starts as starts, st.ends as ends, st.media_item_played as media_item_played, si.ends as show_ends
st.ends as ends, FROM cc_schedule st LEFT JOIN cc_files ft ON st.file_id = ft.id LEFT JOIN cc_show_instances si on st.instance_id = si.id
st.media_item_played as media_item_played,
si.ends as show_ends
FROM cc_schedule st
LEFT JOIN cc_files ft ON st.file_id = ft.id
LEFT JOIN cc_show_instances si on st.instance_id = si.id
WHERE '; WHERE ';
/* Alternate SQL...merge conflict and I'm not sure which on is right.... -MK
$sql = 'Select ft.artist_name, ft.track_title, st.starts as starts, st.ends as ends, st.media_item_played as media_item_played, si.ends as show_ends
FROM cc_schedule st LEFT JOIN cc_files ft ON st.file_id = ft.id
WHERE ';
*/
if (isset($p_previousShowID)){ if (isset($p_previousShowID)){
if (isset($p_nextShowID) || isset($p_currentShowID)) if (isset($p_nextShowID) || isset($p_currentShowID))
$sql .= '('; $sql .= '(';
@ -105,8 +107,8 @@ class Application_Model_Schedule {
$sql .= ' AND st.playout_status > 0 ORDER BY st.starts'; $sql .= ' AND st.playout_status > 0 ORDER BY st.starts';
$rows = $CC_DBC->GetAll($sql);
$rows = $con->query($sql)->fetchAll();
$numberOfRows = count($rows); $numberOfRows = count($rows);
$results['previous'] = null; $results['previous'] = null;
@ -130,7 +132,6 @@ class Application_Model_Schedule {
"ends"=> (($rows[$i]["ends"] > $rows[$i]["show_ends"]) ? $rows[$i]["show_ends"]: $rows[$i]["ends"]), "ends"=> (($rows[$i]["ends"] > $rows[$i]["show_ends"]) ? $rows[$i]["show_ends"]: $rows[$i]["ends"]),
"media_item_played"=>$rows[$i]["media_item_played"], "media_item_played"=>$rows[$i]["media_item_played"],
"record"=>0); "record"=>0);
if ( isset($rows[$i+1])){ if ( isset($rows[$i+1])){
$results['next'] = array("name"=>$rows[$i+1]["artist_name"]." - ".$rows[$i+1]["track_title"], $results['next'] = array("name"=>$rows[$i+1]["artist_name"]." - ".$rows[$i+1]["track_title"],
"starts"=>$rows[$i+1]["starts"], "starts"=>$rows[$i+1]["starts"],
@ -159,8 +160,8 @@ class Application_Model_Schedule {
} }
public static function GetLastScheduleItem($p_timeNow){ public static function GetLastScheduleItem($p_timeNow){
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT" $sql = "SELECT"
." ft.artist_name, ft.track_title," ." ft.artist_name, ft.track_title,"
." st.starts as starts, st.ends as ends" ." st.starts as starts, st.ends as ends"
@ -175,14 +176,14 @@ class Application_Model_Schedule {
." ORDER BY st.ends DESC" ." ORDER BY st.ends DESC"
." LIMIT 1"; ." LIMIT 1";
$row = $CC_DBC->GetAll($sql); $row = $con->query($sql)->fetchAll();
return $row; return $row;
} }
public static function GetCurrentScheduleItem($p_timeNow, $p_instanceId){ public static function GetCurrentScheduleItem($p_timeNow, $p_instanceId){
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
/* Note that usually there will be one result returned. In some /* Note that usually there will be one result returned. In some
* rare cases two songs are returned. This happens when a track * rare cases two songs are returned. This happens when a track
* that was overbooked from a previous show appears as if it * that was overbooked from a previous show appears as if it
@ -200,13 +201,13 @@ class Application_Model_Schedule {
." ORDER BY st.starts DESC" ." ORDER BY st.starts DESC"
." LIMIT 1"; ." LIMIT 1";
$row = $CC_DBC->GetAll($sql); $row = $con->query($sql)->fetchAll();
return $row; return $row;
} }
public static function GetNextScheduleItem($p_timeNow){ public static function GetNextScheduleItem($p_timeNow){
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT" $sql = "SELECT"
." ft.artist_name, ft.track_title," ." ft.artist_name, ft.track_title,"
." st.starts as starts, st.ends as ends" ." st.starts as starts, st.ends as ends"
@ -221,7 +222,7 @@ class Application_Model_Schedule {
." ORDER BY st.starts" ." ORDER BY st.starts"
." LIMIT 1"; ." LIMIT 1";
$row = $CC_DBC->GetAll($sql); $row = $con->query($sql)->fetchAll();
return $row; return $row;
} }
@ -236,8 +237,8 @@ class Application_Model_Schedule {
*/ */
public static function GetScheduleDetailItems($p_start, $p_end, $p_shows) public static function GetScheduleDetailItems($p_start, $p_end, $p_shows)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT DISTINCT $sql = "SELECT DISTINCT
showt.name AS show_name, showt.color AS show_color, showt.name AS show_name, showt.color AS show_color,
@ -273,24 +274,27 @@ class Application_Model_Schedule {
$sql .= " ORDER BY si.starts, sched.starts;"; $sql .= " ORDER BY si.starts, sched.starts;";
$rows = $CC_DBC->GetAll($sql); $rows = $con->query($sql)->fetchAll();
return $rows; return $rows;
} }
public static function UpdateMediaPlayedStatus($p_id) public static function UpdateMediaPlayedStatus($p_id)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "UPDATE ".$CC_CONFIG['scheduleTable'] $sql = "UPDATE ".$CC_CONFIG['scheduleTable']
." SET media_item_played=TRUE" ." SET media_item_played=TRUE"
." WHERE id=$p_id"; ." WHERE id=$p_id";
$retVal = $CC_DBC->query($sql); $retVal = $con->exec($sql);
return $retVal; return $retVal;
} }
public static function getSchduledPlaylistCount(){ public static function getSchduledPlaylistCount()
global $CC_CONFIG, $CC_DBC; {
global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT count(*) as cnt FROM ".$CC_CONFIG['scheduleTable']; $sql = "SELECT count(*) as cnt FROM ".$CC_CONFIG['scheduleTable'];
return $CC_DBC->GetOne($sql); return $con->query($sql)->fetchColumn(0);
} }
@ -409,7 +413,8 @@ class Application_Model_Schedule {
* arrays representing each row. * arrays representing each row.
*/ */
public static function GetItems($p_startTime, $p_endTime) { public static function GetItems($p_startTime, $p_endTime) {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
$baseQuery = "SELECT st.file_id AS file_id," $baseQuery = "SELECT st.file_id AS file_id,"
." st.id as id," ." st.id as id,"
@ -435,13 +440,10 @@ class Application_Model_Schedule {
$sql = $baseQuery.$predicates; $sql = $baseQuery.$predicates;
$rows = $CC_DBC->GetAll($sql); $rows = $con->query($sql)->fetchAll();
if (PEAR::isError($rows)) {
return null;
}
if (count($rows) < 3){ if (count($rows) < 3){
Logging::debug("Get Schedule: Less than 3 results returned. Do another query in an attempt to get 3."); Logging::debug("Get Schedule: Less than 3 results returned. Doing another query since we need a minimum of 3 results.");
$dt = new DateTime("@".time()); $dt = new DateTime("@".time());
$dt->add(new DateInterval("PT24H")); $dt->add(new DateInterval("PT24H"));
@ -455,10 +457,7 @@ class Application_Model_Schedule {
." LIMIT 3"; ." LIMIT 3";
$sql = $baseQuery.$predicates; $sql = $baseQuery.$predicates;
$rows = $CC_DBC->GetAll($sql); $rows = $con->query($sql)->fetchAll();
if (PEAR::isError($rows)) {
return null;
}
} }
return $rows; return $rows;
@ -466,7 +465,7 @@ class Application_Model_Schedule {
public static function GetScheduledPlaylists($p_fromDateTime = null, $p_toDateTime = null){ public static function GetScheduledPlaylists($p_fromDateTime = null, $p_toDateTime = null){
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
/* if $p_fromDateTime and $p_toDateTime function parameters are null, then set range /* if $p_fromDateTime and $p_toDateTime function parameters are null, then set range
* from "now" to "now + 24 hours". */ * from "now" to "now + 24 hours". */
@ -576,8 +575,9 @@ class Application_Model_Schedule {
public static function deleteAll() public static function deleteAll()
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$CC_DBC->query("TRUNCATE TABLE ".$CC_CONFIG["scheduleTable"]); $con = Propel::getConnection();
$con->exec("TRUNCATE TABLE ".$CC_CONFIG["scheduleTable"]);
} }
public static function deleteWithFileId($fileId){ public static function deleteWithFileId($fileId){

View file

@ -113,16 +113,16 @@ class Application_Model_Show {
public function getHosts() public function getHosts()
{ {
global $CC_DBC; $con = Propel::getConnection();
$sql = "SELECT first_name, last_name $sql = "SELECT first_name, last_name
FROM cc_show_hosts LEFT JOIN cc_subjs ON cc_show_hosts.subjs_id = cc_subjs.id FROM cc_show_hosts LEFT JOIN cc_subjs ON cc_show_hosts.subjs_id = cc_subjs.id
WHERE show_id = {$this->_showId}"; WHERE show_id = {$this->_showId}";
$hosts = $CC_DBC->GetAll($sql); $hosts = $con->query($sql)->fetchAll();
$res = array(); $res = array();
foreach($hosts as $host) { foreach ($hosts as $host) {
$res[] = $host['first_name']." ".$host['last_name']; $res[] = $host['first_name']." ".$host['last_name'];
} }
@ -131,18 +131,20 @@ class Application_Model_Show {
public function getHostsIds() public function getHostsIds()
{ {
global $CC_DBC; $con = Propel::getConnection();
$sql = "SELECT subjs_id $sql = "SELECT subjs_id
FROM cc_show_hosts FROM cc_show_hosts
WHERE show_id = {$this->_showId}"; WHERE show_id = {$this->_showId}";
$hosts = $CC_DBC->GetAll($sql); $hosts = $con->query($sql)->fetchAll();
return $hosts; return $hosts;
} }
//remove everything about this show. /**
* remove everything about this show.
*/
public function delete() public function delete()
{ {
//usually we hide the show-instance, but in this case we are deleting the show template //usually we hide the show-instance, but in this case we are deleting the show template
@ -155,7 +157,7 @@ class Application_Model_Show {
public function resizeShow($deltaDay, $deltaMin) public function resizeShow($deltaDay, $deltaMin)
{ {
global $CC_DBC; $con = Propel::getConnection();
if ($deltaDay > 0) { if ($deltaDay > 0) {
return "Shows can have a max length of 24 hours."; return "Shows can have a max length of 24 hours.";
@ -186,7 +188,7 @@ class Application_Model_Show {
AND ((CAST(duration AS interval) + interval '{$deltaDay} days' + interval '{$hours}:{$mins}') <= interval '24:00')"; AND ((CAST(duration AS interval) + interval '{$deltaDay} days' + interval '{$hours}:{$mins}') <= interval '24:00')";
//do both the queries at once. //do both the queries at once.
$CC_DBC->query($sql); $con->exec($sql);
$con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME); $con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
$con->beginTransaction(); $con->beginTransaction();
@ -215,7 +217,7 @@ class Application_Model_Show {
public function cancelShow($day_timestamp) public function cancelShow($day_timestamp)
{ {
global $CC_DBC; $con = Propel::getConnection();
$timeinfo = explode(" ", $day_timestamp); $timeinfo = explode(" ", $day_timestamp);
@ -227,7 +229,7 @@ class Application_Model_Show {
SET modified_instance = TRUE SET modified_instance = TRUE
WHERE starts >= '{$day_timestamp}' AND show_id = {$this->_showId}"; WHERE starts >= '{$day_timestamp}' AND show_id = {$this->_showId}";
$CC_DBC->query($sql); $con->exec($sql);
// check if we can safely delete the show // check if we can safely delete the show
$showInstancesRow = CcShowInstancesQuery::create() $showInstancesRow = CcShowInstancesQuery::create()
@ -237,7 +239,7 @@ class Application_Model_Show {
if(is_null($showInstancesRow)){ if(is_null($showInstancesRow)){
$sql = "DELETE FROM cc_show WHERE id = {$this->_showId}"; $sql = "DELETE FROM cc_show WHERE id = {$this->_showId}";
$CC_DBC->query($sql); $con->exec($sql);
} }
Application_Model_RabbitMq::PushSchedule(); Application_Model_RabbitMq::PushSchedule();
@ -258,7 +260,7 @@ class Application_Model_Show {
*/ */
public function removeUncheckedDaysInstances($p_uncheckedDays) public function removeUncheckedDaysInstances($p_uncheckedDays)
{ {
global $CC_DBC; $con = Propel::getConnection();
//need to convert local doftw to UTC doftw (change made for 2.0 since shows are stored in UTC) //need to convert local doftw to UTC doftw (change made for 2.0 since shows are stored in UTC)
$daysRemovedUTC = array(); $daysRemovedUTC = array();
@ -303,7 +305,7 @@ class Application_Model_Show {
//Logging::log($sql); //Logging::log($sql);
$CC_DBC->query($sql); $con->exec($sql);
} }
/** /**
@ -351,7 +353,7 @@ class Application_Model_Show {
*/ */
public function getRebroadcastsAbsolute() public function getRebroadcastsAbsolute()
{ {
global $CC_DBC; $con = Propel::getConnection();
$showId = $this->getId(); $showId = $this->getId();
@ -361,7 +363,7 @@ class Application_Model_Show {
//Logging::log($sql); //Logging::log($sql);
$rebroadcasts = $CC_DBC->GetAll($sql); $rebroadcasts = $con->query($sql)->fetchAll();
$rebroadcastsLocal = array(); $rebroadcastsLocal = array();
//get each rebroadcast show in cc_show_instances, convert to current timezone to get start date/time. //get each rebroadcast show in cc_show_instances, convert to current timezone to get start date/time.
@ -389,14 +391,14 @@ class Application_Model_Show {
*/ */
public function getRebroadcastsRelative() public function getRebroadcastsRelative()
{ {
global $CC_DBC; $con = Propel::getConnection();
$showId = $this->getId(); $showId = $this->getId();
$sql = "SELECT day_offset, start_time FROM cc_show_rebroadcast " $sql = "SELECT day_offset, start_time FROM cc_show_rebroadcast "
."WHERE show_id = $showId " ."WHERE show_id = $showId "
."ORDER BY day_offset"; ."ORDER BY day_offset";
return $CC_DBC->GetAll($sql); return $con->query($sql)->fetchAll();
} }
/** /**
@ -447,21 +449,17 @@ class Application_Model_Show {
* Return the end date for the repeating show or the empty * Return the end date for the repeating show or the empty
* string if there is no end. * string if there is no end.
*/ */
public function getRepeatingEndDate(){ public function getRepeatingEndDate()
global $CC_DBC; {
$con = Propel::getConnection();
$showId = $this->getId(); $showId = $this->getId();
$sql = "SELECT last_show FROM cc_show_days" $sql = "SELECT last_show FROM cc_show_days"
." WHERE show_id = $showId" ." WHERE show_id = $showId"
." ORDER BY last_show DESC"; ." ORDER BY last_show DESC";
$endDate = $CC_DBC->GetOne($sql); $query = $con->query($sql)->fetchColumn(0);
return $query ? $query : "";
if (is_null($endDate)){
return "";
} else {
return $endDate;
}
} }
/** /**
@ -475,7 +473,7 @@ class Application_Model_Show {
* be gone for good. * be gone for good.
*/ */
public function deleteAllInstances(){ public function deleteAllInstances(){
global $CC_DBC; $con = Propel::getConnection();
$timestamp = gmdate("Y-m-d H:i:s"); $timestamp = gmdate("Y-m-d H:i:s");
@ -484,7 +482,7 @@ class Application_Model_Show {
." WHERE starts > TIMESTAMP '$timestamp'" ." WHERE starts > TIMESTAMP '$timestamp'"
." AND show_id = $showId"; ." AND show_id = $showId";
$CC_DBC->query($sql); $con->exec($sql);
} }
/** /**
@ -492,7 +490,7 @@ class Application_Model_Show {
* show object from the show_instances table. * show object from the show_instances table.
*/ */
public function deleteAllRebroadcasts(){ public function deleteAllRebroadcasts(){
global $CC_DBC; $con = Propel::getConnection();
$timestamp = gmdate("Y-m-d H:i:s"); $timestamp = gmdate("Y-m-d H:i:s");
@ -502,7 +500,7 @@ class Application_Model_Show {
." AND show_id = $showId" ." AND show_id = $showId"
." AND rebroadcast = 1"; ." AND rebroadcast = 1";
$CC_DBC->query($sql); $con->exec($sql);
} }
/** /**
@ -515,7 +513,7 @@ class Application_Model_Show {
* The date which to delete after, if null deletes from the current timestamp. * The date which to delete after, if null deletes from the current timestamp.
*/ */
public function removeAllInstancesFromDate($p_date=null){ public function removeAllInstancesFromDate($p_date=null){
global $CC_DBC; $con = Propel::getConnection();
$timestamp = gmdate("Y-m-d H:i:s"); $timestamp = gmdate("Y-m-d H:i:s");
@ -530,7 +528,7 @@ class Application_Model_Show {
." AND starts > TIMESTAMP '$timestamp'" ." AND starts > TIMESTAMP '$timestamp'"
." AND show_id = $showId"; ." AND show_id = $showId";
$CC_DBC->query($sql); $con->exec($sql);
} }
@ -547,7 +545,7 @@ class Application_Model_Show {
* The date which to delete before * The date which to delete before
*/ */
public function removeAllInstancesBeforeDate($p_date){ public function removeAllInstancesBeforeDate($p_date){
global $CC_DBC; $con = Propel::getConnection();
$timestamp = gmdate("Y-m-d H:i:s"); $timestamp = gmdate("Y-m-d H:i:s");
@ -557,7 +555,7 @@ class Application_Model_Show {
." AND starts > TIMESTAMP '$timestamp'" ." AND starts > TIMESTAMP '$timestamp'"
." AND show_id = $showId"; ." AND show_id = $showId";
$CC_DBC->query($sql); $con->exec($sql);
} }
/** /**
@ -567,7 +565,7 @@ class Application_Model_Show {
* The start date in the format YYYY-MM-DD * The start date in the format YYYY-MM-DD
*/ */
public function getStartDate(){ public function getStartDate(){
global $CC_DBC; $con = Propel::getConnection();
$showId = $this->getId(); $showId = $this->getId();
$sql = "SELECT first_show, start_time, timezone FROM cc_show_days" $sql = "SELECT first_show, start_time, timezone FROM cc_show_days"
@ -575,11 +573,12 @@ class Application_Model_Show {
." ORDER BY first_show" ." ORDER BY first_show"
." LIMIT 1"; ." LIMIT 1";
$rows = $CC_DBC->GetAll($sql); $query = $con->query($sql);
if (count($rows) == 0){ if ($query->rowCount() == 0){
return ""; return "";
} else { } else {
$rows = $query->fetchAll();
$row = $rows[0]; $row = $rows[0];
$dt = new DateTime($row["first_show"]." ".$row["start_time"], new DateTimeZone($row["timezone"])); $dt = new DateTime($row["first_show"]." ".$row["start_time"], new DateTimeZone($row["timezone"]));
@ -596,7 +595,7 @@ class Application_Model_Show {
*/ */
public function getStartTime(){ public function getStartTime(){
global $CC_DBC; $con = Propel::getConnection();
$showId = $this->getId(); $showId = $this->getId();
$sql = "SELECT first_show, start_time, timezone FROM cc_show_days" $sql = "SELECT first_show, start_time, timezone FROM cc_show_days"
@ -604,11 +603,12 @@ class Application_Model_Show {
." ORDER BY first_show" ." ORDER BY first_show"
." LIMIT 1"; ." LIMIT 1";
$rows = $CC_DBC->GetAll($sql); $query = $con->query($sql);
if (count($rows) == 0){ if ($query->rowCount() == 0){
return ""; return "";
} else { } else {
$rows = $query->fetchAll();
$row = $rows[0]; $row = $rows[0];
$dt = new DateTime($row["first_show"]." ".$row["start_time"], new DateTimeZone($row["timezone"])); $dt = new DateTime($row["first_show"]." ".$row["start_time"], new DateTimeZone($row["timezone"]));
$dt->setTimezone(new DateTimeZone("UTC")); $dt->setTimezone(new DateTimeZone("UTC"));
@ -676,7 +676,7 @@ class Application_Model_Show {
* scheduled in the future. * scheduled in the future.
*/ */
public function getAllFutureInstanceIds(){ public function getAllFutureInstanceIds(){
global $CC_DBC; $con = Propel::getConnection();
$date = new Application_Common_DateHelper; $date = new Application_Common_DateHelper;
$timestamp = $date->getTimestamp(); $timestamp = $date->getTimestamp();
@ -687,10 +687,10 @@ class Application_Model_Show {
." AND starts > TIMESTAMP '$timestamp'" ." AND starts > TIMESTAMP '$timestamp'"
." AND modified_instance != TRUE"; ." AND modified_instance != TRUE";
$rows = $CC_DBC->GetAll($sql); $rows = $con->query($sql)->fetchAll();
$instance_ids = array(); $instance_ids = array();
foreach ($rows as $row){ foreach ($rows as $row) {
$instance_ids[] = $row["id"]; $instance_ids[] = $row["id"];
} }
return $instance_ids; return $instance_ids;
@ -705,8 +705,7 @@ class Application_Model_Show {
*/ */
private function updateDurationTime($p_data){ private function updateDurationTime($p_data){
//need to update cc_show_instances, cc_show_days //need to update cc_show_instances, cc_show_days
$con = Propel::getConnection();
global $CC_DBC;
$date = new Application_Common_DateHelper; $date = new Application_Common_DateHelper;
$timestamp = $date->getUtcTimestamp(); $timestamp = $date->getUtcTimestamp();
@ -714,20 +713,20 @@ class Application_Model_Show {
$sql = "UPDATE cc_show_days " $sql = "UPDATE cc_show_days "
."SET duration = '$p_data[add_show_duration]' " ."SET duration = '$p_data[add_show_duration]' "
."WHERE show_id = $p_data[add_show_id]"; ."WHERE show_id = $p_data[add_show_id]";
$CC_DBC->query($sql); $con->exec($sql);
$sql = "UPDATE cc_show_instances " $sql = "UPDATE cc_show_instances "
."SET ends = starts + INTERVAL '$p_data[add_show_duration]' " ."SET ends = starts + INTERVAL '$p_data[add_show_duration]' "
."WHERE show_id = $p_data[add_show_id] " ."WHERE show_id = $p_data[add_show_id] "
."AND ends > TIMESTAMP '$timestamp'"; ."AND ends > TIMESTAMP '$timestamp'";
$CC_DBC->query($sql); $con->exec($sql);
} }
private function updateStartDateTime($p_data, $p_endDate){ private function updateStartDateTime($p_data, $p_endDate){
//need to update cc_schedule, cc_show_instances, cc_show_days //need to update cc_schedule, cc_show_instances, cc_show_days
$con = Propel::getConnection();
global $CC_DBC;
$date = new Application_Common_DateHelper; $date = new Application_Common_DateHelper;
$timestamp = $date->getTimestamp(); $timestamp = $date->getTimestamp();
@ -742,7 +741,7 @@ class Application_Model_Show {
$sql .= "last_show = DATE '$p_endDate' "; $sql .= "last_show = DATE '$p_endDate' ";
} }
$sql .= "WHERE show_id = $p_data[add_show_id]"; $sql .= "WHERE show_id = $p_data[add_show_id]";
$CC_DBC->query($sql); $con->exec($sql);
$dtOld = new DateTime($this->getStartDate()." ".$this->getStartTime(), new DateTimeZone("UTC")); $dtOld = new DateTime($this->getStartDate()." ".$this->getStartTime(), new DateTimeZone("UTC"));
$dtNew = new DateTime($p_data['add_show_start_date']." ".$p_data['add_show_start_time'], new DateTimeZone(date_default_timezone_get())); $dtNew = new DateTime($p_data['add_show_start_date']." ".$p_data['add_show_start_time'], new DateTimeZone(date_default_timezone_get()));
@ -753,7 +752,7 @@ class Application_Model_Show {
."ends = ends + INTERVAL '$diff sec' " ."ends = ends + INTERVAL '$diff sec' "
."WHERE show_id = $p_data[add_show_id] " ."WHERE show_id = $p_data[add_show_id] "
."AND starts > TIMESTAMP '$timestamp'"; ."AND starts > TIMESTAMP '$timestamp'";
$CC_DBC->query($sql); $con->exec($sql);
$showInstanceIds = $this->getAllFutureInstanceIds(); $showInstanceIds = $this->getAllFutureInstanceIds();
if (count($showInstanceIds) > 0 && $diff != 0){ if (count($showInstanceIds) > 0 && $diff != 0){
@ -762,7 +761,7 @@ class Application_Model_Show {
."SET starts = starts + INTERVAL '$diff sec', " ."SET starts = starts + INTERVAL '$diff sec', "
."ends = ends + INTERVAL '$diff sec' " ."ends = ends + INTERVAL '$diff sec' "
."WHERE instance_id IN ($showIdsImploded)"; ."WHERE instance_id IN ($showIdsImploded)";
$CC_DBC->query($sql); $con->exec($sql);
} }
} }
@ -848,7 +847,8 @@ class Application_Model_Show {
* @return CcShowInstancesQuery: An propel object representing a * @return CcShowInstancesQuery: An propel object representing a
* row in the cc_show_instances table. */ * row in the cc_show_instances table. */
public function getInstanceOnDate($p_dateTime){ public function getInstanceOnDate($p_dateTime){
global $CC_DBC; $con = Propel::getConnection();
$timestamp = $p_dateTime->format("Y-m-d H:i:s"); $timestamp = $p_dateTime->format("Y-m-d H:i:s");
$showId = $this->getId(); $showId = $this->getId();
@ -856,7 +856,8 @@ class Application_Model_Show {
." WHERE date(starts) = date(TIMESTAMP '$timestamp') " ." WHERE date(starts) = date(TIMESTAMP '$timestamp') "
." AND show_id = $showId"; ." AND show_id = $showId";
$row = $CC_DBC->GetOne($sql); $query = $con->query();
$row = $query ? $query->fetchColumn(0) : null;
return CcShowInstancesQuery::create() return CcShowInstancesQuery::create()
->findPk($row); ->findPk($row);
} }
@ -1164,8 +1165,15 @@ class Application_Model_Show {
*/ */
public static function populateShowUntil($p_showId) public static function populateShowUntil($p_showId)
{ {
<<<<<<< HEAD
global $CC_DBC; global $CC_DBC;
$date = Application_Model_Preference::GetShowsPopulatedUntil(); $date = Application_Model_Preference::GetShowsPopulatedUntil();
=======
$con = Propel::getConnection();
if (is_null($p_dateTime)) {
$date = Application_Model_Preference::GetShowsPopulatedUntil();
>>>>>>> CC-1927: Remove PEAR DB
if (is_null($date)) { if (is_null($date)) {
$p_populateUntilDateTime = new DateTime("now", new DateTimeZone('UTC')); $p_populateUntilDateTime = new DateTime("now", new DateTimeZone('UTC'));
@ -1175,7 +1183,7 @@ class Application_Model_Show {
} }
$sql = "SELECT * FROM cc_show_days WHERE show_id = $p_showId"; $sql = "SELECT * FROM cc_show_days WHERE show_id = $p_showId";
$res = $CC_DBC->GetAll($sql); $res = $con->query($sql)->fetchAll();
foreach ($res as $showRow) { foreach ($res as $showRow) {
Application_Model_Show::populateShow($showRow, $p_populateUntilDateTime); Application_Model_Show::populateShow($showRow, $p_populateUntilDateTime);
@ -1220,8 +1228,13 @@ class Application_Model_Show {
*/ */
private static function populateNonRepeatingShow($p_showRow, $p_populateUntilDateTime) private static function populateNonRepeatingShow($p_showRow, $p_populateUntilDateTime)
{ {
<<<<<<< HEAD
global $CC_DBC; global $CC_DBC;
=======
$con = Propel::getConnection();
>>>>>>> CC-1927: Remove PEAR DB
$show_id = $p_showRow["show_id"]; $show_id = $p_showRow["show_id"];
$first_show = $p_showRow["first_show"]; //non-UTC $first_show = $p_showRow["first_show"]; //non-UTC
$start_time = $p_showRow["start_time"]; //non-UTC $start_time = $p_showRow["start_time"]; //non-UTC
@ -1261,11 +1274,17 @@ class Application_Model_Show {
} }
$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id={$show_id}"; $sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id={$show_id}";
$rebroadcasts = $CC_DBC->GetAll($sql); $rebroadcasts = $con->query($sql)->fetchAll();
//Logging::log('$start time of non repeating record '.$start); //Logging::log('$start time of non repeating record '.$start);
<<<<<<< HEAD
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone); self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
=======
if ($newInstance) {
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
}
>>>>>>> CC-1927: Remove PEAR DB
} }
} }
@ -1283,7 +1302,7 @@ class Application_Model_Show {
*/ */
private static function populateRepeatingShow($p_showRow, $p_populateUntilDateTime, $p_interval) private static function populateRepeatingShow($p_showRow, $p_populateUntilDateTime, $p_interval)
{ {
global $CC_DBC; $con = Propel::getConnection();
$show_id = $p_showRow["show_id"]; $show_id = $p_showRow["show_id"];
$next_pop_date = $p_showRow["next_pop_date"]; $next_pop_date = $p_showRow["next_pop_date"];
@ -1308,11 +1327,15 @@ class Application_Model_Show {
$utcLastShowDateTime = $last_show ? Application_Common_DateHelper::ConvertToUtcDateTime($last_show, $timezone) : null; $utcLastShowDateTime = $last_show ? Application_Common_DateHelper::ConvertToUtcDateTime($last_show, $timezone) : null;
$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id={$show_id}"; $sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id={$show_id}";
$rebroadcasts = $CC_DBC->GetAll($sql); $rebroadcasts = $con->query($sql)->fetchAll();
$show = new Application_Model_Show($show_id); $show = new Application_Model_Show($show_id);
<<<<<<< HEAD
while($utcStartDateTime->getTimestamp() <= $p_populateUntilDateTime->getTimestamp() while($utcStartDateTime->getTimestamp() <= $p_populateUntilDateTime->getTimestamp()
=======
while ($utcStartDateTime->getTimestamp() <= $p_dateTime->getTimestamp()
>>>>>>> CC-1927: Remove PEAR DB
&& (is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp())){ && (is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp())){
list($utcStartDateTime, $utcEndDateTime) = Application_Model_Show::createUTCStartEndDateTime($start, $duration, $timezone); list($utcStartDateTime, $utcEndDateTime) = Application_Model_Show::createUTCStartEndDateTime($start, $duration, $timezone);
@ -1481,7 +1504,7 @@ class Application_Model_Show {
*/ */
public static function getShows($start_timestamp, $end_timestamp, $excludeInstance=NULL, $onlyRecord=FALSE) public static function getShows($start_timestamp, $end_timestamp, $excludeInstance=NULL, $onlyRecord=FALSE)
{ {
global $CC_DBC; $con = Propel::getConnection();
//UTC DateTime object //UTC DateTime object
$showsPopUntil = Application_Model_Preference::GetShowsPopulatedUntil(); $showsPopUntil = Application_Model_Preference::GetShowsPopulatedUntil();
@ -1527,8 +1550,8 @@ class Application_Model_Show {
//Logging::log("getShows"); //Logging::log("getShows");
//Logging::log($sql); //Logging::log($sql);
$result = $con->query($sql)->fetchAll();
return $CC_DBC->GetAll($sql); return $result;
} }
private static function setNextPop($next_date, $show_id, $day) private static function setNextPop($next_date, $show_id, $day)
@ -1554,7 +1577,7 @@ class Application_Model_Show {
*/ */
public static function populateAllShowsInRange($p_startTimestamp, $p_endTimestamp) public static function populateAllShowsInRange($p_startTimestamp, $p_endTimestamp)
{ {
global $CC_DBC; $con = Propel::getConnection();
$endTimeString = $p_endTimestamp->format("Y-m-d H:i:s"); $endTimeString = $p_endTimestamp->format("Y-m-d H:i:s");
if (!is_null($p_startTimestamp)) { if (!is_null($p_startTimestamp)) {
@ -1570,8 +1593,7 @@ class Application_Model_Show {
OR first_show < '{$endTimeString}' AND last_show > '{$startTimeString}'"; OR first_show < '{$endTimeString}' AND last_show > '{$startTimeString}'";
//Logging::log($sql); //Logging::log($sql);
$res = $con->query($sql)->fetchAll();
$res = $CC_DBC->GetAll($sql);
foreach ($res as $row) { foreach ($res as $row) {
Application_Model_Show::populateShow($row, $p_endTimestamp); Application_Model_Show::populateShow($row, $p_endTimestamp);
@ -1588,14 +1610,10 @@ class Application_Model_Show {
*/ */
public static function getFullCalendarEvents($p_start, $p_end, $p_editable=false) public static function getFullCalendarEvents($p_start, $p_end, $p_editable=false)
{ {
$events = array(); $events = array();
$interval = $p_start->diff($p_end); $interval = $p_start->diff($p_end);
$days = $interval->format('%a'); $days = $interval->format('%a');
$shows = Application_Model_Show::getShows($p_start, $p_end); $shows = Application_Model_Show::getShows($p_start, $p_end);
$today_timestamp = gmdate("Y-m-d H:i:s"); $today_timestamp = gmdate("Y-m-d H:i:s");
foreach ($shows as $show) { foreach ($shows as $show) {
@ -1603,7 +1621,7 @@ class Application_Model_Show {
//only bother calculating percent for week or day view. //only bother calculating percent for week or day view.
if(intval($days) <= 7) { if (intval($days) <= 7) {
$options["percent"] = Application_Model_Show::getPercentScheduled($show["starts"], $show["ends"], $show["time_filled"]); $options["percent"] = Application_Model_Show::getPercentScheduled($show["starts"], $show["ends"], $show["time_filled"]);
} }
@ -1722,10 +1740,16 @@ class Application_Model_Show {
*/ */
public static function GetCurrentShow($timeNow=null) public static function GetCurrentShow($timeNow=null)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
if($timeNow == null){ if($timeNow == null){
<<<<<<< HEAD
$date = new Application_Common_DateHelper; $date = new Application_Common_DateHelper;
$timeNow = $date->getUtcTimestamp(); $timeNow = $date->getUtcTimestamp();
=======
$date = new Application_Model_DateHelper;
$timeNow = $date->getUtcTimestamp();
>>>>>>> CC-1927: Remove PEAR DB
} }
//TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin //TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin
$sql = "SELECT si.starts as start_timestamp, si.ends as end_timestamp, s.name, s.id, si.id as instance_id, si.record, s.url, starts, ends" $sql = "SELECT si.starts as start_timestamp, si.ends as end_timestamp, s.name, s.id, si.id as instance_id, si.record, s.url, starts, ends"
@ -1736,8 +1760,7 @@ class Application_Model_Show {
." AND modified_instance != TRUE"; ." AND modified_instance != TRUE";
// Convert back to local timezone // Convert back to local timezone
$rows = $CC_DBC->GetAll($sql); $rows = $con->query($sql)->fetchAll();
return $rows; return $rows;
} }
@ -1746,7 +1769,8 @@ class Application_Model_Show {
*/ */
public static function getPrevCurrentNext($p_timeNow) public static function getPrevCurrentNext($p_timeNow)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
//TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin //TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin
$sql = "SELECT si.starts as start_timestamp, si.ends as end_timestamp, s.name, s.id, si.id as instance_id, si.record, s.url, starts, ends" $sql = "SELECT si.starts as start_timestamp, si.ends as end_timestamp, s.name, s.id, si.id as instance_id, si.record, s.url, starts, ends"
." FROM $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] s" ." FROM $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] s"
@ -1757,7 +1781,7 @@ class Application_Model_Show {
." ORDER BY si.starts"; ." ORDER BY si.starts";
// Convert back to local timezone // Convert back to local timezone
$rows = $CC_DBC->GetAll($sql); $rows = $con->query($sql)->fetchAll();
$numberOfRows = count($rows); $numberOfRows = count($rows);
$results['previousShow'] = array(); $results['previousShow'] = array();
@ -1826,6 +1850,7 @@ class Application_Model_Show {
} }
return $results; return $results;
} }
/** /**
* Given a start time $timeStart and end time $timeEnd, returns the next $limit * Given a start time $timeStart and end time $timeEnd, returns the next $limit
* number of shows within the time interval; * number of shows within the time interval;
@ -1840,11 +1865,12 @@ class Application_Model_Show {
*/ */
public static function GetNextShows($timeStart, $limit = "0", $timeEnd = "") public static function GetNextShows($timeStart, $limit = "0", $timeEnd = "")
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
// defaults to retrieving shows from next 2 days if no end time has // defaults to retrieving shows from next 2 days if no end time has
// been specified // been specified
if($timeEnd == "") { if ($timeEnd == "") {
$timeEnd = "'$timeStart' + INTERVAL '2 days'"; $timeEnd = "'$timeStart' + INTERVAL '2 days'";
} else { } else {
$timeEnd = "'$timeEnd'"; $timeEnd = "'$timeEnd'";
@ -1864,8 +1890,7 @@ class Application_Model_Show {
$sql = $sql . " LIMIT $limit"; $sql = $sql . " LIMIT $limit";
} }
$rows = $CC_DBC->GetAll($sql); $rows = $con->query($sql)->fetchAll();
return $rows; return $rows;
} }
@ -1890,14 +1915,16 @@ class Application_Model_Show {
} }
public static function GetMaxLengths() { public static function GetMaxLengths() {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT column_name, character_maximum_length FROM information_schema.columns" $sql = "SELECT column_name, character_maximum_length FROM information_schema.columns"
." WHERE table_name = 'cc_show' AND character_maximum_length > 0"; ." WHERE table_name = 'cc_show' AND character_maximum_length > 0";
$result = $CC_DBC->GetAll($sql); $result = $con->query($sql)->fetchAll();
// store result into assoc array // store result into assoc array
$assocArray = array(); $assocArray = array();
foreach($result as $row) { foreach ($result as $row) {
$assocArray[$row['column_name']] = $row['character_maximum_length']; $assocArray[$row['column_name']] = $row['character_maximum_length'];
} }

View file

@ -146,8 +146,9 @@ class Application_Model_ShowInstance {
$this->_showInstance->getDbModifiedInstance(); $this->_showInstance->getDbModifiedInstance();
} }
public function correctScheduleStartTimes(){ public function correctScheduleStartTimes()
global $CC_DBC; {
$con = Propel::getConnection();
$instance_id = $this->getShowInstanceId(); $instance_id = $this->getShowInstanceId();
$sql = "SELECT starts from cc_schedule" $sql = "SELECT starts from cc_schedule"
@ -155,9 +156,9 @@ class Application_Model_ShowInstance {
." ORDER BY starts" ." ORDER BY starts"
." LIMIT 1"; ." LIMIT 1";
$scheduleStarts = $CC_DBC->GetOne($sql); $scheduleStarts = $con->query($sql)->fetchColumn(0);
if (!is_null($scheduleStarts)){ if ($scheduleStarts) {
$scheduleStartsEpoch = strtotime($scheduleStarts); $scheduleStartsEpoch = strtotime($scheduleStarts);
$showStartsEpoch = strtotime($this->getShowInstanceStart()); $showStartsEpoch = strtotime($this->getShowInstanceStart());
@ -169,7 +170,7 @@ class Application_Model_ShowInstance {
." ends = ends + INTERVAL '$diff' second" ." ends = ends + INTERVAL '$diff' second"
." WHERE instance_id = $instance_id"; ." WHERE instance_id = $instance_id";
$CC_DBC->query($sql); $con->exec($sql);
} }
} }
Application_Model_RabbitMq::PushSchedule(); Application_Model_RabbitMq::PushSchedule();
@ -300,7 +301,7 @@ class Application_Model_ShowInstance {
*/ */
public function resizeShow($deltaDay, $deltaMin) public function resizeShow($deltaDay, $deltaMin)
{ {
global $CC_DBC; $con = Propel::getConnection();
$hours = $deltaMin/60; $hours = $deltaMin/60;
if($hours > 0) if($hours > 0)
@ -319,10 +320,10 @@ class Application_Model_ShowInstance {
} }
$sql = "SELECT timestamp '{$ends}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'"; $sql = "SELECT timestamp '{$ends}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'";
$new_ends = $CC_DBC->GetOne($sql); $new_ends = $con->query($sql)->fetchColumn(0);
//only need to check overlap if show increased in size. //only need to check overlap if show increased in size.
if(strtotime($new_ends) > strtotime($ends)) { if (strtotime($new_ends) > strtotime($ends)) {
$utcStartDateTime = new DateTime($ends, new DateTimeZone("UTC")); $utcStartDateTime = new DateTime($ends, new DateTimeZone("UTC"));
$utcEndDateTime = new DateTime($new_ends, new DateTimeZone("UTC")); $utcEndDateTime = new DateTime($new_ends, new DateTimeZone("UTC"));
@ -339,7 +340,7 @@ class Application_Model_ShowInstance {
if($this->isRecorded()) { if($this->isRecorded()) {
$sql = "UPDATE cc_show_instances SET ends = (ends + interval '{$deltaDay} days' + interval '{$hours}:{$mins}') $sql = "UPDATE cc_show_instances SET ends = (ends + interval '{$deltaDay} days' + interval '{$hours}:{$mins}')
WHERE rebroadcast = 1 AND instance_id = {$this->_instanceId}"; WHERE rebroadcast = 1 AND instance_id = {$this->_instanceId}";
$CC_DBC->query($sql); $con->exec($sql);
} }
$this->setShowEnd($new_ends); $this->setShowEnd($new_ends);
@ -481,8 +482,6 @@ class Application_Model_ShowInstance {
public function delete() public function delete()
{ {
global $CC_DBC;
// see if it was recording show // see if it was recording show
$recording = $this->isRecorded(); $recording = $this->isRecorded();
// get show id // get show id
@ -631,7 +630,7 @@ class Application_Model_ShowInstance {
public function getShowListContent() public function getShowListContent()
{ {
global $CC_DBC; $con = Propel::getConnection();
$sql = "SELECT * $sql = "SELECT *
FROM (cc_schedule AS s LEFT JOIN cc_files AS f ON f.id = s.file_id) FROM (cc_schedule AS s LEFT JOIN cc_files AS f ON f.id = s.file_id)
@ -640,7 +639,7 @@ class Application_Model_ShowInstance {
//Logging::log($sql); //Logging::log($sql);
$results = $CC_DBC->GetAll($sql); $results = $con->query($sql)->fetchAll();
foreach ($results as &$row) { foreach ($results as &$row) {
@ -656,15 +655,17 @@ class Application_Model_ShowInstance {
return $results; return $results;
} }
public function getLastAudioItemEnd(){ public function getLastAudioItemEnd()
global $CC_DBC; {
$con = Propel::getConnection();
$sql = "SELECT ends FROM cc_schedule " $sql = "SELECT ends FROM cc_schedule "
."WHERE instance_id = {$this->_instanceId} " ."WHERE instance_id = {$this->_instanceId} "
."ORDER BY ends DESC " ."ORDER BY ends DESC "
."LIMIT 1"; ."LIMIT 1";
return $CC_DBC->GetOne($sql); $query = $con->query($sql)->fetchColumn(0);
return $query ? $query : NULL;
} }
public function getShowEndGapTime(){ public function getShowEndGapTime(){
@ -682,7 +683,8 @@ class Application_Model_ShowInstance {
} }
public static function GetLastShowInstance($p_timeNow){ public static function GetLastShowInstance($p_timeNow){
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT si.id" $sql = "SELECT si.id"
." FROM $CC_CONFIG[showInstances] si" ." FROM $CC_CONFIG[showInstances] si"
@ -691,16 +693,18 @@ class Application_Model_ShowInstance {
." ORDER BY si.ends DESC" ." ORDER BY si.ends DESC"
." LIMIT 1"; ." LIMIT 1";
$id = $CC_DBC->GetOne($sql); $id = $con->query($sql)->fetchColumn(0);
if (is_null($id)){ if ($id) {
return null;
} else {
return new Application_Model_ShowInstance($id); return new Application_Model_ShowInstance($id);
} else {
return null;
} }
} }
public static function GetCurrentShowInstance($p_timeNow){ public static function GetCurrentShowInstance($p_timeNow)
global $CC_CONFIG, $CC_DBC; {
global $CC_CONFIG;
$con = Propel::getConnection();
/* Orderby si.starts descending, because in some cases /* Orderby si.starts descending, because in some cases
* we can have multiple shows overlapping each other. In * we can have multiple shows overlapping each other. In
@ -716,16 +720,18 @@ class Application_Model_ShowInstance {
." ORDER BY si.starts DESC" ." ORDER BY si.starts DESC"
." LIMIT 1"; ." LIMIT 1";
$id = $CC_DBC->GetOne($sql); $id = $con->query($sql)->fetchColumn(0);
if (is_null($id)){ if ($id) {
return null;
} else {
return new Application_Model_ShowInstance($id); return new Application_Model_ShowInstance($id);
} else {
return null;
} }
} }
public static function GetNextShowInstance($p_timeNow){ public static function GetNextShowInstance($p_timeNow)
global $CC_CONFIG, $CC_DBC; {
global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT si.id" $sql = "SELECT si.id"
." FROM $CC_CONFIG[showInstances] si" ." FROM $CC_CONFIG[showInstances] si"
@ -734,24 +740,28 @@ class Application_Model_ShowInstance {
." ORDER BY si.starts" ." ORDER BY si.starts"
." LIMIT 1"; ." LIMIT 1";
$id = $CC_DBC->GetOne($sql); $id = $con->query($sql)->fetchColumn(0);
if (is_null($id)){ if ($id) {
return null;
} else {
return new Application_Model_ShowInstance($id); return new Application_Model_ShowInstance($id);
} else {
return null;
} }
} }
// returns number of show instances that ends later than $day // returns number of show instances that ends later than $day
public static function GetShowInstanceCount($day){ public static function GetShowInstanceCount($day)
global $CC_CONFIG, $CC_DBC; {
global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT count(*) as cnt FROM $CC_CONFIG[showInstances] WHERE ends < '$day'"; $sql = "SELECT count(*) as cnt FROM $CC_CONFIG[showInstances] WHERE ends < '$day'";
return $CC_DBC->GetOne($sql); return $con->query($sql)->fetchColumn(0);
} }
// this returns end timestamp of all shows that are in the range and has live DJ set up // this returns end timestamp of all shows that are in the range and has live DJ set up
public static function GetEndTimeOfNextShowWithLiveDJ($p_startTime, $p_endTime){ public static function GetEndTimeOfNextShowWithLiveDJ($p_startTime, $p_endTime)
global $CC_CONFIG, $CC_DBC; {
global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT ends $sql = "SELECT ends
FROM cc_show_instances as si FROM cc_show_instances as si
@ -759,7 +769,7 @@ class Application_Model_ShowInstance {
WHERE si.ends > '$p_startTime' and si.ends < '$p_endTime' and (sh.live_stream_using_airtime_auth or live_stream_using_custom_auth) WHERE si.ends > '$p_startTime' and si.ends < '$p_endTime' and (sh.live_stream_using_airtime_auth or live_stream_using_custom_auth)
ORDER BY si.ends"; ORDER BY si.ends";
return $CC_DBC->GetAll($sql); return $con->query($sql)->fetchAll();
} }
function isRepeating(){ function isRepeating(){

View file

@ -242,16 +242,14 @@ class Application_Model_StoredFile {
*/ */
public function setState($p_state, $p_editedby=NULL) public function setState($p_state, $p_editedby=NULL)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
$escapedState = pg_escape_string($p_state); $escapedState = pg_escape_string($p_state);
$eb = (!is_null($p_editedby) ? ", editedBy=$p_editedby" : ''); $eb = (!is_null($p_editedby) ? ", editedBy=$p_editedby" : '');
$sql = "UPDATE ".$CC_CONFIG['filesTable'] $sql = "UPDATE ".$CC_CONFIG['filesTable']
." SET state='$escapedState'$eb, mtime=now()" ." SET state='$escapedState'$eb, mtime=now()"
." WHERE gunid='{$this->gunid}'"; ." WHERE gunid='{$this->gunid}'";
$res = $CC_DBC->query($sql); $res = $con->exec($sql);
if (PEAR::isError($res)) {
return $res;
}
$this->state = $p_state; $this->state = $p_state;
$this->editedby = $p_editedby; $this->editedby = $p_editedby;
return TRUE; return TRUE;
@ -262,11 +260,12 @@ class Application_Model_StoredFile {
* @return array * @return array
*/ */
public function getPlaylists() { public function getPlaylists() {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT playlist_id " $sql = "SELECT playlist_id "
." FROM ".$CC_CONFIG['playistTable'] ." FROM ".$CC_CONFIG['playistTable']
." WHERE file_id='{$this->id}'"; ." WHERE file_id='{$this->id}'";
$ids = $CC_DBC->getAll($sql); $ids = $con->query($sql)->fetchAll();
$playlists = array(); $playlists = array();
if (is_array($ids) && count($ids) > 0) { if (is_array($ids) && count($ids) > 0) {
foreach ($ids as $id) { foreach ($ids as $id) {
@ -820,6 +819,7 @@ Logging::log("getting media! - 2");
$md5 = md5_file($audio_file); $md5 = md5_file($audio_file);
$duplicate = Application_Model_StoredFile::RecallByMd5($md5, true); $duplicate = Application_Model_StoredFile::RecallByMd5($md5, true);
$result = null; $result = null;
if ($duplicate) { if ($duplicate) {
if (PEAR::isError($duplicate)) { if (PEAR::isError($duplicate)) {
@ -865,9 +865,11 @@ Logging::log("getting media! - 2");
public static function getFileCount() public static function getFileCount()
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT count(*) as cnt FROM ".$CC_CONFIG["filesTable"]." WHERE file_exists"; $sql = "SELECT count(*) as cnt FROM ".$CC_CONFIG["filesTable"]." WHERE file_exists";
return $CC_DBC->GetOne($sql); return $con->query($sql)->fetchColumn(0);
} }
/** /**
@ -876,26 +878,27 @@ Logging::log("getting media! - 2");
* @param $dir_id - if this is not provided, it returns all files with full path constructed. * @param $dir_id - if this is not provided, it returns all files with full path constructed.
* @param $propelObj - if this is true, it returns array of proepl obj * @param $propelObj - if this is true, it returns array of proepl obj
*/ */
public static function listAllFiles($dir_id=null, $propelObj=false){ public static function listAllFiles($dir_id=null, $propelObj=false)
global $CC_DBC; {
$con = Propel::getConnection();
if($propelObj){ if ($propelObj) {
$sql = "SELECT m.directory || f.filepath as fp" $sql = "SELECT m.directory || f.filepath as fp"
." FROM CC_MUSIC_DIRS m" ." FROM CC_MUSIC_DIRS m"
." LEFT JOIN CC_FILES f" ." LEFT JOIN CC_FILES f"
." ON m.id = f.directory WHERE m.id = $dir_id and f.file_exists = 'TRUE'"; ." ON m.id = f.directory WHERE m.id = $dir_id and f.file_exists = 'TRUE'";
}else{ } else {
$sql = "SELECT filepath as fp" $sql = "SELECT filepath as fp"
." FROM CC_FILES" ." FROM CC_FILES"
." WHERE directory = $dir_id and file_exists = 'TRUE'"; ." WHERE directory = $dir_id and file_exists = 'TRUE'";
} }
$rows = $CC_DBC->getAll($sql); $rows = $con->query($sql)->fetchAll();
$results = array(); $results = array();
foreach ($rows as $row){ foreach ($rows as $row) {
if($propelObj){ if ($propelObj) {
$results[] = Application_Model_StoredFile::RecallByFilepath($row["fp"]); $results[] = Application_Model_StoredFile::RecallByFilepath($row["fp"]);
}else{ } else {
$results[] = $row["fp"]; $results[] = $row["fp"];
} }
} }

View file

@ -1,19 +1,21 @@
<?php <?php
class Application_Model_StreamSetting { class Application_Model_StreamSetting {
public static function SetValue($key, $value, $type){ public static function SetValue($key, $value, $type)
global $CC_CONFIG, $CC_DBC; {
global $CC_CONFIG;
$con = Propel::getConnection();
$key = pg_escape_string($key); $key = pg_escape_string($key);
$value = pg_escape_string($value); $value = pg_escape_string($value);
//Check if key already exists // Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_stream_setting" $sql = "SELECT COUNT(*) FROM cc_stream_setting"
." WHERE keyname = '$key'"; ." WHERE keyname = '$key'";
$result = $CC_DBC->GetOne($sql); $result = $con->query($sql)->fetchColumn(0);
if($result == 1) { if ($result == 1) {
$sql = "UPDATE cc_stream_setting" $sql = "UPDATE cc_stream_setting"
." SET value = '$value', type='$type'" ." SET value = '$value', type='$type'"
." WHERE keyname = '$key'"; ." WHERE keyname = '$key'";
@ -22,16 +24,18 @@ class Application_Model_StreamSetting {
." VALUES ('$key', '$value', '$type')"; ." VALUES ('$key', '$value', '$type')";
} }
return $CC_DBC->query($sql); return $con->exec($sql);
} }
public static function GetValue($key){ public static function GetValue($key)
global $CC_CONFIG, $CC_DBC; {
global $CC_CONFIG;
$con = Propel::getConnection();
//Check if key already exists //Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_stream_setting" $sql = "SELECT COUNT(*) FROM cc_stream_setting"
." WHERE keyname = '$key'"; ." WHERE keyname = '$key'";
$result = $CC_DBC->GetOne($sql); $result = $con->query($sql)->fetchColumn(0);
if ($result == 0) if ($result == 0)
return ""; return "";
@ -39,98 +43,102 @@ class Application_Model_StreamSetting {
$sql = "SELECT value FROM cc_stream_setting" $sql = "SELECT value FROM cc_stream_setting"
." WHERE keyname = '$key'"; ." WHERE keyname = '$key'";
$result = $CC_DBC->GetOne($sql); $result = $con->query($sql)->fetchColumn(0);
return $result; return $result ? $result : NULL;
} }
} }
/* Returns the id's of all streams that are enabled in an array. An /* Returns the id's of all streams that are enabled in an array. An
* example of the array returned in JSON notation is ["s1", "s2", "s3"] */ * example of the array returned in JSON notation is ["s1", "s2", "s3"] */
public static function getEnabledStreamIds(){ public static function getEnabledStreamIds()
global $CC_DBC; {
$con = Propel::getConnection();
$sql = "SELECT * " $sql = "SELECT * "
."FROM cc_stream_setting " ."FROM cc_stream_setting "
."WHERE keyname LIKE '%_enable' " ."WHERE keyname LIKE '%_enable' "
."AND value='true'"; ."AND value='true'";
$rows = $CC_DBC->getAll($sql); $rows = $con->query($sql)->fetchAll();
$ids = array(); $ids = array();
foreach ($rows as $row){ foreach ($rows as $row) {
$ids[] = substr($row["keyname"], 0, strpos($row["keyname"], "_")); $ids[] = substr($row["keyname"], 0, strpos($row["keyname"], "_"));
} }
//Logging::log(print_r($ids, true)); //Logging::log(print_r($ids, true));
return $ids; return $ids;
} }
/* Retruns only global data as array*/ /* Returns only global data as array*/
public static function getGlobalData(){ public static function getGlobalData()
global $CC_DBC; {
$con = Propel::getConnection();
$sql = "SELECT * " $sql = "SELECT * "
."FROM cc_stream_setting " ."FROM cc_stream_setting "
."WHERE keyname IN ('output_sound_device', 'icecast_vorbis_metadata')"; ."WHERE keyname IN ('output_sound_device', 'icecast_vorbis_metadata')";
$rows = $CC_DBC->getAll($sql); $rows = $con->query($sql)->fetchAll();
$data = array(); $data = array();
foreach($rows as $row){ foreach ($rows as $row) {
$data[$row["keyname"]] = $row["value"]; $data[$row["keyname"]] = $row["value"];
} }
return $data; return $data;
} }
/* Returns all information related to a specific stream. An example /* Returns all information related to a specific stream. An example
* of a stream id is 's1' or 's2'. */ * of a stream id is 's1' or 's2'. */
public static function getStreamData($p_streamId){ public static function getStreamData($p_streamId)
global $CC_DBC; {
$con = Propel::getConnection();
$sql = "SELECT * " $sql = "SELECT * "
."FROM cc_stream_setting " ."FROM cc_stream_setting "
."WHERE keyname LIKE '${p_streamId}_%'"; ."WHERE keyname LIKE '${p_streamId}_%'";
$rows = $CC_DBC->getAll($sql); $rows = $con->query($sql)->fetchAll();
$data = array(); $data = array();
foreach($rows as $row){ foreach ($rows as $row) {
$data[$row["keyname"]] = $row["value"]; $data[$row["keyname"]] = $row["value"];
} }
return $data; return $data;
} }
public static function getStreamSetting(){ public static function getStreamSetting()
global $CC_DBC; {
$con = Propel::getConnection();
$sql = "SELECT *" $sql = "SELECT *"
." FROM cc_stream_setting" ." FROM cc_stream_setting"
." WHERE keyname not like '%_error'"; ." WHERE keyname not like '%_error'";
$rows = $CC_DBC->getAll($sql); $rows = $con->query($sql)->fetchAll();
$exists = array(); $exists = array();
foreach($rows as $r){ foreach ($rows as $r) {
if($r['keyname'] == 'master_live_stream_port'){ if ($r['keyname'] == 'master_live_stream_port') {
$exists['master_live_stream_port'] = true; $exists['master_live_stream_port'] = true;
}elseif($r['keyname'] == 'master_live_stream_mp'){ } elseif($r['keyname'] == 'master_live_stream_mp') {
$exists['master_live_stream_mp'] = true; $exists['master_live_stream_mp'] = true;
}elseif($r['keyname'] == 'dj_live_stream_port'){ } elseif($r['keyname'] == 'dj_live_stream_port') {
$exists['dj_live_stream_port'] = true; $exists['dj_live_stream_port'] = true;
}elseif($r['keyname'] == 'dj_live_stream_mp'){ } elseif($r['keyname'] == 'dj_live_stream_mp') {
$exists['dj_live_stream_mp'] = true; $exists['dj_live_stream_mp'] = true;
} }
} }
if(!isset($exists["master_live_stream_port"])){ if (!isset($exists["master_live_stream_port"])) {
$rows[] = (array("keyname" =>"master_live_stream_port", "value"=>self::GetMasterLiveSteamPort(), "type"=>"integer")); $rows[] = (array("keyname" =>"master_live_stream_port", "value"=>self::GetMasterLiveSteamPort(), "type"=>"integer"));
} }
if(!isset($exists["master_live_stream_mp"])){ if (!isset($exists["master_live_stream_mp"])) {
$rows[] = (array("keyname" =>"master_live_stream_mp", "value"=>self::GetMasterLiveSteamMountPoint(), "type"=>"string")); $rows[] = (array("keyname" =>"master_live_stream_mp", "value"=>self::GetMasterLiveSteamMountPoint(), "type"=>"string"));
} }
if(!isset($exists["dj_live_stream_port"])){ if (!isset($exists["dj_live_stream_port"])) {
$rows[] = (array("keyname" =>"dj_live_stream_port", "value"=>self::GetDJLiveSteamPort(), "type"=>"integer")); $rows[] = (array("keyname" =>"dj_live_stream_port", "value"=>self::GetDJLiveSteamPort(), "type"=>"integer"));
} }
if(!isset($exists["dj_live_stream_mp"])){ if (!isset($exists["dj_live_stream_mp"])) {
$rows[] = (array("keyname" =>"dj_live_stream_mp", "value"=>self::GetDJLiveSteamMountPoint(), "type"=>"string")); $rows[] = (array("keyname" =>"dj_live_stream_mp", "value"=>self::GetDJLiveSteamMountPoint(), "type"=>"string"));
} }
return $rows; return $rows;
@ -143,17 +151,18 @@ class Application_Model_StreamSetting {
* @param $data - array that contains all the data. $data is [][] which * @param $data - array that contains all the data. $data is [][] which
* contains multiple stream information * contains multiple stream information
*/ */
public static function setStreamSetting($data){ public static function setStreamSetting($data)
global $CC_DBC; {
$con = Propel::getConnection();
foreach ($data as $key=>$d) { foreach ($data as $key=>$d) {
if ($key == "output_sound_device" || $key == "icecast_vorbis_metadata") { if ($key == "output_sound_device" || $key == "icecast_vorbis_metadata") {
$v = $d == 1?"true":"false"; $v = $d == 1?"true":"false";
$sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$key'"; $sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$key'";
$CC_DBC->query($sql); $con->exec($sql);
} else if ($key == "output_sound_device_type") { } else if ($key == "output_sound_device_type") {
$sql = "UPDATE cc_stream_setting SET value='$d' WHERE keyname='$key'"; $sql = "UPDATE cc_stream_setting SET value='$d' WHERE keyname='$key'";
$CC_DBC->query($sql); $con->exec($sql);
} else if (is_array($d)) { } else if (is_array($d)) {
$temp = explode('_', $key); $temp = explode('_', $key);
$prefix = $temp[0]; $prefix = $temp[0];
@ -164,7 +173,7 @@ class Application_Model_StreamSetting {
} }
$v = trim($v); $v = trim($v);
$sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$keyname'"; $sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$keyname'";
$CC_DBC->query($sql); $con->exec($sql);
} }
} else { } else {
Logging::log("Warning unexpected value: ".$key); Logging::log("Warning unexpected value: ".$key);
@ -177,12 +186,13 @@ class Application_Model_StreamSetting {
* *
* $data - data array. $data is []. * $data - data array. $data is [].
*/ */
public static function setIndivisualStreamSetting($data){ public static function setIndivisualStreamSetting($data)
global $CC_DBC; {
$con = Propel::getConnection();
foreach($data as $keyname => $v){ foreach ($data as $keyname => $v) {
$sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$keyname'"; $sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$keyname'";
$CC_DBC->query($sql); $con->exec($sql);
} }
} }
@ -190,45 +200,48 @@ class Application_Model_StreamSetting {
* Stores liquidsoap status if $boot_time > save time. * Stores liquidsoap status if $boot_time > save time.
* save time is the time that user clicked save on stream setting page * save time is the time that user clicked save on stream setting page
*/ */
public static function setLiquidsoapError($stream_id, $msg, $boot_time=null){ public static function setLiquidsoapError($stream_id, $msg, $boot_time=null)
global $CC_DBC; {
$con = Propel::getConnection();
$update_time = Application_Model_Preference::GetStreamUpdateTimestemp(); $update_time = Application_Model_Preference::GetStreamUpdateTimestemp();
if($boot_time == null || $boot_time > $update_time ){ if ($boot_time == null || $boot_time > $update_time) {
$keyname = "s".$stream_id."_liquidsoap_error"; $keyname = "s".$stream_id."_liquidsoap_error";
$sql = "SELECT COUNT(*) FROM cc_stream_setting" $sql = "SELECT COUNT(*) FROM cc_stream_setting"
." WHERE keyname = '$keyname'"; ." WHERE keyname = '$keyname'";
$result = $CC_DBC->GetOne($sql); $result = $con->query($sql)->fetchColumn(0);
if ($result == 1){ if ($result == 1) {
$sql = "UPDATE cc_stream_setting" $sql = "UPDATE cc_stream_setting"
." SET value = '$msg'" ." SET value = '$msg'"
." WHERE keyname = '$keyname'"; ." WHERE keyname = '$keyname'";
}else{ } else {
$sql = "INSERT INTO cc_stream_setting (keyname, value, type)" $sql = "INSERT INTO cc_stream_setting (keyname, value, type)"
." VALUES ('$keyname', '$msg', 'string')"; ." VALUES ('$keyname', '$msg', 'string')";
} }
$res = $CC_DBC->query($sql); $res = $con->exec($sql);
} }
} }
public static function getLiquidsoapError($stream_id){ public static function getLiquidsoapError($stream_id)
global $CC_DBC; {
$con = Propel::getConnection();
$keyname = "s".$stream_id."_liquidsoap_error"; $keyname = "s".$stream_id."_liquidsoap_error";
$sql = "SELECT value FROM cc_stream_setting" $sql = "SELECT value FROM cc_stream_setting"
." WHERE keyname = '$keyname'"; ." WHERE keyname = '$keyname'";
$result = $CC_DBC->GetOne($sql); $result = $con->query($sql)->fetchColumn(0);
return $result; return $result ? $result : NULL;
} }
public static function getStreamEnabled($stream_id){ public static function getStreamEnabled($stream_id)
global $CC_DBC; {
$con = Propel::getConnection();
$keyname = "s" . $stream_id . "_enable"; $keyname = "s" . $stream_id . "_enable";
$sql = "SELECT value FROM cc_stream_setting" $sql = "SELECT value FROM cc_stream_setting"
." WHERE keyname = '$keyname'"; ." WHERE keyname = '$keyname'";
$result = $CC_DBC->GetOne($sql); $result = $con->query($sql)->fetchColumn(0);
if ($result == 'false') { if ($result == 'false') {
$result = false; $result = false;
} else { } else {
@ -241,21 +254,22 @@ class Application_Model_StreamSetting {
* Only returns info that is needed for data collection * Only returns info that is needed for data collection
* returns array('s1'=>array(keyname=>value)) * returns array('s1'=>array(keyname=>value))
*/ */
public static function getStreamInfoForDataCollection(){ public static function getStreamInfoForDataCollection()
global $CC_DBC; {
$con = Propel::getConnection();
$out = array(); $out = array();
$enabled_stream = self::getEnabledStreamIds(); $enabled_stream = self::getEnabledStreamIds();
foreach($enabled_stream as $stream){ foreach ($enabled_stream as $stream) {
$keys = "'".$stream."_output', "."'".$stream."_type', "."'".$stream."_bitrate', "."'".$stream."_host'"; $keys = "'".$stream."_output', "."'".$stream."_type', "."'".$stream."_bitrate', "."'".$stream."_host'";
$sql = "SELECT keyname, value FROM cc_stream_setting" $sql = "SELECT keyname, value FROM cc_stream_setting"
." WHERE keyname IN ($keys)"; ." WHERE keyname IN ($keys)";
$rows = $CC_DBC->getAll($sql); $rows = $con->query($sql)->fetchAll();
$info = array(); $info = array();
foreach($rows as $r){ foreach ($rows as $r) {
$temp = explode("_", $r['keyname']); $temp = explode("_", $r['keyname']);
$info[$temp[1]] = $r['value']; $info[$temp[1]] = $r['value'];
$out[$stream] = $info; $out[$stream] = $info;

View file

@ -28,16 +28,15 @@ class Application_Model_Subjects {
*/ */
public static function Authenticate($login, $pass='') public static function Authenticate($login, $pass='')
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
$cpass = md5($pass); $cpass = md5($pass);
$sql = "SELECT id FROM ".$CC_CONFIG['subjTable'] $sql = "SELECT id FROM ".$CC_CONFIG['subjTable']
." WHERE login='$login' AND pass='$cpass' AND type='U'"; ." WHERE login='$login' AND pass='$cpass' AND type='U'"
$id = $CC_DBC->getOne($sql); ." LIMIT 1";
if (PEAR::isError($id)) { $query = $con->query($sql)->fetchColumn(0);
return $id; return $query;
} }
return (is_null($id) ? FALSE : $id);
} // fn authenticate
/** /**
@ -54,7 +53,8 @@ class Application_Model_Subjects {
*/ */
public static function Passwd($login, $oldpass=null, $pass='', $passenc=FALSE) public static function Passwd($login, $oldpass=null, $pass='', $passenc=FALSE)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$con = Propel::getConnection();
if (!$passenc) { if (!$passenc) {
$cpass = md5($pass); $cpass = md5($pass);
} else { } else {
@ -68,12 +68,9 @@ class Application_Model_Subjects {
} }
$sql = "UPDATE ".$CC_CONFIG['subjTable']." SET pass='$cpass'" $sql = "UPDATE ".$CC_CONFIG['subjTable']." SET pass='$cpass'"
." WHERE login='$login' $oldpCond AND type='U'"; ." WHERE login='$login' $oldpCond AND type='U'";
$r = $CC_DBC->query($sql); $con->exec($sql);
if (PEAR::isError($r)) {
return $r;
}
return TRUE; return TRUE;
} // fn passwd }
/* --------------------------------------------------------------- groups */ /* --------------------------------------------------------------- groups */
@ -84,20 +81,21 @@ class Application_Model_Subjects {
* Get subject id from login * Get subject id from login
* *
* @param string $login * @param string $login
* @return int|PEAR_Error * @return int|false
*/ */
public static function GetSubjId($login) public static function GetSubjId($login)
{ {
global $CC_CONFIG; global $CC_CONFIG;
global $CC_DBC; $con = Propel::getConnection();
$sql = "SELECT id FROM ".$CC_CONFIG['subjTable'] $sql = "SELECT id FROM ".$CC_CONFIG['subjTable']
." WHERE login='$login'"; ." WHERE login='$login'";
return $CC_DBC->getOne($sql); $query = $con->query($sql)->fetchColumn(0);
} // fn getSubjId return $query ? $query : NULL;
}
/** /**
* Return true if uid is [id]direct member of gid * Return true if uid is direct member of gid
* *
* @param int $uid * @param int $uid
* local user id * local user id
@ -107,47 +105,42 @@ class Application_Model_Subjects {
*/ */
public static function IsMemberOf($uid, $gid) public static function IsMemberOf($uid, $gid)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG;
$sql = "SELECT count(*)as cnt" $con = Propel::getConnection();
$sql = "SELECT count(*) as cnt"
." FROM ".$CC_CONFIG['smembTable'] ." FROM ".$CC_CONFIG['smembTable']
." WHERE uid='$uid' AND gid='$gid'"; ." WHERE uid='$uid' AND gid='$gid'";
$res = $CC_DBC->getOne($sql); $res = $con->query($sql)->fetchColumn(0);
if (PEAR::isError($res)) {
return $res;
}
return (intval($res) > 0); return (intval($res) > 0);
} // fn isMemberOf }
public static function increaseLoginAttempts($login){ public static function increaseLoginAttempts($login)
global $CC_CONFIG, $CC_DBC; {
global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "UPDATE ".$CC_CONFIG['subjTable']." SET login_attempts = login_attempts+1" $sql = "UPDATE ".$CC_CONFIG['subjTable']." SET login_attempts = login_attempts+1"
." WHERE login='$login'"; ." WHERE login='$login'";
$res = $CC_DBC->query($sql); $res = $con->exec($sql);
if (PEAR::isError($res)) {
return $res;
}
return (intval($res) > 0); return (intval($res) > 0);
} }
public static function resetLoginAttempts($login){ public static function resetLoginAttempts($login)
global $CC_CONFIG, $CC_DBC; {
global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "UPDATE ".$CC_CONFIG['subjTable']." SET login_attempts = '0'" $sql = "UPDATE ".$CC_CONFIG['subjTable']." SET login_attempts = '0'"
." WHERE login='$login'"; ." WHERE login='$login'";
$res = $CC_DBC->query($sql); $res = $con->exec($sql);
if (PEAR::isError($res)) { return TRUE;
return $res;
}
return (intval($res) > 0);
} }
public static function getLoginAttempts($login){ public static function getLoginAttempts($login)
global $CC_CONFIG, $CC_DBC; {
global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT login_attempts FROM ".$CC_CONFIG['subjTable']." WHERE login='$login'"; $sql = "SELECT login_attempts FROM ".$CC_CONFIG['subjTable']." WHERE login='$login'";
$res = $CC_DBC->getOne($sql); $res = $con->query($sql)->fetchColumn(0);
if (PEAR::isError($res)) { return $res ? $res : 0;
return $res;
}
return $res;
} }
} // class Subjects } // class Subjects

View file

@ -185,15 +185,14 @@ class Application_Model_User {
return $user; return $user;
} }
public static function getUsers($type, $search=NULL) { public static function getUsers($type, $search=NULL)
global $CC_DBC; {
$con = Propel::getConnection();
$sql;
$sql_gen = "SELECT login AS value, login AS label, id as index FROM cc_subjs "; $sql_gen = "SELECT login AS value, login AS label, id as index FROM cc_subjs ";
$sql = $sql_gen; $sql = $sql_gen;
if(is_array($type)) { if (is_array($type)) {
for($i=0; $i<count($type); $i++) { for($i=0; $i<count($type); $i++) {
$type[$i] = "type = '{$type[$i]}'"; $type[$i] = "type = '{$type[$i]}'";
} }
@ -205,7 +204,7 @@ class Application_Model_User {
$sql = $sql_gen ." WHERE (". $sql_type.") "; $sql = $sql_gen ." WHERE (". $sql_type.") ";
if(!is_null($search)) { if (!is_null($search)) {
$like = "login ILIKE '%{$search}%'"; $like = "login ILIKE '%{$search}%'";
$sql = $sql . " AND ".$like; $sql = $sql . " AND ".$like;
@ -213,22 +212,20 @@ class Application_Model_User {
$sql = $sql ." ORDER BY login"; $sql = $sql ." ORDER BY login";
return $CC_DBC->GetAll($sql); return $con->query($sql)->fetchAll();;
} }
public static function getUserCount($type=NULL){ public static function getUserCount($type=NULL){
global $CC_DBC; $con = Propel::getConnection();
$sql = '';
$sql;
$sql_gen = "SELECT count(*) AS cnt FROM cc_subjs "; $sql_gen = "SELECT count(*) AS cnt FROM cc_subjs ";
if(!isset($type)){ if (!isset($type)) {
$sql = $sql_gen; $sql = $sql_gen;
} }
else{ else{
if(is_array($type)) { if (is_array($type)) {
for($i=0; $i<count($type); $i++) { for ($i=0; $i<count($type); $i++) {
$type[$i] = "type = '{$type[$i]}'"; $type[$i] = "type = '{$type[$i]}'";
} }
$sql_type = join(" OR ", $type); $sql_type = join(" OR ", $type);
@ -240,7 +237,8 @@ class Application_Model_User {
$sql = $sql_gen ." WHERE (". $sql_type.") "; $sql = $sql_gen ." WHERE (". $sql_type.") ";
} }
return $CC_DBC->GetOne($sql); $query = $con->query($sql)->fetchColumn(0);
return $query ? $query : NULL;
} }
public static function getHosts($search=NULL) { public static function getHosts($search=NULL) {
@ -277,13 +275,13 @@ class Application_Model_User {
} }
public static function getUserData($id){ public static function getUserData($id){
global $CC_DBC; $con = Propel::getConnection();
$sql = "SELECT login, first_name, last_name, type, id, email, skype_contact, jabber_contact" $sql = "SELECT login, first_name, last_name, type, id, email, skype_contact, jabber_contact"
." FROM cc_subjs" ." FROM cc_subjs"
." WHERE id = $id"; ." WHERE id = $id";
return $CC_DBC->GetRow($sql); return $con->query($sql)->fetch();
} }
public static function GetUserID($login){ public static function GetUserID($login){