diff --git a/airtime_mvc/application/Bootstrap.php b/airtime_mvc/application/Bootstrap.php index 4b0f7e35d..e7f4ac90e 100644 --- a/airtime_mvc/application/Bootstrap.php +++ b/airtime_mvc/application/Bootstrap.php @@ -10,7 +10,7 @@ require_once 'propel/runtime/lib/Propel.php'; Propel::init(__DIR__."/configs/airtime-conf-production.php"); require_once __DIR__."/configs/constants.php"; -require_once 'DB.php'; +// require_once 'DB.php'; require_once 'Preference.php'; require_once "DateHelper.php"; @@ -20,12 +20,34 @@ require_once __DIR__.'/controllers/plugins/RabbitMqPlugin.php'; global $CC_CONFIG, $CC_DBC; $dsn = $CC_CONFIG['dsn']; -$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); +// ****************************************************************** +// Differences between PEAR DB & Propel/PDO: +// When selecting a single value from a null return set, +// PEAR returns NULL +// PDO returns false +// ****************************************************************** + +// $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(); diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 1ef9b3aa1..232577ae5 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -342,7 +342,7 @@ class ApiController extends Zend_Controller_Action exit; } - PEAR::setErrorHandling(PEAR_ERROR_RETURN); + //PEAR::setErrorHandling(PEAR_ERROR_RETURN); $data = Application_Model_Schedule::GetScheduledPlaylists(); echo json_encode($data, JSON_FORCE_OBJECT); diff --git a/airtime_mvc/application/models/LoginAttempts.php b/airtime_mvc/application/models/LoginAttempts.php index 18b16df9b..6ebeafff6 100644 --- a/airtime_mvc/application/models/LoginAttempts.php +++ b/airtime_mvc/application/models/LoginAttempts.php @@ -1,45 +1,36 @@ GetOne($sql); - if($res){ + $res = $con->query($sql)->fetchColumn(0); + if ($res) { $sql = "UPDATE cc_login_attempts SET attempts=attempts+1 WHERE ip='$ip'"; - $res = $CC_DBC->query($sql); - if (PEAR::isError($res)) { - return $res; - } - }else{ + $con->exec($sql); + } else { $sql = "INSERT INTO cc_login_attempts (ip, attempts) values ('$ip', '1')"; - $res = $CC_DBC->query($sql); - if (PEAR::isError($res)) { - return $res; - } + $con->exec($sql); } } - + public static function getAttempts($ip){ - global $CC_DBC; + $con = Propel::getConnection(); $sql = "select attempts from cc_login_attempts WHERE ip='$ip'"; - $res = $CC_DBC->GetOne($sql); - return $res; + $res = $con->query($sql)->fetchColumn(0); + return $res ? $res : 0; } - + public static function resetAttempts($ip){ - global $CC_DBC; + $con = Propel::getConnection(); $sql = "select count(*) from cc_login_attempts WHERE ip='$ip'"; - $res = $CC_DBC->GetOne($sql); - if($res){ + $res = $con->query($sql)->fetchColumn(0); + if ($res > 0) { $sql = "DELETE FROM cc_login_attempts WHERE ip='$ip'"; - $res = $CC_DBC->query($sql); - if (PEAR::isError($res)) { - return $res; - } + $con->exec($sql); } } } \ No newline at end of file diff --git a/airtime_mvc/application/models/MusicDir.php b/airtime_mvc/application/models/MusicDir.php index b07ffff75..3c8b64e01 100644 --- a/airtime_mvc/application/models/MusicDir.php +++ b/airtime_mvc/application/models/MusicDir.php @@ -58,7 +58,8 @@ class Application_Model_MusicDir { 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 * 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 * otherwise, it will set "Exists" flag to true - **/ + */ public function remove($userAddedWatchedDir=true) { - global $CC_DBC; + $con = Propel::getConnection(); $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 - RIGHT JOIN cc_schedule as s on s.file_id = f.id WHERE md.id = $music_dir_id"; + $sql = "SELECT DISTINCT s.instance_id from cc_music_dirs as md " + ." 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 - $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"; - $files = $CC_DBC->GetAll($sql); + $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"; + $files = $con->query($sql)->fetchAll(); // 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']); if($temp_file != null){ $temp_file->setFileExistsFlag(false); @@ -92,9 +95,9 @@ class Application_Model_MusicDir { } // set RemovedFlag to true - if($userAddedWatchedDir){ + if ($userAddedWatchedDir) { self::setWatchedFlag(false); - }else{ + } else { self::setExistsFlag(false); } //$res = $this->_dir->delete(); diff --git a/airtime_mvc/application/models/Playlist.php b/airtime_mvc/application/models/Playlist.php index 92063218c..bc48bb2d0 100644 --- a/airtime_mvc/application/models/Playlist.php +++ b/airtime_mvc/application/models/Playlist.php @@ -541,7 +541,7 @@ class Application_Model_Playlist { ->filterByDbPlaylistId($this->id) ->filterByDbPosition($this->getSize()-1) ->findOne($this->con); - + $this->changeFadeInfo($row->getDbId(), null, $fadeout); } } @@ -769,10 +769,12 @@ class Application_Model_Playlist { return $res; } - public static function getPlaylistCount(){ - global $CC_CONFIG, $CC_DBC; + public static function getPlaylistCount() + { + global $CC_CONFIG; + $con = Propel::getConnection(); $sql = 'SELECT count(*) as cnt FROM '.$CC_CONFIG["playListTable"]; - return $CC_DBC->GetOne($sql); + return $con->query($sql)->fetchColumn(0); } /** diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index 0786152c3..5601a6158 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -4,7 +4,8 @@ class Application_Model_Preference { public static function SetValue($key, $value, $isUserValue = false){ - global $CC_CONFIG, $CC_DBC; + global $CC_CONFIG; + $con = Propel::getConnection(); //called from a daemon process if(!class_exists("Zend_Auth", false) || !Zend_Auth::getInstance()->hasIdentity()) { @@ -21,13 +22,13 @@ class Application_Model_Preference //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 = $CC_DBC->GetOne($sql); + + $result = $con->query($sql)->fetchColumn(0); if($result == 1) { // result found @@ -38,8 +39,8 @@ class Application_Model_Preference ." WHERE keystr = '$key'"; } else { // user pref - $sql = "UPDATE cc_pref" - . " SET valstr = '$value'" + $sql = "UPDATE cc_pref" + . " SET valstr = '$value'" . " WHERE keystr = '$key' AND subjid = $id"; } } else { @@ -54,39 +55,39 @@ class Application_Model_Preference ." VALUES ($id, '$key', '$value')"; } } - - return $CC_DBC->query($sql); + + return $con->exec($sql); } public static function GetValue($key, $isUserValue = false){ - global $CC_CONFIG, $CC_DBC; - + global $CC_CONFIG; + $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) { + if ($isUserValue) { $auth = Zend_Auth::getInstance(); if($auth->hasIdentity()) { $id = $auth->getIdentity()->id; $sql .= " AND subjid = '$id'"; } } - $result = $CC_DBC->GetOne($sql); - + $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 = $CC_DBC->GetOne($sql); - return $result; + + $result = $con->query($sql)->fetchColumn(0); + return $result ? $result : ""; } } @@ -109,36 +110,36 @@ class Application_Model_Preference $view->headTitle()->exchangeArray(array()); //clear headTitle ArrayObject $view->headTitle(self::GetHeadTitle()); } - + $eventType = "update_station_name"; $md = array("station_name"=>$title); - + Application_Model_RabbitMq::SendMessageToPypo($eventType, $md); } /** - * Set the furthest date that a never-ending show + * Set the furthest date that a never-ending show * should be populated until. - * + * * @param DateTime $dateTime * A row from cc_show_days table - */ + */ public static function SetShowsPopulatedUntil($dateTime) { self::SetValue("shows_populated_until", $dateTime->format("Y-m-d H:i:s")); } /** - * Get the furthest date that a never-ending show + * Get the furthest date that a never-ending show * should be populated until. * * Returns null if the value hasn't been set, otherwise returns - * a DateTime object representing the date. - * + * a DateTime object representing the date. + * * @return DateTime (in UTC Timezone) */ public static function GetShowsPopulatedUntil() { $date = self::GetValue("shows_populated_until"); - + if ($date == ""){ return null; } else { @@ -163,15 +164,15 @@ class Application_Model_Preference $fade = str_pad($fade, 9, "0", STR_PAD_LEFT); return $fade; } - + public static function SetDefaultTransitionFade($fade) { self::SetValue("default_transition_fade", $fade); - + $eventType = "update_transition_fade"; $md = array("transition_fade"=>$fade); Application_Model_RabbitMq::SendMessageToPypo($eventType, $md); } - + public static function GetDefaultTransitionFade() { $transition_fade = self::GetValue("default_transition_fade"); if($transition_fade == ""){ @@ -182,10 +183,10 @@ class Application_Model_Preference public static function SetStreamLabelFormat($type){ self::SetValue("stream_label_format", $type); - + $eventType = "update_stream_format"; $md = array("stream_format"=>$type); - + Application_Model_RabbitMq::SendMessageToPypo($eventType, $md); } @@ -365,10 +366,11 @@ class Application_Model_Preference return self::GetValue("uniqueId"); } - public static function GetCountryList(){ - global $CC_DBC; + public static function GetCountryList() + { + $con = Propel::getConnection(); $sql = "SELECT * FROM cc_country"; - $res = $CC_DBC->GetAll($sql); + $res = $con->query($sql)->fetchAll(); $out = array(); $out[""] = "Select Country"; foreach($res as $r){ @@ -401,7 +403,7 @@ class Application_Model_Preference $outputArray['STATION_COUNTRY'] = self::GetStationCountry(); $outputArray['STATION_CITY'] = self::GetStationCity(); $outputArray['STATION_DESCRIPTION'] = self::GetStationDescription(); - + // get web server info if(isset($systemInfoArray["AIRTIME_VERSION_URL"])){ @@ -438,7 +440,7 @@ class Application_Model_Preference foreach($s_info as $k => $v){ $outputString .= "\t".strtoupper($k)." : ".$v."\n"; } - } + } }else{ $outputString .= $key.' : '.$out."\n"; } @@ -452,7 +454,7 @@ class Application_Model_Preference return $outputString; } } - + public static function GetInstallMethod(){ $easy_install = file_exists('/usr/bin/airtime-easy-setup'); $debian_install = file_exists('/var/lib/dpkg/info/airtime.config'); @@ -559,7 +561,7 @@ class Application_Model_Preference return self::GetValue("system_version"); } } - + public static function GetLatestVersion(){ $latest = self::GetValue("latest_version"); if($latest == null || strlen($latest) == 0) { @@ -568,14 +570,14 @@ class Application_Model_Preference return $latest; } } - + public static function SetLatestVersion($version){ $pattern = "/^[0-9]+\.[0-9]+\.[0-9]+/"; if(preg_match($pattern, $version)) { self::SetValue("latest_version", $version); } } - + public static function GetLatestLink(){ $link = self::GetValue("latest_link"); if($link == null || strlen($link) == 0) { @@ -584,7 +586,7 @@ class Application_Model_Preference return $link; } } - + public static function SetLatestLink($link){ $pattern = "#^(http|https|ftp)://" . "([a-zA-Z0-9]+\.)*[a-zA-Z0-9]+" . @@ -609,7 +611,7 @@ class Application_Model_Preference public static function GetSoundCloudDownloadbleOption() { return self::GetValue("soundcloud_downloadable"); } - + public static function SetWeekStartDay($day) { self::SetValue("week_start_day", $day); } @@ -622,7 +624,7 @@ class Application_Model_Preference return $val; } } - + /** * Stores the last timestamp of user updating stream setting */ @@ -630,7 +632,7 @@ class Application_Model_Preference $now = time(); self::SetValue("stream_update_timestamp", $now); } - + /** * Gets the last timestamp of user updating stream setting */ @@ -641,22 +643,22 @@ class Application_Model_Preference } return $update_time; } - + public static function GetClientId() { return self::GetValue("client_id"); } - + public static function SetClientId($id) { if (is_numeric($id)) { self::SetValue("client_id", $id); } } - + /* User specific preferences start */ /** * Sets the time scale preference (agendaDay/agendaWeek/month) in Calendar. - * + * * @param $timeScale new time scale */ public static function SetCalendarTimeScale($timeScale) { @@ -674,16 +676,16 @@ class Application_Model_Preference } return $val; } - + /** * Sets the number of entries to show preference in library under Playlist Builder. - * + * * @param $numEntries new number of entries to show */ public static function SetLibraryNumEntries($numEntries) { self::SetValue("library_num_entries", $numEntries, true /* user specific */); } - + /** * Retrieves the number of entries to show preference in library under Playlist Builder. * Defaults to 10 if no entry exists @@ -695,10 +697,10 @@ class Application_Model_Preference } return $val; } - + /** * Sets the time interval preference in Calendar. - * + * * @param $timeInterval new time interval */ public static function SetCalendarTimeInterval($timeInterval) { @@ -716,11 +718,11 @@ class Application_Model_Preference } return $val; } - + public static function SetDiskQuota($value){ self::SetValue("disk_quota", $value, false); } - + public static function GetDiskQuota(){ $val = self::GetValue("disk_quota"); if(strlen($val) == 0) { @@ -728,27 +730,27 @@ class Application_Model_Preference } return $val; } - + public static function SetLiveSteamMasterUsername($value){ self::SetValue("live_stream_master_username", $value, false); } - + public static function GetLiveSteamMasterUsername(){ return self::GetValue("live_stream_master_username"); } - + public static function SetLiveSteamMasterPassword($value){ self::SetValue("live_stream_master_password", $value, false); } - + public static function GetLiveSteamMasterPassword(){ return self::GetValue("live_stream_master_password"); } - + public static function SetSourceStatus($sourcename, $status){ self::SetValue($sourcename, $status, false); } - + public static function GetSourceStatus($sourcename){ $value = self::GetValue($sourcename); if($value == null || $value == "false"){ @@ -757,11 +759,11 @@ class Application_Model_Preference return true; } } - + public static function SetSourceSwitchStatus($sourcename, $status){ self::SetValue($sourcename."_switch", $status, false); } - + public static function GetSourceSwitchStatus($sourcename){ $value = self::GetValue($sourcename."_switch"); if($value == null || $value == "off"){ @@ -770,19 +772,19 @@ class Application_Model_Preference return "on"; } } - + public static function SetMasterDJSourceConnectionURL($value){ self::SetValue("master_dj_source_connection_url", $value, false); } - + public static function GetMasterDJSourceConnectionURL(){ return self::GetValue("master_dj_source_connection_url"); } - + public static function SetLiveDJSourceConnectionURL($value){ self::SetValue("live_dj_source_connection_url", $value, false); } - + public static function GetLiveDJSourceConnectionURL(){ return self::GetValue("live_dj_source_connection_url"); } @@ -795,7 +797,7 @@ class Application_Model_Preference return self::GetValue("system_email"); } /* User specific preferences end */ - + public static function ShouldShowPopUp(){ $today = mktime(0, 0, 0, gmdate("m"), gmdate("d"), gmdate("Y")); $remindDate = Application_Model_Preference::GetRemindMeDate(); diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index ba65f4a22..b185ae93f 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -9,10 +9,11 @@ class Application_Model_Schedule { */ public function IsFileScheduledInTheFuture($p_fileId) { - global $CC_CONFIG, $CC_DBC; + global $CC_CONFIG; + $con = Propel::getConnection(); $sql = "SELECT COUNT(*) FROM ".$CC_CONFIG["scheduleTable"] ." 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')) { return TRUE; } else { @@ -37,13 +38,13 @@ class Application_Model_Schedule { $date = new Application_Common_DateHelper; $timeNow = $date->getTimestamp(); $utcTimeNow = $date->getUtcTimestamp(); - + $shows = Application_Model_Show::getPrevCurrentNext($utcTimeNow); $previousShowID = count($shows['previousShow'])>0?$shows['previousShow'][0]['instance_id']:null; $currentShowID = count($shows['currentShow'])>0?$shows['currentShow'][0]['instance_id']:null; $nextShowID = count($shows['nextShow'])>0?$shows['nextShow'][0]['instance_id']:null; $results = Application_Model_Schedule::GetPrevCurrentNext($previousShowID, $currentShowID, $nextShowID, $utcTimeNow); - + $range = array("env"=>APPLICATION_ENV, "schedulerTime"=>$timeNow, "previous"=>$results['previous'] !=null?$results['previous']:(count($shows['previousShow'])>0?$shows['previousShow'][0]:null), @@ -53,10 +54,10 @@ class Application_Model_Schedule { "nextShow"=>$shows['nextShow'], "timezone"=> date("T"), "timezoneOffset"=> date("Z")); - + return $range; } - + /** * Queries the database for the set of schedules one hour before and after the given time. * If a show starts and ends within that time that is considered the current show. Then the @@ -69,19 +70,20 @@ class Application_Model_Schedule { { if ($p_previousShowID == null && $p_currentShowID == null && $p_nextShowID == null) return; - - global $CC_CONFIG, $CC_DBC; - $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 - LEFT JOIN cc_show_instances si on st.instance_id = si.id + + + global $CC_CONFIG; + $con = Propel::getConnection(); + $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 LEFT JOIN cc_show_instances si on st.instance_id = si.id 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_nextShowID) || isset($p_currentShowID)) $sql .= '('; @@ -102,17 +104,17 @@ class Application_Model_Schedule { $sql .= ')'; } else if($p_previousShowID != null && $p_currentShowID != null) $sql .= ')'; - + $sql .= ' AND st.playout_status > 0 ORDER BY st.starts'; - - $rows = $CC_DBC->GetAll($sql); - + + + $rows = $con->query($sql)->fetchAll(); $numberOfRows = count($rows); $results['previous'] = null; $results['current'] = null; $results['next'] = null; - + $timeNowAsMillis = strtotime($p_timeNow); for( $i = 0; $i < $numberOfRows; ++$i ){ // if the show is overbooked, then update the track end time to the end of the show time. @@ -130,7 +132,6 @@ class Application_Model_Schedule { "ends"=> (($rows[$i]["ends"] > $rows[$i]["show_ends"]) ? $rows[$i]["show_ends"]: $rows[$i]["ends"]), "media_item_played"=>$rows[$i]["media_item_played"], "record"=>0); - if ( isset($rows[$i+1])){ $results['next'] = array("name"=>$rows[$i+1]["artist_name"]." - ".$rows[$i+1]["track_title"], "starts"=>$rows[$i+1]["starts"], @@ -157,10 +158,10 @@ class Application_Model_Schedule { } return $results; } - - public static function GetLastScheduleItem($p_timeNow){ - global $CC_CONFIG, $CC_DBC; + public static function GetLastScheduleItem($p_timeNow){ + global $CC_CONFIG; + $con = Propel::getConnection(); $sql = "SELECT" ." ft.artist_name, ft.track_title," ." st.starts as starts, st.ends as ends" @@ -175,14 +176,14 @@ class Application_Model_Schedule { ." ORDER BY st.ends DESC" ." LIMIT 1"; - $row = $CC_DBC->GetAll($sql); + $row = $con->query($sql)->fetchAll(); return $row; } 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 * rare cases two songs are returned. This happens when a track * that was overbooked from a previous show appears as if it @@ -200,13 +201,13 @@ class Application_Model_Schedule { ." ORDER BY st.starts DESC" ." LIMIT 1"; - $row = $CC_DBC->GetAll($sql); + $row = $con->query($sql)->fetchAll(); return $row; } public static function GetNextScheduleItem($p_timeNow){ - global $CC_CONFIG, $CC_DBC; - + global $CC_CONFIG; + $con = Propel::getConnection(); $sql = "SELECT" ." ft.artist_name, ft.track_title," ." st.starts as starts, st.ends as ends" @@ -221,7 +222,7 @@ class Application_Model_Schedule { ." ORDER BY st.starts" ." LIMIT 1"; - $row = $CC_DBC->GetAll($sql); + $row = $con->query($sql)->fetchAll(); return $row; } @@ -236,8 +237,8 @@ class Application_Model_Schedule { */ public static function GetScheduleDetailItems($p_start, $p_end, $p_shows) { - global $CC_CONFIG, $CC_DBC; - + global $CC_CONFIG; + $con = Propel::getConnection(); $sql = "SELECT DISTINCT showt.name AS show_name, showt.color AS show_color, @@ -265,32 +266,35 @@ class Application_Model_Schedule { ((si.starts >= '{$p_start}' AND si.starts < '{$p_end}') OR (si.ends > '{$p_start}' AND si.ends <= '{$p_end}') OR (si.starts <= '{$p_start}' AND si.ends >= '{$p_end}'))"; - - + + if (count($p_shows) > 0) { $sql .= " AND show_id IN (".implode(",", $p_shows).")"; } $sql .= " ORDER BY si.starts, sched.starts;"; - $rows = $CC_DBC->GetAll($sql); + $rows = $con->query($sql)->fetchAll(); return $rows; } public static function UpdateMediaPlayedStatus($p_id) { - global $CC_CONFIG, $CC_DBC; + global $CC_CONFIG; + $con = Propel::getConnection(); $sql = "UPDATE ".$CC_CONFIG['scheduleTable'] ." SET media_item_played=TRUE" ." WHERE id=$p_id"; - $retVal = $CC_DBC->query($sql); + $retVal = $con->exec($sql); return $retVal; } - public static function getSchduledPlaylistCount(){ - global $CC_CONFIG, $CC_DBC; + public static function getSchduledPlaylistCount() + { + global $CC_CONFIG; + $con = Propel::getConnection(); $sql = "SELECT count(*) as cnt FROM ".$CC_CONFIG['scheduleTable']; - return $CC_DBC->GetOne($sql); + return $con->query($sql)->fetchColumn(0); } @@ -398,7 +402,7 @@ class Application_Model_Schedule { * $p_startTime and $p_endTime specify the range. Schedule items returned * do not have to be entirely within this range. It is enough that the end * or beginning of the scheduled item is in the range. - * + * * * @param string $p_startTime * In the format YYYY-MM-DD HH:MM:SS.nnnnnn @@ -409,8 +413,9 @@ class Application_Model_Schedule { * arrays representing each row. */ 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," ." st.id as id," ." st.instance_id as instance_id," @@ -425,48 +430,42 @@ class Application_Model_Schedule { ." FROM $CC_CONFIG[scheduleTable] as st" ." LEFT JOIN $CC_CONFIG[showInstances] as si" ." ON st.instance_id = si.id"; - + $predicates = " WHERE st.ends > '$p_startTime'" ." AND st.starts < '$p_endTime'" ." AND st.playout_status > 0" ." AND si.ends > '$p_startTime'" ." ORDER BY st.starts"; - + $sql = $baseQuery.$predicates; - $rows = $CC_DBC->GetAll($sql); - if (PEAR::isError($rows)) { - return null; - } - + $rows = $con->query($sql)->fetchAll(); + 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->add(new DateInterval("PT24H")); $range_end = $dt->format("Y-m-d H:i:s"); - + $predicates = " WHERE st.ends > '$p_startTime'" ." AND st.starts < '$range_end'" ." AND st.playout_status > 0" ." AND si.ends > '$p_startTime'" ." ORDER BY st.starts" ." LIMIT 3"; - + $sql = $baseQuery.$predicates; - $rows = $CC_DBC->GetAll($sql); - if (PEAR::isError($rows)) { - return null; - } + $rows = $con->query($sql)->fetchAll(); } - + return $rows; } 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 * from "now" to "now + 24 hours". */ @@ -478,16 +477,16 @@ class Application_Model_Schedule { } if (is_null($p_fromDateTime)) { $t2 = new DateTime("@".time()); - + $cache_ahead_hours = $CC_CONFIG["cache_ahead_hours"]; - + if (is_numeric($cache_ahead_hours)){ //make sure we are not dealing with a float $cache_ahead_hours = intval($cache_ahead_hours); } else { $cache_ahead_hours = 1; } - + $t2->add(new DateInterval("PT".$cache_ahead_hours."H")); $range_end = $t2->format("Y-m-d H:i:s"); } else { @@ -502,7 +501,7 @@ class Application_Model_Schedule { $data["status"] = array(); $data["media"] = array(); - + $kick_times = Application_Model_ShowInstance::GetEndTimeOfNextShowWithLiveDJ($range_start, $range_end); foreach($kick_times as $kick_time_info){ $kick_time = $kick_time_info['ends']; @@ -513,13 +512,13 @@ class Application_Model_Schedule { $switchOffDataTime = new DateTime($kick_time, $utcTimeZone); $switch_off_time = $switchOffDataTime->sub(new DateInterval('PT'.$transition_time.'S')); $switch_off_time = $switch_off_time->format("Y-m-d H:i:s"); - + $kick_start = Application_Model_Schedule::AirtimeTimeToPypoTime($kick_time); $data["media"][$kick_start]['start'] = $kick_start; $data["media"][$kick_start]['end'] = $kick_start; $data["media"][$kick_start]['event_type'] = "kick_out"; $data["media"][$kick_start]['type'] = "event"; - + if($kick_time !== $switch_off_time){ $data["media"][$switch_start]['start'] = Application_Model_Schedule::AirtimeTimeToPypoTime($switch_off_time); $data["media"][$switch_start]['end'] = Application_Model_Schedule::AirtimeTimeToPypoTime($switch_off_time); @@ -547,7 +546,7 @@ class Application_Model_Schedule { /* TODO: Not all tracks will have "show_end" */ if ($trackEndDateTime->getTimestamp() > $showEndDateTime->getTimestamp()){ $di = $trackStartDateTime->diff($showEndDateTime); - + $item["cue_out"] = $di->format("%H:%i:%s").".000"; $item["end"] = $showEndDateTime->format("Y-m-d H:i:s"); } @@ -576,8 +575,9 @@ class Application_Model_Schedule { public static function deleteAll() { - global $CC_CONFIG, $CC_DBC; - $CC_DBC->query("TRUNCATE TABLE ".$CC_CONFIG["scheduleTable"]); + global $CC_CONFIG; + $con = Propel::getConnection(); + $con->exec("TRUNCATE TABLE ".$CC_CONFIG["scheduleTable"]); } public static function deleteWithFileId($fileId){ diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index a3cf0588a..8e8e558e4 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -113,36 +113,38 @@ class Application_Model_Show { public function getHosts() { - global $CC_DBC; + $con = Propel::getConnection(); $sql = "SELECT first_name, last_name FROM cc_show_hosts LEFT JOIN cc_subjs ON cc_show_hosts.subjs_id = cc_subjs.id WHERE show_id = {$this->_showId}"; - $hosts = $CC_DBC->GetAll($sql); + $hosts = $con->query($sql)->fetchAll(); $res = array(); - foreach($hosts as $host) { + foreach ($hosts as $host) { $res[] = $host['first_name']." ".$host['last_name']; } return $res; } - + public function getHostsIds() { - global $CC_DBC; + $con = Propel::getConnection(); $sql = "SELECT subjs_id FROM cc_show_hosts WHERE show_id = {$this->_showId}"; - $hosts = $CC_DBC->GetAll($sql); + $hosts = $con->query($sql)->fetchAll(); return $hosts; } - //remove everything about this show. + /** + * remove everything about this show. + */ public function delete() { //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) { - global $CC_DBC; + $con = Propel::getConnection(); if ($deltaDay > 0) { 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')"; //do both the queries at once. - $CC_DBC->query($sql); + $con->exec($sql); $con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME); $con->beginTransaction(); @@ -215,7 +217,7 @@ class Application_Model_Show { public function cancelShow($day_timestamp) { - global $CC_DBC; + $con = Propel::getConnection(); $timeinfo = explode(" ", $day_timestamp); @@ -227,7 +229,7 @@ class Application_Model_Show { SET modified_instance = TRUE WHERE starts >= '{$day_timestamp}' AND show_id = {$this->_showId}"; - $CC_DBC->query($sql); + $con->exec($sql); // check if we can safely delete the show $showInstancesRow = CcShowInstancesQuery::create() @@ -237,7 +239,7 @@ class Application_Model_Show { if(is_null($showInstancesRow)){ $sql = "DELETE FROM cc_show WHERE id = {$this->_showId}"; - $CC_DBC->query($sql); + $con->exec($sql); } Application_Model_RabbitMq::PushSchedule(); @@ -258,7 +260,7 @@ class Application_Model_Show { */ 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) $daysRemovedUTC = array(); @@ -303,7 +305,7 @@ class Application_Model_Show { //Logging::log($sql); - $CC_DBC->query($sql); + $con->exec($sql); } /** @@ -315,10 +317,10 @@ class Application_Model_Show { */ public function isRecorded(){ $showInstancesRow = CcShowInstancesQuery::create() - ->filterByDbShowId($this->getId()) - ->filterByDbRecord(1) - ->filterByDbModifiedInstance(false) - ->findOne(); + ->filterByDbShowId($this->getId()) + ->filterByDbRecord(1) + ->filterByDbModifiedInstance(false) + ->findOne(); return !is_null($showInstancesRow); } @@ -351,7 +353,7 @@ class Application_Model_Show { */ public function getRebroadcastsAbsolute() { - global $CC_DBC; + $con = Propel::getConnection(); $showId = $this->getId(); @@ -361,7 +363,7 @@ class Application_Model_Show { //Logging::log($sql); - $rebroadcasts = $CC_DBC->GetAll($sql); + $rebroadcasts = $con->query($sql)->fetchAll(); $rebroadcastsLocal = array(); //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() { - global $CC_DBC; + $con = Propel::getConnection(); $showId = $this->getId(); $sql = "SELECT day_offset, start_time FROM cc_show_rebroadcast " ."WHERE show_id = $showId " ."ORDER BY day_offset"; - return $CC_DBC->GetAll($sql); + return $con->query($sql)->fetchAll(); } /** @@ -431,8 +433,8 @@ class Application_Model_Show { public function getRepeatType() { $showDaysRow = CcShowDaysQuery::create() - ->filterByDbShowId($this->_showId) - ->findOne(); + ->filterByDbShowId($this->_showId) + ->findOne(); if (!is_null($showDaysRow)){ return $showDaysRow->getDbRepeatType(); @@ -447,21 +449,17 @@ class Application_Model_Show { * Return the end date for the repeating show or the empty * string if there is no end. */ - public function getRepeatingEndDate(){ - global $CC_DBC; + public function getRepeatingEndDate() + { + $con = Propel::getConnection(); $showId = $this->getId(); $sql = "SELECT last_show FROM cc_show_days" ." WHERE show_id = $showId" ." ORDER BY last_show DESC"; - $endDate = $CC_DBC->GetOne($sql); - - if (is_null($endDate)){ - return ""; - } else { - return $endDate; - } + $query = $con->query($sql)->fetchColumn(0); + return $query ? $query : ""; } /** @@ -475,7 +473,7 @@ class Application_Model_Show { * be gone for good. */ public function deleteAllInstances(){ - global $CC_DBC; + $con = Propel::getConnection(); $timestamp = gmdate("Y-m-d H:i:s"); @@ -484,7 +482,7 @@ class Application_Model_Show { ." WHERE starts > TIMESTAMP '$timestamp'" ." 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. */ public function deleteAllRebroadcasts(){ - global $CC_DBC; + $con = Propel::getConnection(); $timestamp = gmdate("Y-m-d H:i:s"); @@ -502,7 +500,7 @@ class Application_Model_Show { ." AND show_id = $showId" ." 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. */ public function removeAllInstancesFromDate($p_date=null){ - global $CC_DBC; + $con = Propel::getConnection(); $timestamp = gmdate("Y-m-d H:i:s"); @@ -530,7 +528,7 @@ class Application_Model_Show { ." AND starts > TIMESTAMP '$timestamp'" ." 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 */ public function removeAllInstancesBeforeDate($p_date){ - global $CC_DBC; + $con = Propel::getConnection(); $timestamp = gmdate("Y-m-d H:i:s"); @@ -557,7 +555,7 @@ class Application_Model_Show { ." AND starts > TIMESTAMP '$timestamp'" ." 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 */ public function getStartDate(){ - global $CC_DBC; + $con = Propel::getConnection(); $showId = $this->getId(); $sql = "SELECT first_show, start_time, timezone FROM cc_show_days" @@ -575,11 +573,12 @@ class Application_Model_Show { ." ORDER BY first_show" ." LIMIT 1"; - $rows = $CC_DBC->GetAll($sql); + $query = $con->query($sql); - if (count($rows) == 0){ + if ($query->rowCount() == 0){ return ""; } else { + $rows = $query->fetchAll(); $row = $rows[0]; $dt = new DateTime($row["first_show"]." ".$row["start_time"], new DateTimeZone($row["timezone"])); @@ -596,7 +595,7 @@ class Application_Model_Show { */ public function getStartTime(){ - global $CC_DBC; + $con = Propel::getConnection(); $showId = $this->getId(); $sql = "SELECT first_show, start_time, timezone FROM cc_show_days" @@ -604,11 +603,12 @@ class Application_Model_Show { ." ORDER BY first_show" ." LIMIT 1"; - $rows = $CC_DBC->GetAll($sql); + $query = $con->query($sql); - if (count($rows) == 0){ + if ($query->rowCount() == 0){ return ""; } else { + $rows = $query->fetchAll(); $row = $rows[0]; $dt = new DateTime($row["first_show"]." ".$row["start_time"], new DateTimeZone($row["timezone"])); $dt->setTimezone(new DateTimeZone("UTC")); @@ -676,7 +676,7 @@ class Application_Model_Show { * scheduled in the future. */ public function getAllFutureInstanceIds(){ - global $CC_DBC; + $con = Propel::getConnection(); $date = new Application_Common_DateHelper; $timestamp = $date->getTimestamp(); @@ -687,10 +687,10 @@ class Application_Model_Show { ." AND starts > TIMESTAMP '$timestamp'" ." AND modified_instance != TRUE"; - $rows = $CC_DBC->GetAll($sql); + $rows = $con->query($sql)->fetchAll(); $instance_ids = array(); - foreach ($rows as $row){ + foreach ($rows as $row) { $instance_ids[] = $row["id"]; } return $instance_ids; @@ -705,8 +705,7 @@ class Application_Model_Show { */ private function updateDurationTime($p_data){ //need to update cc_show_instances, cc_show_days - - global $CC_DBC; + $con = Propel::getConnection(); $date = new Application_Common_DateHelper; $timestamp = $date->getUtcTimestamp(); @@ -714,20 +713,20 @@ class Application_Model_Show { $sql = "UPDATE cc_show_days " ."SET duration = '$p_data[add_show_duration]' " ."WHERE show_id = $p_data[add_show_id]"; - $CC_DBC->query($sql); + $con->exec($sql); $sql = "UPDATE cc_show_instances " ."SET ends = starts + INTERVAL '$p_data[add_show_duration]' " ."WHERE show_id = $p_data[add_show_id] " ."AND ends > TIMESTAMP '$timestamp'"; - $CC_DBC->query($sql); + $con->exec($sql); + } private function updateStartDateTime($p_data, $p_endDate){ //need to update cc_schedule, cc_show_instances, cc_show_days - - global $CC_DBC; + $con = Propel::getConnection(); $date = new Application_Common_DateHelper; $timestamp = $date->getTimestamp(); @@ -742,7 +741,7 @@ class Application_Model_Show { $sql .= "last_show = DATE '$p_endDate' "; } $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")); $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' " ."WHERE show_id = $p_data[add_show_id] " ."AND starts > TIMESTAMP '$timestamp'"; - $CC_DBC->query($sql); + $con->exec($sql); $showInstanceIds = $this->getAllFutureInstanceIds(); if (count($showInstanceIds) > 0 && $diff != 0){ @@ -762,7 +761,7 @@ class Application_Model_Show { ."SET starts = starts + INTERVAL '$diff sec', " ."ends = ends + INTERVAL '$diff sec' " ."WHERE instance_id IN ($showIdsImploded)"; - $CC_DBC->query($sql); + $con->exec($sql); } } @@ -805,7 +804,7 @@ class Application_Model_Show { return $showInstance; } - + /** * returns info about live stream override info */ @@ -848,7 +847,8 @@ class Application_Model_Show { * @return CcShowInstancesQuery: An propel object representing a * row in the cc_show_instances table. */ public function getInstanceOnDate($p_dateTime){ - global $CC_DBC; + $con = Propel::getConnection(); + $timestamp = $p_dateTime->format("Y-m-d H:i:s"); $showId = $this->getId(); @@ -856,7 +856,8 @@ class Application_Model_Show { ." WHERE date(starts) = date(TIMESTAMP '$timestamp') " ." AND show_id = $showId"; - $row = $CC_DBC->GetOne($sql); + $query = $con->query(); + $row = $query ? $query->fetchColumn(0) : null; return CcShowInstancesQuery::create() ->findPk($row); } @@ -1164,8 +1165,15 @@ class Application_Model_Show { */ public static function populateShowUntil($p_showId) { +<<<<<<< HEAD global $CC_DBC; $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)) { $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"; - $res = $CC_DBC->GetAll($sql); + $res = $con->query($sql)->fetchAll(); foreach ($res as $showRow) { Application_Model_Show::populateShow($showRow, $p_populateUntilDateTime); @@ -1220,8 +1228,13 @@ class Application_Model_Show { */ private static function populateNonRepeatingShow($p_showRow, $p_populateUntilDateTime) { +<<<<<<< HEAD global $CC_DBC; +======= + $con = Propel::getConnection(); + +>>>>>>> CC-1927: Remove PEAR DB $show_id = $p_showRow["show_id"]; $first_show = $p_showRow["first_show"]; //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}"; - $rebroadcasts = $CC_DBC->GetAll($sql); + $rebroadcasts = $con->query($sql)->fetchAll(); //Logging::log('$start time of non repeating record '.$start); +<<<<<<< HEAD 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) { - global $CC_DBC; + $con = Propel::getConnection(); $show_id = $p_showRow["show_id"]; $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; $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); +<<<<<<< HEAD while($utcStartDateTime->getTimestamp() <= $p_populateUntilDateTime->getTimestamp() +======= + while ($utcStartDateTime->getTimestamp() <= $p_dateTime->getTimestamp() +>>>>>>> CC-1927: Remove PEAR DB && (is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp())){ 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) { - global $CC_DBC; + $con = Propel::getConnection(); //UTC DateTime object $showsPopUntil = Application_Model_Preference::GetShowsPopulatedUntil(); @@ -1527,8 +1550,8 @@ class Application_Model_Show { //Logging::log("getShows"); //Logging::log($sql); - - return $CC_DBC->GetAll($sql); + $result = $con->query($sql)->fetchAll(); + return $result; } 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) { - global $CC_DBC; + $con = Propel::getConnection(); $endTimeString = $p_endTimestamp->format("Y-m-d H:i:s"); if (!is_null($p_startTimestamp)) { @@ -1570,8 +1593,7 @@ class Application_Model_Show { OR first_show < '{$endTimeString}' AND last_show > '{$startTimeString}'"; //Logging::log($sql); - - $res = $CC_DBC->GetAll($sql); + $res = $con->query($sql)->fetchAll(); foreach ($res as $row) { Application_Model_Show::populateShow($row, $p_endTimestamp); @@ -1588,22 +1610,18 @@ class Application_Model_Show { */ public static function getFullCalendarEvents($p_start, $p_end, $p_editable=false) { - $events = array(); - $interval = $p_start->diff($p_end); $days = $interval->format('%a'); - $shows = Application_Model_Show::getShows($p_start, $p_end); - $today_timestamp = gmdate("Y-m-d H:i:s"); foreach ($shows as $show) { $options = array(); //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"]); } @@ -1612,19 +1630,19 @@ class Application_Model_Show { } $events[] = Application_Model_Show::makeFullCalendarEvent($show, $options); } - + return $events; } - + /** * Calculates the percentage of a show scheduled given the start and end times in date/time format * and the time_filled as the total time the schow is scheduled for in time format. **/ private static function getPercentScheduled($p_starts, $p_ends, $p_time_filled){ - $durationSeconds = (strtotime($p_ends) - strtotime($p_starts)); - $time_filled = Application_Model_Schedule::WallTimeToMillisecs($p_time_filled) / 1000; + $durationSeconds = (strtotime($p_ends) - strtotime($p_starts)); + $time_filled = Application_Model_Schedule::WallTimeToMillisecs($p_time_filled) / 1000; $percent = ceil(( $time_filled / $durationSeconds) * 100); - + return $percent; } @@ -1722,10 +1740,16 @@ class Application_Model_Show { */ public static function GetCurrentShow($timeNow=null) { - global $CC_CONFIG, $CC_DBC; + global $CC_CONFIG; + $con = Propel::getConnection(); if($timeNow == null){ +<<<<<<< HEAD $date = new Application_Common_DateHelper; $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 $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"; // Convert back to local timezone - $rows = $CC_DBC->GetAll($sql); - + $rows = $con->query($sql)->fetchAll(); return $rows; } @@ -1746,7 +1769,8 @@ class Application_Model_Show { */ 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 $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" @@ -1757,15 +1781,15 @@ class Application_Model_Show { ." ORDER BY si.starts"; // Convert back to local timezone - $rows = $CC_DBC->GetAll($sql); + $rows = $con->query($sql)->fetchAll(); $numberOfRows = count($rows); - + $results['previousShow'] = array(); $results['currentShow'] = array(); $results['nextShow'] = array(); - + $timeNowAsMillis = strtotime($p_timeNow); - + for( $i = 0; $i < $numberOfRows; ++$i ){ //Find the show that is within the current time. if ((strtotime($rows[$i]['starts']) <= $timeNowAsMillis) && (strtotime($rows[$i]['ends']) >= $timeNowAsMillis)){ @@ -1779,9 +1803,9 @@ class Application_Model_Show { "starts"=>$rows[$i-1]['starts'], "ends"=>$rows[$i-1]['ends']); } - + $results['currentShow'][0] = $rows[$i]; - + if ( isset($rows[$i+1])){ $results['nextShow'][0] = array( "id"=>$rows[$i+1]['id'], @@ -1791,7 +1815,7 @@ class Application_Model_Show { "end_timestamp"=>$rows[$i+1]['end_timestamp'], "starts"=>$rows[$i+1]['starts'], "ends"=>$rows[$i+1]['ends']); - + } break; } @@ -1826,6 +1850,7 @@ class Application_Model_Show { } return $results; } + /** * Given a start time $timeStart and end time $timeEnd, returns the next $limit * number of shows within the time interval; @@ -1840,11 +1865,12 @@ class Application_Model_Show { */ 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 // been specified - if($timeEnd == "") { + if ($timeEnd == "") { $timeEnd = "'$timeStart' + INTERVAL '2 days'"; } else { $timeEnd = "'$timeEnd'"; @@ -1864,8 +1890,7 @@ class Application_Model_Show { $sql = $sql . " LIMIT $limit"; } - $rows = $CC_DBC->GetAll($sql); - + $rows = $con->query($sql)->fetchAll(); return $rows; } @@ -1890,14 +1915,16 @@ class Application_Model_Show { } 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" ." 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 $assocArray = array(); - foreach($result as $row) { + foreach ($result as $row) { $assocArray[$row['column_name']] = $row['character_maximum_length']; } diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index a6361dac0..e2af915f9 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -146,8 +146,9 @@ class Application_Model_ShowInstance { $this->_showInstance->getDbModifiedInstance(); } - public function correctScheduleStartTimes(){ - global $CC_DBC; + public function correctScheduleStartTimes() + { + $con = Propel::getConnection(); $instance_id = $this->getShowInstanceId(); $sql = "SELECT starts from cc_schedule" @@ -155,9 +156,9 @@ class Application_Model_ShowInstance { ." ORDER BY starts" ." LIMIT 1"; - $scheduleStarts = $CC_DBC->GetOne($sql); + $scheduleStarts = $con->query($sql)->fetchColumn(0); - if (!is_null($scheduleStarts)){ + if ($scheduleStarts) { $scheduleStartsEpoch = strtotime($scheduleStarts); $showStartsEpoch = strtotime($this->getShowInstanceStart()); @@ -169,7 +170,7 @@ class Application_Model_ShowInstance { ." ends = ends + INTERVAL '$diff' second" ." WHERE instance_id = $instance_id"; - $CC_DBC->query($sql); + $con->exec($sql); } } Application_Model_RabbitMq::PushSchedule(); @@ -300,7 +301,7 @@ class Application_Model_ShowInstance { */ public function resizeShow($deltaDay, $deltaMin) { - global $CC_DBC; + $con = Propel::getConnection(); $hours = $deltaMin/60; if($hours > 0) @@ -319,10 +320,10 @@ class Application_Model_ShowInstance { } $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. - if(strtotime($new_ends) > strtotime($ends)) { + if (strtotime($new_ends) > strtotime($ends)) { $utcStartDateTime = new DateTime($ends, new DateTimeZone("UTC")); $utcEndDateTime = new DateTime($new_ends, new DateTimeZone("UTC")); @@ -339,7 +340,7 @@ class Application_Model_ShowInstance { if($this->isRecorded()) { $sql = "UPDATE cc_show_instances SET ends = (ends + interval '{$deltaDay} days' + interval '{$hours}:{$mins}') WHERE rebroadcast = 1 AND instance_id = {$this->_instanceId}"; - $CC_DBC->query($sql); + $con->exec($sql); } $this->setShowEnd($new_ends); @@ -481,8 +482,6 @@ class Application_Model_ShowInstance { public function delete() { - global $CC_DBC; - // see if it was recording show $recording = $this->isRecorded(); // get show id @@ -631,7 +630,7 @@ class Application_Model_ShowInstance { public function getShowListContent() { - global $CC_DBC; + $con = Propel::getConnection(); $sql = "SELECT * 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); - $results = $CC_DBC->GetAll($sql); + $results = $con->query($sql)->fetchAll(); foreach ($results as &$row) { @@ -655,16 +654,18 @@ class Application_Model_ShowInstance { return $results; } - - public function getLastAudioItemEnd(){ - global $CC_DBC; + + public function getLastAudioItemEnd() + { + $con = Propel::getConnection(); $sql = "SELECT ends FROM cc_schedule " ."WHERE instance_id = {$this->_instanceId} " ."ORDER BY ends DESC " ."LIMIT 1"; - return $CC_DBC->GetOne($sql); + $query = $con->query($sql)->fetchColumn(0); + return $query ? $query : NULL; } public function getShowEndGapTime(){ @@ -682,25 +683,28 @@ class Application_Model_ShowInstance { } public static function GetLastShowInstance($p_timeNow){ - global $CC_CONFIG, $CC_DBC; + global $CC_CONFIG; + $con = Propel::getConnection(); $sql = "SELECT si.id" - ." FROM $CC_CONFIG[showInstances] si" - ." WHERE si.ends < TIMESTAMP '$p_timeNow'" - ." AND si.modified_instance = 'f'" - ." ORDER BY si.ends DESC" - ." LIMIT 1"; + ." FROM $CC_CONFIG[showInstances] si" + ." WHERE si.ends < TIMESTAMP '$p_timeNow'" + ." AND si.modified_instance = 'f'" + ." ORDER BY si.ends DESC" + ." LIMIT 1"; - $id = $CC_DBC->GetOne($sql); - if (is_null($id)){ - return null; - } else { + $id = $con->query($sql)->fetchColumn(0); + if ($id) { return new Application_Model_ShowInstance($id); + } else { + return null; } } - public static function GetCurrentShowInstance($p_timeNow){ - global $CC_CONFIG, $CC_DBC; + public static function GetCurrentShowInstance($p_timeNow) + { + global $CC_CONFIG; + $con = Propel::getConnection(); /* Orderby si.starts descending, because in some cases * we can have multiple shows overlapping each other. In @@ -709,57 +713,63 @@ class Application_Model_ShowInstance { */ $sql = "SELECT si.id" - ." FROM $CC_CONFIG[showInstances] si" - ." WHERE si.starts <= TIMESTAMP '$p_timeNow'" - ." AND si.ends > TIMESTAMP '$p_timeNow'" - ." AND si.modified_instance = 'f'" - ." ORDER BY si.starts DESC" - ." LIMIT 1"; + ." FROM $CC_CONFIG[showInstances] si" + ." WHERE si.starts <= TIMESTAMP '$p_timeNow'" + ." AND si.ends > TIMESTAMP '$p_timeNow'" + ." AND si.modified_instance = 'f'" + ." ORDER BY si.starts DESC" + ." LIMIT 1"; - $id = $CC_DBC->GetOne($sql); - if (is_null($id)){ - return null; - } else { + $id = $con->query($sql)->fetchColumn(0); + if ($id) { return new Application_Model_ShowInstance($id); + } else { + return null; } } - public static function GetNextShowInstance($p_timeNow){ - global $CC_CONFIG, $CC_DBC; + public static function GetNextShowInstance($p_timeNow) + { + global $CC_CONFIG; + $con = Propel::getConnection(); $sql = "SELECT si.id" - ." FROM $CC_CONFIG[showInstances] si" - ." WHERE si.starts > TIMESTAMP '$p_timeNow'" - ." AND si.modified_instance = 'f'" - ." ORDER BY si.starts" - ." LIMIT 1"; + ." FROM $CC_CONFIG[showInstances] si" + ." WHERE si.starts > TIMESTAMP '$p_timeNow'" + ." AND si.modified_instance = 'f'" + ." ORDER BY si.starts" + ." LIMIT 1"; - $id = $CC_DBC->GetOne($sql); - if (is_null($id)){ - return null; - } else { + $id = $con->query($sql)->fetchColumn(0); + if ($id) { return new Application_Model_ShowInstance($id); + } else { + return null; } } // returns number of show instances that ends later than $day - public static function GetShowInstanceCount($day){ - global $CC_CONFIG, $CC_DBC; + public static function GetShowInstanceCount($day) + { + global $CC_CONFIG; + $con = Propel::getConnection(); $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 - public static function GetEndTimeOfNextShowWithLiveDJ($p_startTime, $p_endTime){ - global $CC_CONFIG, $CC_DBC; - + public static function GetEndTimeOfNextShowWithLiveDJ($p_startTime, $p_endTime) + { + global $CC_CONFIG; + $con = Propel::getConnection(); + $sql = "SELECT ends FROM cc_show_instances as si JOIN cc_show as sh ON si.show_id = sh.id 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"; - - return $CC_DBC->GetAll($sql); + + return $con->query($sql)->fetchAll(); } function isRepeating(){ diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 770fecaf8..7347e3f0c 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -242,16 +242,14 @@ class Application_Model_StoredFile { */ 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); $eb = (!is_null($p_editedby) ? ", editedBy=$p_editedby" : ''); $sql = "UPDATE ".$CC_CONFIG['filesTable'] - ." SET state='$escapedState'$eb, mtime=now()" - ." WHERE gunid='{$this->gunid}'"; - $res = $CC_DBC->query($sql); - if (PEAR::isError($res)) { - return $res; - } + ." SET state='$escapedState'$eb, mtime=now()" + ." WHERE gunid='{$this->gunid}'"; + $res = $con->exec($sql); $this->state = $p_state; $this->editedby = $p_editedby; return TRUE; @@ -262,11 +260,12 @@ class Application_Model_StoredFile { * @return array */ public function getPlaylists() { - global $CC_CONFIG, $CC_DBC; + global $CC_CONFIG; + $con = Propel::getConnection(); $sql = "SELECT playlist_id " - ." FROM ".$CC_CONFIG['playistTable'] - ." WHERE file_id='{$this->id}'"; - $ids = $CC_DBC->getAll($sql); + ." FROM ".$CC_CONFIG['playistTable'] + ." WHERE file_id='{$this->id}'"; + $ids = $con->query($sql)->fetchAll(); $playlists = array(); if (is_array($ids) && count($ids) > 0) { foreach ($ids as $id) { @@ -583,7 +582,7 @@ Logging::log("getting media! - 2"); } public static function searchLibraryFiles($datatables) { - + $con = Propel::getConnection(CcFilesPeer::DATABASE_NAME); $displayColumns = array("id", "track_title", "artist_name", "album_title", "genre", "length", @@ -656,7 +655,7 @@ Logging::log("getting media! - 2"); default: $fromTable = $unionTable; } - + $results = Application_Model_Datatables::findEntries($con, $displayColumns, $fromTable, $datatables); //Used by the audio preview functionality in the library. @@ -803,7 +802,7 @@ Logging::log("getting media! - 2"); //check to see if we have enough space in the /organize directory to copy the file $freeSpace = disk_free_space($destination_folder); $fileSize = filesize($audio_file); - + if ( $freeSpace < $fileSize){ $freeSpace = ceil($freeSpace/1024/1024); $fileSize = ceil($fileSize/1024/1024); @@ -820,6 +819,7 @@ Logging::log("getting media! - 2"); $md5 = md5_file($audio_file); $duplicate = Application_Model_StoredFile::RecallByMd5($md5, true); + $result = null; if ($duplicate) { if (PEAR::isError($duplicate)) { @@ -865,9 +865,11 @@ Logging::log("getting media! - 2"); 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"; - 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 $propelObj - if this is true, it returns array of proepl obj */ - public static function listAllFiles($dir_id=null, $propelObj=false){ - global $CC_DBC; + public static function listAllFiles($dir_id=null, $propelObj=false) + { + $con = Propel::getConnection(); - if($propelObj){ + if ($propelObj) { $sql = "SELECT m.directory || f.filepath as fp" ." FROM CC_MUSIC_DIRS m" ." LEFT JOIN CC_FILES f" ." ON m.id = f.directory WHERE m.id = $dir_id and f.file_exists = 'TRUE'"; - }else{ + } else { $sql = "SELECT filepath as fp" ." FROM CC_FILES" ." WHERE directory = $dir_id and file_exists = 'TRUE'"; } - $rows = $CC_DBC->getAll($sql); + $rows = $con->query($sql)->fetchAll(); $results = array(); - foreach ($rows as $row){ - if($propelObj){ + foreach ($rows as $row) { + if ($propelObj) { $results[] = Application_Model_StoredFile::RecallByFilepath($row["fp"]); - }else{ + } else { $results[] = $row["fp"]; } } diff --git a/airtime_mvc/application/models/StreamSetting.php b/airtime_mvc/application/models/StreamSetting.php index ab05fadb9..7c3d9715f 100644 --- a/airtime_mvc/application/models/StreamSetting.php +++ b/airtime_mvc/application/models/StreamSetting.php @@ -1,19 +1,21 @@ GetOne($sql); + ." WHERE keyname = '$key'"; - if($result == 1) { + $result = $con->query($sql)->fetchColumn(0); + + if ($result == 1) { $sql = "UPDATE cc_stream_setting" ." SET value = '$value', type='$type'" ." WHERE keyname = '$key'"; @@ -21,139 +23,146 @@ class Application_Model_StreamSetting { $sql = "INSERT INTO cc_stream_setting (keyname, value, type)" ." VALUES ('$key', '$value', '$type')"; } - - return $CC_DBC->query($sql); + + return $con->exec($sql); } - - public static function GetValue($key){ - global $CC_CONFIG, $CC_DBC; - + + public static function GetValue($key) + { + global $CC_CONFIG; + $con = Propel::getConnection(); + //Check if key already exists $sql = "SELECT COUNT(*) FROM cc_stream_setting" ." WHERE keyname = '$key'"; - $result = $CC_DBC->GetOne($sql); + $result = $con->query($sql)->fetchColumn(0); if ($result == 0) return ""; else { $sql = "SELECT value FROM cc_stream_setting" - ." WHERE keyname = '$key'"; - - $result = $CC_DBC->GetOne($sql); - return $result; + ." WHERE keyname = '$key'"; + + $result = $con->query($sql)->fetchColumn(0); + return $result ? $result : NULL; } } /* 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"] */ - public static function getEnabledStreamIds(){ - global $CC_DBC; + public static function getEnabledStreamIds() + { + $con = Propel::getConnection(); $sql = "SELECT * " ."FROM cc_stream_setting " ."WHERE keyname LIKE '%_enable' " ."AND value='true'"; - $rows = $CC_DBC->getAll($sql); + $rows = $con->query($sql)->fetchAll(); $ids = array(); - foreach ($rows as $row){ + foreach ($rows as $row) { $ids[] = substr($row["keyname"], 0, strpos($row["keyname"], "_")); } //Logging::log(print_r($ids, true)); - return $ids; } - - /* Retruns only global data as array*/ - public static function getGlobalData(){ - global $CC_DBC; - $sql = "SELECT * " - ."FROM cc_stream_setting " - ."WHERE keyname IN ('output_sound_device', 'icecast_vorbis_metadata')"; - - $rows = $CC_DBC->getAll($sql); - $data = array(); - - foreach($rows as $row){ - $data[$row["keyname"]] = $row["value"]; - } - - return $data; - } - /* Returns all information related to a specific stream. An example - * of a stream id is 's1' or 's2'. */ - public static function getStreamData($p_streamId){ - global $CC_DBC; - $sql = "SELECT * " - ."FROM cc_stream_setting " - ."WHERE keyname LIKE '${p_streamId}_%'"; - $rows = $CC_DBC->getAll($sql); + /* Returns only global data as array*/ + public static function getGlobalData() + { + $con = Propel::getConnection(); + $sql = "SELECT * " + ."FROM cc_stream_setting " + ."WHERE keyname IN ('output_sound_device', 'icecast_vorbis_metadata')"; + + $rows = $con->query($sql)->fetchAll(); $data = array(); - foreach($rows as $row){ + foreach ($rows as $row) { $data[$row["keyname"]] = $row["value"]; } return $data; } - - public static function getStreamSetting(){ - global $CC_DBC; + + /* Returns all information related to a specific stream. An example + * of a stream id is 's1' or 's2'. */ + public static function getStreamData($p_streamId) + { + $con = Propel::getConnection(); + $sql = "SELECT * " + ."FROM cc_stream_setting " + ."WHERE keyname LIKE '${p_streamId}_%'"; + + $rows = $con->query($sql)->fetchAll(); + $data = array(); + + foreach ($rows as $row) { + $data[$row["keyname"]] = $row["value"]; + } + + return $data; + } + + public static function getStreamSetting() + { + $con = Propel::getConnection(); $sql = "SELECT *" ." FROM cc_stream_setting" ." WHERE keyname not like '%_error'"; - $rows = $CC_DBC->getAll($sql); - + $rows = $con->query($sql)->fetchAll(); + $exists = array(); - - foreach($rows as $r){ - if($r['keyname'] == 'master_live_stream_port'){ + + foreach ($rows as $r) { + if ($r['keyname'] == 'master_live_stream_port') { $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; - }elseif($r['keyname'] == 'dj_live_stream_port'){ + } elseif($r['keyname'] == 'dj_live_stream_port') { $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; } } - - 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")); } - 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")); } - 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")); } - 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")); } return $rows; } - + /* * function that take all the information of stream and sets them. * This is used by stream setting via UI. - * + * * @param $data - array that contains all the data. $data is [][] which * contains multiple stream information */ - public static function setStreamSetting($data){ - global $CC_DBC; - + public static function setStreamSetting($data) + { + $con = Propel::getConnection(); + foreach ($data as $key=>$d) { if ($key == "output_sound_device" || $key == "icecast_vorbis_metadata") { $v = $d == 1?"true":"false"; $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") { $sql = "UPDATE cc_stream_setting SET value='$d' WHERE keyname='$key'"; - $CC_DBC->query($sql); + $con->exec($sql); } else if (is_array($d)) { $temp = explode('_', $key); $prefix = $temp[0]; @@ -164,71 +173,75 @@ class Application_Model_StreamSetting { } $v = trim($v); $sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$keyname'"; - $CC_DBC->query($sql); + $con->exec($sql); } } else { Logging::log("Warning unexpected value: ".$key); } } } - + /* * Sets indivisual stream setting. - * + * * $data - data array. $data is []. */ - public static function setIndivisualStreamSetting($data){ - global $CC_DBC; - - foreach($data as $keyname => $v){ + public static function setIndivisualStreamSetting($data) + { + $con = Propel::getConnection(); + + foreach ($data as $keyname => $v) { $sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$keyname'"; - $CC_DBC->query($sql); + $con->exec($sql); } } - + /* * Stores liquidsoap status if $boot_time > save time. * save time is the time that user clicked save on stream setting page */ - public static function setLiquidsoapError($stream_id, $msg, $boot_time=null){ - global $CC_DBC; - + public static function setLiquidsoapError($stream_id, $msg, $boot_time=null) + { + $con = Propel::getConnection(); + $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"; $sql = "SELECT COUNT(*) FROM cc_stream_setting" ." WHERE keyname = '$keyname'"; - $result = $CC_DBC->GetOne($sql); - if ($result == 1){ + $result = $con->query($sql)->fetchColumn(0); + if ($result == 1) { $sql = "UPDATE cc_stream_setting" ." SET value = '$msg'" ." WHERE keyname = '$keyname'"; - }else{ + } else { $sql = "INSERT INTO cc_stream_setting (keyname, value, type)" ." VALUES ('$keyname', '$msg', 'string')"; } - $res = $CC_DBC->query($sql); + $res = $con->exec($sql); } } - - public static function getLiquidsoapError($stream_id){ - global $CC_DBC; - + + public static function getLiquidsoapError($stream_id) + { + $con = Propel::getConnection(); + $keyname = "s".$stream_id."_liquidsoap_error"; $sql = "SELECT value FROM cc_stream_setting" ." WHERE keyname = '$keyname'"; - $result = $CC_DBC->GetOne($sql); - - return $result; + $result = $con->query($sql)->fetchColumn(0); + + return $result ? $result : NULL; } - - public static function getStreamEnabled($stream_id){ - global $CC_DBC; - + + public static function getStreamEnabled($stream_id) + { + $con = Propel::getConnection(); + $keyname = "s" . $stream_id . "_enable"; $sql = "SELECT value FROM cc_stream_setting" ." WHERE keyname = '$keyname'"; - $result = $CC_DBC->GetOne($sql); + $result = $con->query($sql)->fetchColumn(0); if ($result == 'false') { $result = false; } else { @@ -236,62 +249,63 @@ class Application_Model_StreamSetting { } return $result; } - + /* * Only returns info that is needed for data collection * returns array('s1'=>array(keyname=>value)) */ - public static function getStreamInfoForDataCollection(){ - global $CC_DBC; - + public static function getStreamInfoForDataCollection() + { + $con = Propel::getConnection(); + $out = array(); $enabled_stream = self::getEnabledStreamIds(); - - foreach($enabled_stream as $stream){ + + foreach ($enabled_stream as $stream) { $keys = "'".$stream."_output', "."'".$stream."_type', "."'".$stream."_bitrate', "."'".$stream."_host'"; - + $sql = "SELECT keyname, value FROM cc_stream_setting" - ." WHERE keyname IN ($keys)"; - - $rows = $CC_DBC->getAll($sql); + ." WHERE keyname IN ($keys)"; + + $rows = $con->query($sql)->fetchAll(); $info = array(); - foreach($rows as $r){ + foreach ($rows as $r) { $temp = explode("_", $r['keyname']); $info[$temp[1]] = $r['value']; - $out[$stream] = $info; + $out[$stream] = $info; } } return $out; } - + public static function SetMasterLiveSteamPort($value){ self::SetValue("master_live_stream_port", $value, "integer"); } - + public static function GetMasterLiveSteamPort(){ return self::GetValue("master_live_stream_port"); } - + public static function SetMasterLiveSteamMountPoint($value){ self::SetValue("master_live_stream_mp", $value, "string"); } - + public static function GetMasterLiveSteamMountPoint(){ return self::GetValue("master_live_stream_mp"); } - + public static function SetDJLiveSteamPort($value){ self::SetValue("dj_live_stream_port", $value, "integer"); } - + public static function GetDJLiveSteamPort(){ return self::GetValue("dj_live_stream_port"); } - + public static function SetDJLiveSteamMountPoint($value){ self::SetValue("dj_live_stream_mp", $value, "string"); } - + public static function GetDJLiveSteamMountPoint(){ return self::GetValue("dj_live_stream_mp"); } diff --git a/airtime_mvc/application/models/Subjects.php b/airtime_mvc/application/models/Subjects.php index 59eeefff1..45c672b61 100644 --- a/airtime_mvc/application/models/Subjects.php +++ b/airtime_mvc/application/models/Subjects.php @@ -28,16 +28,15 @@ class Application_Model_Subjects { */ public static function Authenticate($login, $pass='') { - global $CC_CONFIG, $CC_DBC; + global $CC_CONFIG; + $con = Propel::getConnection(); $cpass = md5($pass); $sql = "SELECT id FROM ".$CC_CONFIG['subjTable'] - ." WHERE login='$login' AND pass='$cpass' AND type='U'"; - $id = $CC_DBC->getOne($sql); - if (PEAR::isError($id)) { - return $id; - } - return (is_null($id) ? FALSE : $id); - } // fn authenticate + ." WHERE login='$login' AND pass='$cpass' AND type='U'" + ." LIMIT 1"; + $query = $con->query($sql)->fetchColumn(0); + return $query; + } /** @@ -54,7 +53,8 @@ class Application_Model_Subjects { */ public static function Passwd($login, $oldpass=null, $pass='', $passenc=FALSE) { - global $CC_CONFIG, $CC_DBC; + global $CC_CONFIG; + $con = Propel::getConnection(); if (!$passenc) { $cpass = md5($pass); } else { @@ -68,12 +68,9 @@ class Application_Model_Subjects { } $sql = "UPDATE ".$CC_CONFIG['subjTable']." SET pass='$cpass'" ." WHERE login='$login' $oldpCond AND type='U'"; - $r = $CC_DBC->query($sql); - if (PEAR::isError($r)) { - return $r; - } + $con->exec($sql); return TRUE; - } // fn passwd + } /* --------------------------------------------------------------- groups */ @@ -84,20 +81,21 @@ class Application_Model_Subjects { * Get subject id from login * * @param string $login - * @return int|PEAR_Error + * @return int|false */ public static function GetSubjId($login) { global $CC_CONFIG; - global $CC_DBC; + $con = Propel::getConnection(); $sql = "SELECT id FROM ".$CC_CONFIG['subjTable'] ." WHERE login='$login'"; - return $CC_DBC->getOne($sql); - } // fn getSubjId + $query = $con->query($sql)->fetchColumn(0); + 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 * local user id @@ -107,47 +105,42 @@ class Application_Model_Subjects { */ public static function IsMemberOf($uid, $gid) { - global $CC_CONFIG, $CC_DBC; - $sql = "SELECT count(*)as cnt" + global $CC_CONFIG; + $con = Propel::getConnection(); + $sql = "SELECT count(*) as cnt" ." FROM ".$CC_CONFIG['smembTable'] ." WHERE uid='$uid' AND gid='$gid'"; - $res = $CC_DBC->getOne($sql); - if (PEAR::isError($res)) { - return $res; - } + $res = $con->query($sql)->fetchColumn(0); return (intval($res) > 0); - } // fn isMemberOf + } - public static function increaseLoginAttempts($login){ - global $CC_CONFIG, $CC_DBC; + public static function increaseLoginAttempts($login) + { + global $CC_CONFIG; + $con = Propel::getConnection(); $sql = "UPDATE ".$CC_CONFIG['subjTable']." SET login_attempts = login_attempts+1" ." WHERE login='$login'"; - $res = $CC_DBC->query($sql); - if (PEAR::isError($res)) { - return $res; - } + $res = $con->exec($sql); return (intval($res) > 0); } - - public static function resetLoginAttempts($login){ - global $CC_CONFIG, $CC_DBC; + + public static function resetLoginAttempts($login) + { + global $CC_CONFIG; + $con = Propel::getConnection(); $sql = "UPDATE ".$CC_CONFIG['subjTable']." SET login_attempts = '0'" ." WHERE login='$login'"; - $res = $CC_DBC->query($sql); - if (PEAR::isError($res)) { - return $res; - } - return (intval($res) > 0); + $res = $con->exec($sql); + return TRUE; } - - public static function getLoginAttempts($login){ - global $CC_CONFIG, $CC_DBC; + + public static function getLoginAttempts($login) + { + global $CC_CONFIG; + $con = Propel::getConnection(); $sql = "SELECT login_attempts FROM ".$CC_CONFIG['subjTable']." WHERE login='$login'"; - $res = $CC_DBC->getOne($sql); - if (PEAR::isError($res)) { - return $res; - } - return $res; + $res = $con->query($sql)->fetchColumn(0); + return $res ? $res : 0; } } // class Subjects diff --git a/airtime_mvc/application/models/User.php b/airtime_mvc/application/models/User.php index 5c0d701df..f09af3371 100644 --- a/airtime_mvc/application/models/User.php +++ b/airtime_mvc/application/models/User.php @@ -26,7 +26,7 @@ class Application_Model_User { public function getId() { return $this->_userInstance->getDbId(); } - + public function isGuest() { return $this->getType() == UTYPE_GUEST; } @@ -34,7 +34,7 @@ class Application_Model_User { public function isHost($showId) { return $this->isUserType(UTYPE_HOST, $showId); } - + public function isPM() { return $this->isUserType(UTYPE_PROGRAM_MANAGER); } @@ -185,15 +185,14 @@ class Application_Model_User { return $user; } - public static function getUsers($type, $search=NULL) { - global $CC_DBC; - - $sql; + public static function getUsers($type, $search=NULL) + { + $con = Propel::getConnection(); $sql_gen = "SELECT login AS value, login AS label, id as index FROM cc_subjs "; $sql = $sql_gen; - if(is_array($type)) { + if (is_array($type)) { for($i=0; $iGetAll($sql); + return $con->query($sql)->fetchAll();; } public static function getUserCount($type=NULL){ - global $CC_DBC; - - $sql; - + $con = Propel::getConnection(); + $sql = ''; $sql_gen = "SELECT count(*) AS cnt FROM cc_subjs "; - if(!isset($type)){ + if (!isset($type)) { $sql = $sql_gen; } else{ - if(is_array($type)) { - for($i=0; $iGetOne($sql); + $query = $con->query($sql)->fetchColumn(0); + return $query ? $query : NULL; } public static function getHosts($search=NULL) { @@ -248,7 +246,7 @@ class Application_Model_User { } public static function getUsersDataTablesInfo($datatables) { - + $con = Propel::getConnection(CcSubjsPeer::DATABASE_NAME); $displayColumns = array("id", "login", "first_name", "last_name", "type"); @@ -263,7 +261,7 @@ class Application_Model_User { } $res = Application_Model_Datatables::findEntries($con, $displayColumns, $fromTable, $datatables); - + // mark record which is for the current user foreach($res['aaData'] as &$record){ if($record['login'] == $username){ @@ -277,13 +275,13 @@ class Application_Model_User { } 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" ." FROM cc_subjs" ." WHERE id = $id"; - return $CC_DBC->GetRow($sql); + return $con->query($sql)->fetch(); } public static function GetUserID($login){