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");
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();

View file

@ -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);

View file

@ -5,41 +5,32 @@ class Application_Model_LoginAttempts {
}
public static function increaseAttempts($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) {
$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);
}
}
}

View file

@ -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();

View file

@ -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);
}
/**

View file

@ -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()) {
@ -27,7 +28,7 @@ class Application_Model_Preference
$sql .= " AND subjid = '$id'";
}
$result = $CC_DBC->GetOne($sql);
$result = $con->query($sql)->fetchColumn(0);
if($result == 1) {
// 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){
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 {
@ -85,8 +86,8 @@ class Application_Model_Preference
$sql .= " AND subjid = '$id'";
}
$result = $CC_DBC->GetOne($sql);
return $result;
$result = $con->query($sql)->fetchColumn(0);
return $result ? $result : "";
}
}
@ -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){

View file

@ -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 {
@ -70,18 +71,19 @@ 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 .= '(';
@ -105,8 +107,8 @@ class Application_Model_Schedule {
$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;
@ -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"],
@ -159,8 +160,8 @@ class Application_Model_Schedule {
}
public static function GetLastScheduleItem($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"
@ -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,
@ -273,24 +274,27 @@ class Application_Model_Schedule {
$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);
}
@ -409,7 +413,8 @@ 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,"
@ -435,13 +440,10 @@ class Application_Model_Schedule {
$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"));
@ -455,10 +457,7 @@ class Application_Model_Schedule {
." LIMIT 3";
$sql = $baseQuery.$predicates;
$rows = $CC_DBC->GetAll($sql);
if (PEAR::isError($rows)) {
return null;
}
$rows = $con->query($sql)->fetchAll();
}
return $rows;
@ -466,7 +465,7 @@ class Application_Model_Schedule {
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". */
@ -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){

View file

@ -113,16 +113,16 @@ 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'];
}
@ -131,18 +131,20 @@ class Application_Model_Show {
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);
}
}
@ -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,14 +1610,10 @@ 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) {
@ -1603,7 +1621,7 @@ class Application_Model_Show {
//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"]);
}
@ -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,7 +1781,7 @@ 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();
@ -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'];
}

View file

@ -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) {
@ -656,15 +655,17 @@ 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,49 +713,55 @@ 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
@ -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)
ORDER BY si.ends";
return $CC_DBC->GetAll($sql);
return $con->query($sql)->fetchAll();
}
function isRepeating(){

View file

@ -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) {
@ -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"];
}
}

View file

@ -1,19 +1,21 @@
<?php
class Application_Model_StreamSetting {
public static function SetValue($key, $value, $type){
global $CC_CONFIG, $CC_DBC;
public static function SetValue($key, $value, $type)
{
global $CC_CONFIG;
$con = Propel::getConnection();
$key = pg_escape_string($key);
$value = pg_escape_string($value);
//Check if key already exists
// Check if key already exists
$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"
." SET value = '$value', type='$type'"
." WHERE keyname = '$key'";
@ -22,115 +24,121 @@ class Application_Model_StreamSetting {
." 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'";
." WHERE keyname = '$key'";
$result = $CC_DBC->GetOne($sql);
return $result;
$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;
/* 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')";
."FROM cc_stream_setting "
."WHERE keyname IN ('output_sound_device', 'icecast_vorbis_metadata')";
$rows = $CC_DBC->getAll($sql);
$rows = $con->query($sql)->fetchAll();
$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);
$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;
@ -143,17 +151,18 @@ class Application_Model_StreamSetting {
* @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,7 +173,7 @@ 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);
@ -177,12 +186,13 @@ class Application_Model_StreamSetting {
*
* $data - data array. $data is [].
*/
public static function setIndivisualStreamSetting($data){
global $CC_DBC;
public static function setIndivisualStreamSetting($data)
{
$con = Propel::getConnection();
foreach($data as $keyname => $v){
foreach ($data as $keyname => $v) {
$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.
* 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);
$result = $con->query($sql)->fetchColumn(0);
return $result;
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 {
@ -241,21 +254,22 @@ class Application_Model_StreamSetting {
* 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)";
." WHERE keyname IN ($keys)";
$rows = $CC_DBC->getAll($sql);
$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;

View file

@ -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

View file

@ -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; $i<count($type); $i++) {
$type[$i] = "type = '{$type[$i]}'";
}
@ -205,7 +204,7 @@ class Application_Model_User {
$sql = $sql_gen ." WHERE (". $sql_type.") ";
if(!is_null($search)) {
if (!is_null($search)) {
$like = "login ILIKE '%{$search}%'";
$sql = $sql . " AND ".$like;
@ -213,22 +212,20 @@ class Application_Model_User {
$sql = $sql ." ORDER BY login";
return $CC_DBC->GetAll($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; $i<count($type); $i++) {
if (is_array($type)) {
for ($i=0; $i<count($type); $i++) {
$type[$i] = "type = '{$type[$i]}'";
}
$sql_type = join(" OR ", $type);
@ -240,7 +237,8 @@ class Application_Model_User {
$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) {
@ -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){