Merge branch 'master' of dev.sourcefabric.org:airtime
This commit is contained in:
commit
263b89295f
|
@ -1,8 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
class Application_Common_Database
|
class Application_Common_Database
|
||||||
{
|
{
|
||||||
public static function prepareAndExecute($sql, array $paramValueMap,
|
const SINGLE = 'single';
|
||||||
$type='all', $fetchType=PDO::FETCH_ASSOC, $con=null)
|
const COLUMN = 'column';
|
||||||
|
const ALL = 'all';
|
||||||
|
const EXECUTE = 'execute';
|
||||||
|
const ROW_COUNT = 'row_count';
|
||||||
|
|
||||||
|
public static function prepareAndExecute($sql,
|
||||||
|
array $paramValueMap = array(),
|
||||||
|
$type=self::ALL,
|
||||||
|
$fetchType=PDO::FETCH_ASSOC,
|
||||||
|
$con=null)
|
||||||
{
|
{
|
||||||
if (is_null($con)) {
|
if (is_null($con)) {
|
||||||
$con = Propel::getConnection();
|
$con = Propel::getConnection();
|
||||||
|
@ -13,14 +22,16 @@ class Application_Common_Database
|
||||||
}
|
}
|
||||||
$rows = array();
|
$rows = array();
|
||||||
if ($stmt->execute()) {
|
if ($stmt->execute()) {
|
||||||
if ($type == 'single') {
|
if ($type == self::SINGLE) {
|
||||||
$rows = $stmt->fetch($fetchType);
|
$rows = $stmt->fetch($fetchType);
|
||||||
} else if ($type == 'column'){
|
} else if ($type == self::COLUMN){
|
||||||
$rows = $stmt->fetchColumn();
|
$rows = $stmt->fetchColumn();
|
||||||
} else if ($type == 'all') {
|
} else if ($type == self::ALL) {
|
||||||
$rows = $stmt->fetchAll($fetchType);
|
$rows = $stmt->fetchAll($fetchType);
|
||||||
} else if ($type == 'execute') {
|
} else if ($type == self::EXECUTE) {
|
||||||
$rows = null;
|
$rows = null;
|
||||||
|
} else if ($type == self::ROW_COUNT) {
|
||||||
|
$rows = $stmt->rowCount();
|
||||||
} else {
|
} else {
|
||||||
$msg = "bad type passed: type($type)";
|
$msg = "bad type passed: type($type)";
|
||||||
throw new Exception("Error: $msg");
|
throw new Exception("Error: $msg");
|
||||||
|
|
|
@ -520,8 +520,6 @@ class ApiController extends Zend_Controller_Action
|
||||||
//File is not in database anymore.
|
//File is not in database anymore.
|
||||||
if (is_null($file)) {
|
if (is_null($file)) {
|
||||||
$return_hash['error'] = _("File does not exist in Airtime.");
|
$return_hash['error'] = _("File does not exist in Airtime.");
|
||||||
|
|
||||||
return $return_hash;
|
|
||||||
}
|
}
|
||||||
//Updating a metadata change.
|
//Updating a metadata change.
|
||||||
else {
|
else {
|
||||||
|
@ -547,8 +545,6 @@ class ApiController extends Zend_Controller_Action
|
||||||
$return_hash['error'] = _("File doesn't exist in Airtime.");
|
$return_hash['error'] = _("File doesn't exist in Airtime.");
|
||||||
Logging::warn("Attempt to delete file that doesn't exist.
|
Logging::warn("Attempt to delete file that doesn't exist.
|
||||||
Path: '$filepath'");
|
Path: '$filepath'");
|
||||||
|
|
||||||
return $return_hash;
|
|
||||||
} else {
|
} else {
|
||||||
$file->deleteByMediaMonitor();
|
$file->deleteByMediaMonitor();
|
||||||
}
|
}
|
||||||
|
@ -561,11 +557,11 @@ class ApiController extends Zend_Controller_Action
|
||||||
$file->deleteByMediaMonitor();
|
$file->deleteByMediaMonitor();
|
||||||
}
|
}
|
||||||
$return_hash['success'] = 1;
|
$return_hash['success'] = 1;
|
||||||
|
|
||||||
return $return_hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$return_hash['fileid'] = is_null($file) ? '-1' : $file->getId();
|
if (!isset($return_hash['error'])) {
|
||||||
|
$return_hash['fileid'] = is_null($file) ? '-1' : $file->getId();
|
||||||
|
}
|
||||||
$con->commit();
|
$con->commit();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Logging::warn("rolling back");
|
Logging::warn("rolling back");
|
||||||
|
|
|
@ -6,14 +6,13 @@ class Application_Model_LiveLog
|
||||||
public static function GetLiveShowDuration($p_keepData=false)
|
public static function GetLiveShowDuration($p_keepData=false)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$con = Propel::getConnection();
|
|
||||||
|
|
||||||
$sql = "SELECT * FROM CC_LIVE_LOG"
|
$sql = "SELECT * FROM CC_LIVE_LOG"
|
||||||
." WHERE state = 'L'"
|
." WHERE state = :state"
|
||||||
." and (start_time >= (now() - INTERVAL '1 day'))"
|
." and (start_time >= (now() - INTERVAL '1 day'))"
|
||||||
." ORDER BY id";
|
." ORDER BY id";
|
||||||
|
$rows = Application_Common_Database::prepareAndExecute($sql, array(':state'=>'L'),
|
||||||
$rows = $con->query($sql)->fetchAll();
|
Application_Common_Database::ALL);
|
||||||
|
|
||||||
/* Check if last log has end time.
|
/* Check if last log has end time.
|
||||||
* If not, set end time to current time
|
* If not, set end time to current time
|
||||||
|
@ -24,17 +23,19 @@ class Application_Model_LiveLog
|
||||||
$skip = false;
|
$skip = false;
|
||||||
} else {
|
} else {
|
||||||
$sql = "SELECT * FROM CC_LIVE_LOG"
|
$sql = "SELECT * FROM CC_LIVE_LOG"
|
||||||
." WHERE state = 'L'"
|
." WHERE state = :state"
|
||||||
." ORDER BY id";
|
." ORDER BY id";
|
||||||
$rows = $con->query($sql)->fetchAll();
|
$rows = Application_Common_Database::prepareAndExecute($sql, array(':state'=>'L'),
|
||||||
|
Application_Common_Database::ALL);
|
||||||
|
|
||||||
if ($rows != null) {
|
if ($rows != null) {
|
||||||
$last_row = self::UpdateLastLogEndTime(array_pop($rows));
|
$last_row = self::UpdateLastLogEndTime(array_pop($rows));
|
||||||
array_push($rows, $last_row);
|
array_push($rows, $last_row);
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
$sql_delete = "DELETE FROM CC_LIVE_LOG"
|
$sql_delete = "DELETE FROM CC_LIVE_LOG"
|
||||||
." WHERE id = '{$row['id']}'";
|
." WHERE id = :id";
|
||||||
$con->exec($sql_delete);
|
Application_Common_Database::prepareAndExecute($sql_delete, array(':id'=>$row['id']),
|
||||||
|
Application_Common_Database::EXECUTE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$skip = true;
|
$skip = true;
|
||||||
|
@ -80,8 +81,9 @@ class Application_Model_LiveLog
|
||||||
if (!$p_keepData) {
|
if (!$p_keepData) {
|
||||||
// Delete data we just used to start a new log history
|
// Delete data we just used to start a new log history
|
||||||
$sql_delete = "DELETE FROM CC_LIVE_LOG"
|
$sql_delete = "DELETE FROM CC_LIVE_LOG"
|
||||||
." WHERE id = '{$row['id']}'";
|
." WHERE id = :id";
|
||||||
$con->exec($sql_delete);
|
Application_Common_Database::prepareAndExecute($sql_delete, array(':id'=>$row['id']),
|
||||||
|
Application_Common_Database::EXECUTE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Trim milliseconds
|
//Trim milliseconds
|
||||||
|
@ -104,14 +106,14 @@ class Application_Model_LiveLog
|
||||||
public static function GetScheduledDuration($p_keepData=false)
|
public static function GetScheduledDuration($p_keepData=false)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$con = Propel::getConnection();
|
|
||||||
|
|
||||||
$sql_get_logs = "SELECT * FROM CC_LIVE_LOG"
|
$sql_get_logs = "SELECT * FROM CC_LIVE_LOG"
|
||||||
." WHERE state = 'S'"
|
." WHERE state = :state"
|
||||||
." and (start_time >= (now() - INTERVAL '1 day'))"
|
." and (start_time >= (now() - INTERVAL '1 day'))"
|
||||||
." ORDER BY id";
|
." ORDER BY id";
|
||||||
|
|
||||||
$rows = $con->query($sql_get_logs)->fetchAll();
|
$rows = Application_Common_Database::prepareAndExecute($sql_get_logs, array(':state'=>'S'),
|
||||||
|
Application_Common_Database::ALL);
|
||||||
|
|
||||||
/* Check if last log has end time.
|
/* Check if last log has end time.
|
||||||
* If not, set end time to current time
|
* If not, set end time to current time
|
||||||
|
@ -122,17 +124,19 @@ class Application_Model_LiveLog
|
||||||
$skip = false;
|
$skip = false;
|
||||||
} else {
|
} else {
|
||||||
$sql = "SELECT * FROM CC_LIVE_LOG"
|
$sql = "SELECT * FROM CC_LIVE_LOG"
|
||||||
." WHERE state = 'S'"
|
." WHERE state = :state"
|
||||||
." ORDER BY id";
|
." ORDER BY id";
|
||||||
$rows = $con->query($sql)->fetchAll();
|
$rows = Application_Common_Database::prepareAndExecute($sql, array(':state'=>'S'),
|
||||||
|
Application_Common_Database::ALL);
|
||||||
|
|
||||||
if ($rows != null) {
|
if ($rows != null) {
|
||||||
$last_row = self::UpdateLastLogEndTime(array_pop($rows));
|
$last_row = self::UpdateLastLogEndTime(array_pop($rows));
|
||||||
array_push($rows, $last_row);
|
array_push($rows, $last_row);
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
$sql_delete = "DELETE FROM CC_LIVE_LOG"
|
$sql_delete = "DELETE FROM CC_LIVE_LOG"
|
||||||
." WHERE id = '{$row['id']}'";
|
." WHERE id = :id";
|
||||||
$con->exec($sql_delete);
|
Application_Common_Database::prepareAndExecute($sql_delete, array(':id'=>$row['id']),
|
||||||
|
Application_Common_Database::EXECUTE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$skip = true;
|
$skip = true;
|
||||||
|
@ -148,11 +152,17 @@ class Application_Model_LiveLog
|
||||||
*/
|
*/
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
$sql_get_tracks = "SELECT * FROM cc_schedule"
|
$sql_get_tracks = "SELECT * FROM cc_schedule"
|
||||||
." WHERE starts >= '{$row['start_time']}'"
|
." WHERE starts >= :starts1"
|
||||||
." AND starts < '{$row['end_time']}'"
|
." AND starts < :starts2"
|
||||||
." AND file_id IS NOT NULL"
|
." AND file_id IS NOT NULL"
|
||||||
." AND media_item_played IS TRUE";
|
." AND media_item_played IS TRUE";
|
||||||
$tracks = $con->query($sql_get_tracks)->fetchAll();
|
$params = array(
|
||||||
|
':starts1'=>$row['start_time'],
|
||||||
|
':starts2'=>$row['end_time']
|
||||||
|
);
|
||||||
|
$tracks = Application_Common_Database::prepareAndExecute($sql_get_tracks, $params,
|
||||||
|
Application_Common_Database::ALL);
|
||||||
|
|
||||||
foreach ($tracks as $track) {
|
foreach ($tracks as $track) {
|
||||||
if ($track['ends'] > $row['end_time']) {
|
if ($track['ends'] > $row['end_time']) {
|
||||||
$scheduled_ends = new DateTime($row['end_time']);
|
$scheduled_ends = new DateTime($row['end_time']);
|
||||||
|
@ -237,8 +247,9 @@ class Application_Model_LiveLog
|
||||||
if (!$p_keepData) {
|
if (!$p_keepData) {
|
||||||
//Delete row because we do not need data anymore
|
//Delete row because we do not need data anymore
|
||||||
$sql_delete = "DELETE FROM CC_LIVE_LOG"
|
$sql_delete = "DELETE FROM CC_LIVE_LOG"
|
||||||
." WHERE id = '{$row['id']}'";
|
." WHERE id = :id";
|
||||||
$con->exec($sql_delete);
|
Application_Common_Database::prepareAndExecute($sql_delete, array(':id'=>$row['id']),
|
||||||
|
Application_Common_Database::EXECUTE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +286,6 @@ class Application_Model_LiveLog
|
||||||
public static function SetNewLogTime($state, $dateTime)
|
public static function SetNewLogTime($state, $dateTime)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$con = Propel::getConnection();
|
|
||||||
|
|
||||||
$scheduled = Application_Model_Preference::GetSourceSwitchStatus('scheduled_play');
|
$scheduled = Application_Model_Preference::GetSourceSwitchStatus('scheduled_play');
|
||||||
if ($state == 'L' && $scheduled == 'on') {
|
if ($state == 'L' && $scheduled == 'on') {
|
||||||
|
@ -286,13 +296,23 @@ class Application_Model_LiveLog
|
||||||
* has ended
|
* has ended
|
||||||
*/
|
*/
|
||||||
$sql_select = "SELECT max(id) from CC_LIVE_LOG"
|
$sql_select = "SELECT max(id) from CC_LIVE_LOG"
|
||||||
." WHERE (state='L' and end_time is NULL) or (state='S' and end_time is NULL)";
|
." WHERE (state= :state1 and end_time is NULL) or (state= :state2 and end_time is NULL)";
|
||||||
$id = $con->query($sql_select)->fetchColumn(0);
|
$params = array(
|
||||||
|
":state1"=> 'L',
|
||||||
|
":state2"=> 'S'
|
||||||
|
);
|
||||||
|
$id = Application_Common_Database::prepareAndExecute($sql_select, $params,
|
||||||
|
Application_Common_Database::COLUMN);
|
||||||
|
|
||||||
if ($id == null) {
|
if ($id == null) {
|
||||||
$sql_insert = "INSERT INTO CC_LIVE_LOG (state, start_time)"
|
$sql_insert = "INSERT INTO CC_LIVE_LOG (state, start_time)"
|
||||||
." VALUES ('$state', '{$dateTime->format("Y-m-d H:i:s")}')";
|
." VALUES (:state, :start)";
|
||||||
$con->exec($sql_insert);
|
$params = array(
|
||||||
|
':state'=>$state,
|
||||||
|
':start'=>$dateTime->format("Y-m-d H:i:s")
|
||||||
|
);
|
||||||
|
Application_Common_Database::prepareAndExecute($sql_insert, $params,
|
||||||
|
Application_Common_Database::EXECUTE);
|
||||||
if ($state == "S") {
|
if ($state == "S") {
|
||||||
// if scheduled play source is getting broadcasted
|
// if scheduled play source is getting broadcasted
|
||||||
Application_Model_Schedule::UpdateBrodcastedStatus($dateTime, 1);
|
Application_Model_Schedule::UpdateBrodcastedStatus($dateTime, 1);
|
||||||
|
@ -309,24 +329,28 @@ class Application_Model_LiveLog
|
||||||
public static function SetEndTime($state, $dateTime, $override=false)
|
public static function SetEndTime($state, $dateTime, $override=false)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$con = Propel::getConnection();
|
|
||||||
|
|
||||||
$dj_live = Application_Model_Preference::GetSourceSwitchStatus('live_dj');
|
$dj_live = Application_Model_Preference::GetSourceSwitchStatus('live_dj');
|
||||||
$master_live = Application_Model_Preference::GetSourceSwitchStatus('master_dj');
|
$master_live = Application_Model_Preference::GetSourceSwitchStatus('master_dj');
|
||||||
|
|
||||||
if (($dj_live=='off' && $master_live=='off') || $state == 'S' || $override) {
|
if (($dj_live=='off' && $master_live=='off') || $state == 'S' || $override) {
|
||||||
$sql = "SELECT id, state from cc_live_log"
|
$sql = "SELECT id, state from cc_live_log"
|
||||||
." where id in (select max(id) from cc_live_log)";
|
." where id in (select max(id) from cc_live_log)";
|
||||||
$row = $con->query($sql)->fetch();
|
$row = Application_Common_Database::prepareAndExecute($sql, array(),
|
||||||
|
Application_Common_Database::SINGLE);
|
||||||
|
|
||||||
/* Only set end time if state recevied ($state)
|
/* Only set end time if state recevied ($state)
|
||||||
* is the last row in cc_live_log
|
* is the last row in cc_live_log
|
||||||
*/
|
*/
|
||||||
if ($row['state'] == $state) {
|
if ($row['state'] == $state) {
|
||||||
$update_sql = "UPDATE CC_LIVE_LOG"
|
$update_sql = "UPDATE CC_LIVE_LOG"
|
||||||
." SET end_time = '{$dateTime->format("Y-m-d H:i:s")}'"
|
." SET end_time = :end"
|
||||||
." WHERE id = '{$row['id']}'";
|
." WHERE id = :id";
|
||||||
$con->exec($update_sql);
|
$params = array(
|
||||||
|
':end'=>$dateTime->format("Y-m-d H:i:s"),
|
||||||
|
':id'=>$row['id']
|
||||||
|
);
|
||||||
|
Application_Common_Database::prepareAndExecute($update_sql, $params,
|
||||||
|
Application_Common_Database::EXECUTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//If live broadcasting is off, turn scheduled play on
|
//If live broadcasting is off, turn scheduled play on
|
||||||
|
|
|
@ -6,7 +6,7 @@ class Application_Model_Locale
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
$con = Propel::getConnection();
|
||||||
$sql = "SELECT * FROM cc_locale";
|
$sql = "SELECT * FROM cc_locale";
|
||||||
$res = $con->query($sql)->fetchAll();
|
$res = Application_Common_Database::prepareAndExecute($sql);
|
||||||
$out = array();
|
$out = array();
|
||||||
foreach ($res as $r) {
|
foreach ($res as $r) {
|
||||||
$out[$r["locale_code"]] = $r["locale_lang"];
|
$out[$r["locale_code"]] = $r["locale_lang"];
|
||||||
|
|
|
@ -7,35 +7,32 @@ class Application_Model_LoginAttempts
|
||||||
|
|
||||||
public static function increaseAttempts($ip)
|
public static function increaseAttempts($ip)
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
$sql = "select count(*) from cc_login_attempts WHERE ip= :ip";
|
||||||
$sql = "select count(*) from cc_login_attempts WHERE ip='$ip'";
|
$res = Application_Common_Database::prepareAndExecute($sql, array(':ip'=>$ip), Application_Common_Database::ALL);
|
||||||
$res = $con->query($sql)->fetchColumn(0);
|
|
||||||
if ($res) {
|
if ($res) {
|
||||||
$sql = "UPDATE cc_login_attempts SET attempts=attempts+1 WHERE ip='$ip'";
|
$sql = "UPDATE cc_login_attempts SET attempts=attempts+1 WHERE ip= :ip";
|
||||||
$con->exec($sql);
|
Application_Common_Database::prepareAndExecute($sql, array(':ip'=>$ip), Application_Common_Database::EXECUTE);
|
||||||
} else {
|
} else {
|
||||||
$sql = "INSERT INTO cc_login_attempts (ip, attempts) values ('$ip', '1')";
|
$sql = "INSERT INTO cc_login_attempts (ip, attempts) values (':ip', '1')";
|
||||||
$con->exec($sql);
|
Application_Common_Database::prepareAndExecute($sql, array(':ip'=>$ip), Application_Common_Database::EXECUTE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAttempts($ip)
|
public static function getAttempts($ip)
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
$sql = "select attempts from cc_login_attempts WHERE ip= :ip";
|
||||||
$sql = "select attempts from cc_login_attempts WHERE ip='$ip'";
|
$res = Application_Common_Database::prepareAndExecute($sql, array(':ip'=>$ip), Application_Common_Database::ALL);
|
||||||
$res = $con->query($sql)->fetchColumn(0);
|
|
||||||
|
|
||||||
return $res ? $res : 0;
|
return $res ? $res : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function resetAttempts($ip)
|
public static function resetAttempts($ip)
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
$sql = "select count(*) from cc_login_attempts WHERE ip= :ip";
|
||||||
$sql = "select count(*) from cc_login_attempts WHERE ip='$ip'";
|
$res = Application_Common_Database::prepareAndExecute($sql, array(':ip'=>$ip), Application_Common_Database::COLUMN);
|
||||||
$res = $con->query($sql)->fetchColumn(0);
|
|
||||||
if ($res > 0) {
|
if ($res > 0) {
|
||||||
$sql = "DELETE FROM cc_login_attempts WHERE ip='$ip'";
|
$sql = "DELETE FROM cc_login_attempts WHERE ip= :ip";
|
||||||
$con->exec($sql);
|
Application_Common_Database::prepareAndExecute($sql, array(':ip'=>$ip), Application_Common_Database::EXECUTE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -936,10 +936,10 @@ SQL;
|
||||||
|
|
||||||
public static function getPlaylistCount()
|
public static function getPlaylistCount()
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
|
||||||
$sql = 'SELECT count(*) as cnt FROM cc_playlist';
|
$sql = 'SELECT count(*) as cnt FROM cc_playlist';
|
||||||
|
|
||||||
return $con->query($sql)->fetchColumn(0);
|
return Application_Common_Database::prepareAndExecute($sql, array(),
|
||||||
|
Application_Common_Database::COLUMN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1063,13 +1063,12 @@ SQL;
|
||||||
|
|
||||||
public static function getAllPlaylistFiles()
|
public static function getAllPlaylistFiles()
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
|
||||||
$sql = <<<SQL
|
$sql = <<<SQL
|
||||||
SELECT distinct(file_id)
|
SELECT distinct(file_id)
|
||||||
FROM cc_playlistcontents
|
FROM cc_playlistcontents
|
||||||
WHERE file_id is not null
|
WHERE file_id is not null
|
||||||
SQL;
|
SQL;
|
||||||
$files = $con->query($sql)->fetchAll();
|
$files = Application_Common_Database::prepareAndExecute($sql);
|
||||||
$real_files = array();
|
$real_files = array();
|
||||||
foreach ($files as $f) {
|
foreach ($files as $f) {
|
||||||
$real_files[] = $f['file_id'];
|
$real_files[] = $f['file_id'];
|
||||||
|
@ -1079,13 +1078,12 @@ SQL;
|
||||||
|
|
||||||
public static function getAllPlaylistStreams()
|
public static function getAllPlaylistStreams()
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
|
||||||
$sql = <<<SQL
|
$sql = <<<SQL
|
||||||
SELECT distinct(stream_id)
|
SELECT distinct(stream_id)
|
||||||
FROM cc_playlistcontents
|
FROM cc_playlistcontents
|
||||||
WHERE stream_id is not null
|
WHERE stream_id is not null
|
||||||
SQL;
|
SQL;
|
||||||
$streams = $con->query($sql)->fetchAll();
|
$streams = Application_Common_Database::prepareAndExecute($sql);
|
||||||
$real_streams = array();
|
$real_streams = array();
|
||||||
foreach ($streams as $s) {
|
foreach ($streams as $s) {
|
||||||
$real_streams[] = $s['stream_id'];
|
$real_streams[] = $s['stream_id'];
|
||||||
|
|
|
@ -418,7 +418,6 @@ SQL;
|
||||||
|
|
||||||
public static function UpdateMediaPlayedStatus($p_id)
|
public static function UpdateMediaPlayedStatus($p_id)
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
|
||||||
$sql = "UPDATE cc_schedule"
|
$sql = "UPDATE cc_schedule"
|
||||||
." SET media_item_played=TRUE";
|
." SET media_item_played=TRUE";
|
||||||
// we need to update 'broadcasted' column as well
|
// we need to update 'broadcasted' column as well
|
||||||
|
@ -431,11 +430,11 @@ SQL;
|
||||||
$sql .= ", broadcasted=1";
|
$sql .= ", broadcasted=1";
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= " WHERE id=$p_id";
|
$sql .= " WHERE id=:pid";
|
||||||
|
$map = array(":pid" => $p_id);
|
||||||
|
|
||||||
$retVal = $con->exec($sql);
|
Application_Common_Database::prepareAndExecute($sql, $map,
|
||||||
|
Application_Common_Database::EXECUTE);
|
||||||
return $retVal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function UpdateBrodcastedStatus($dateTime, $value)
|
public static function UpdateBrodcastedStatus($dateTime, $value)
|
||||||
|
@ -952,8 +951,9 @@ SQL;
|
||||||
|
|
||||||
public static function deleteAll()
|
public static function deleteAll()
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
$sql = "TRUNCATE TABLE cc_schedule";
|
||||||
$con->exec("TRUNCATE TABLE cc_schedule");
|
Application_Common_Database::prepareAndExecute($sql, array(),
|
||||||
|
Application_Common_Database::EXECUTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function deleteWithFileId($fileId)
|
public static function deleteWithFileId($fileId)
|
||||||
|
|
|
@ -602,8 +602,6 @@ SQL;
|
||||||
Application_Common_Database::prepareAndExecute( $sql,
|
Application_Common_Database::prepareAndExecute( $sql,
|
||||||
array( ':showId' => $this->getId(),
|
array( ':showId' => $this->getId(),
|
||||||
':timestamp' => gmdate("Y-m-d H:i:s")), 'execute');
|
':timestamp' => gmdate("Y-m-d H:i:s")), 'execute');
|
||||||
|
|
||||||
$con->exec($sql);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -617,8 +615,6 @@ SQL;
|
||||||
*/
|
*/
|
||||||
public function removeAllInstancesFromDate($p_date=null)
|
public function removeAllInstancesFromDate($p_date=null)
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
|
||||||
|
|
||||||
$timestamp = gmdate("Y-m-d H:i:s");
|
$timestamp = gmdate("Y-m-d H:i:s");
|
||||||
|
|
||||||
if (is_null($p_date)) {
|
if (is_null($p_date)) {
|
||||||
|
@ -628,12 +624,16 @@ SQL;
|
||||||
|
|
||||||
$showId = $this->getId();
|
$showId = $this->getId();
|
||||||
$sql = "DELETE FROM cc_show_instances "
|
$sql = "DELETE FROM cc_show_instances "
|
||||||
." WHERE date(starts) >= DATE '$p_date'"
|
." WHERE date(starts) >= :date::date"
|
||||||
." AND starts > TIMESTAMP '$timestamp'"
|
." AND starts > :timestamp::timestamp"
|
||||||
." AND show_id = $showId";
|
." AND show_id = :showId";
|
||||||
|
|
||||||
$con->exec($sql);
|
$map = array(":date"=>$p_date,
|
||||||
|
':timestamp'=>$timestamp,
|
||||||
|
':showId'=>$showId);
|
||||||
|
|
||||||
|
$res = Application_Common_Database::prepareAndExecute($sql, $map,
|
||||||
|
Application_Common_Database::EXECUTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -650,17 +650,20 @@ SQL;
|
||||||
*/
|
*/
|
||||||
public function removeAllInstancesBeforeDate($p_date)
|
public function removeAllInstancesBeforeDate($p_date)
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
|
||||||
|
|
||||||
$timestamp = gmdate("Y-m-d H:i:s");
|
$timestamp = gmdate("Y-m-d H:i:s");
|
||||||
|
|
||||||
$showId = $this->getId();
|
$showId = $this->getId();
|
||||||
$sql = "DELETE FROM cc_show_instances "
|
$sql = "DELETE FROM cc_show_instances "
|
||||||
." WHERE date(starts) < DATE '$p_date'"
|
." WHERE date(starts) < :date::date"
|
||||||
." AND starts > TIMESTAMP '$timestamp'"
|
." AND starts > :timestamp::timestamp"
|
||||||
." AND show_id = $showId";
|
." AND show_id = :showId";
|
||||||
|
|
||||||
$con->exec($sql);
|
$map = array(":date"=>$p_date,
|
||||||
|
":timestamp"=>$timestamp,
|
||||||
|
":showId"=>$showId);
|
||||||
|
|
||||||
|
$res = Application_Common_Database::prepareAndExecute($sql, $map,
|
||||||
|
Application_Common_Database::EXECUTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNextFutureRepeatShowTime()
|
public function getNextFutureRepeatShowTime()
|
||||||
|
@ -870,43 +873,62 @@ SQL;
|
||||||
|
|
||||||
private function updateStartDateTime($p_data, $p_endDate)
|
private function updateStartDateTime($p_data, $p_endDate)
|
||||||
{
|
{
|
||||||
//need to update cc_schedule, cc_show_instances, cc_show_days
|
|
||||||
$con = Propel::getConnection();
|
|
||||||
|
|
||||||
$date = new Application_Common_DateHelper;
|
$date = new Application_Common_DateHelper;
|
||||||
$timestamp = $date->getTimestamp();
|
$timestamp = $date->getTimestamp();
|
||||||
|
|
||||||
//TODO fix this from overwriting info.
|
//TODO fix this from overwriting info.
|
||||||
$sql = "UPDATE cc_show_days "
|
$sql = "UPDATE cc_show_days "
|
||||||
."SET start_time = TIME '$p_data[add_show_start_time]', "
|
."SET start_time = :start_time::time, "
|
||||||
."first_show = DATE '$p_data[add_show_start_date]', ";
|
."first_show = :start_date::date, ";
|
||||||
if (strlen ($p_endDate) == 0) {
|
if (strlen ($p_endDate) == 0) {
|
||||||
$sql .= "last_show = NULL ";
|
$sql .= "last_show = NULL ";
|
||||||
} else {
|
} else {
|
||||||
$sql .= "last_show = DATE '$p_endDate' ";
|
$sql .= "last_show = :end_date::date";
|
||||||
}
|
}
|
||||||
$sql .= "WHERE show_id = $p_data[add_show_id]";
|
$sql .= "WHERE show_id = :show_id";
|
||||||
$con->exec($sql);
|
|
||||||
|
$map = array(":start_time" => $p_data['add_show_start_time'],
|
||||||
|
':start_date' => $p_data['add_show_start_date'],
|
||||||
|
':end_date' => $p_endDate,
|
||||||
|
':show_id' => $p_data['add_show_id'],
|
||||||
|
);
|
||||||
|
|
||||||
|
$res = Application_Common_Database::prepareAndExecute($sql, $map,
|
||||||
|
Application_Common_Database::EXECUTE);
|
||||||
|
|
||||||
$dtOld = new DateTime($this->getStartDate()." ".$this->getStartTime(), new DateTimeZone("UTC"));
|
$dtOld = new DateTime($this->getStartDate()." ".$this->getStartTime(), new DateTimeZone("UTC"));
|
||||||
$dtNew = new DateTime($p_data['add_show_start_date']." ".$p_data['add_show_start_time'], new DateTimeZone(date_default_timezone_get()));
|
$dtNew = new DateTime($p_data['add_show_start_date']." ".$p_data['add_show_start_time'],
|
||||||
|
new DateTimeZone(date_default_timezone_get()));
|
||||||
$diff = $dtOld->getTimestamp() - $dtNew->getTimestamp();
|
$diff = $dtOld->getTimestamp() - $dtNew->getTimestamp();
|
||||||
|
|
||||||
$sql = "UPDATE cc_show_instances "
|
$sql = "UPDATE cc_show_instances "
|
||||||
."SET starts = starts + INTERVAL '$diff sec', "
|
."SET starts = starts + :diff1::interval, "
|
||||||
."ends = ends + INTERVAL '$diff sec' "
|
."ends = ends + :diff2::interval "
|
||||||
."WHERE show_id = $p_data[add_show_id] "
|
."WHERE show_id = :show_id "
|
||||||
."AND starts > TIMESTAMP '$timestamp'";
|
."AND starts > :timestamp::timestamp";
|
||||||
$con->exec($sql);
|
$map = array(
|
||||||
|
":diff1"=>"$diff sec",
|
||||||
|
":diff2"=>"$diff sec",
|
||||||
|
":show_id"=>$p_data['add_show_id'],
|
||||||
|
":timestamp"=>$timestamp,
|
||||||
|
);
|
||||||
|
$res = Application_Common_Database::prepareAndExecute($sql, $map,
|
||||||
|
Application_Common_Database::EXECUTE);
|
||||||
|
|
||||||
$showInstanceIds = $this->getAllFutureInstanceIds();
|
$showInstanceIds = $this->getAllFutureInstanceIds();
|
||||||
if (count($showInstanceIds) > 0 && $diff != 0) {
|
if (count($showInstanceIds) > 0 && $diff != 0) {
|
||||||
$showIdsImploded = implode(",", $showInstanceIds);
|
$showIdsImploded = implode(",", $showInstanceIds);
|
||||||
$sql = "UPDATE cc_schedule "
|
$sql = "UPDATE cc_schedule "
|
||||||
."SET starts = starts + INTERVAL '$diff sec', "
|
."SET starts = starts + :diff1::interval, "
|
||||||
."ends = ends + INTERVAL '$diff sec' "
|
."ends = ends + :diff2::interval "
|
||||||
."WHERE instance_id IN ($showIdsImploded)";
|
."WHERE instance_id IN (:show_ids)";
|
||||||
$con->exec($sql);
|
$map = array(
|
||||||
|
":diff1"=>"$diff sec",
|
||||||
|
":diff2"=>"$diff sec",
|
||||||
|
":show_ids"=>$showIdsImploded,
|
||||||
|
);
|
||||||
|
$res = Application_Common_Database::prepareAndExecute($sql, $map,
|
||||||
|
Application_Common_Database::EXECUTE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2199,12 +2221,11 @@ SQL;
|
||||||
|
|
||||||
public static function getMaxLengths()
|
public static function getMaxLengths()
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
|
||||||
$sql = <<<SQL
|
$sql = <<<SQL
|
||||||
SELECT column_name, character_maximum_length FROM information_schema.columns
|
SELECT column_name, character_maximum_length FROM information_schema.columns
|
||||||
WHERE table_name = 'cc_show' AND character_maximum_length > 0
|
WHERE table_name = 'cc_show' AND character_maximum_length > 0
|
||||||
SQL;
|
SQL;
|
||||||
$result = $con->query($sql)->fetchAll();
|
$result = Application_Common_Database::prepareAndExecute($sql);
|
||||||
$assocArray = array();
|
$assocArray = array();
|
||||||
foreach ($result as $row) {
|
foreach ($result as $row) {
|
||||||
$assocArray[$row['column_name']] = $row['character_maximum_length'];
|
$assocArray[$row['column_name']] = $row['character_maximum_length'];
|
||||||
|
|
|
@ -151,9 +151,6 @@ class Application_Model_StoredFile
|
||||||
}
|
}
|
||||||
$dbMd[constant($mdConst)] = $mdValue;
|
$dbMd[constant($mdConst)] = $mdValue;
|
||||||
|
|
||||||
} else {
|
|
||||||
Logging::warn("using metadata that is not defined.
|
|
||||||
[$mdConst] => [$mdValue]");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->setDbColMetadata($dbMd);
|
$this->setDbColMetadata($dbMd);
|
||||||
|
@ -1063,9 +1060,9 @@ SQL;
|
||||||
|
|
||||||
public static function getFileCount()
|
public static function getFileCount()
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
|
||||||
$sql = "SELECT count(*) as cnt FROM cc_files WHERE file_exists";
|
$sql = "SELECT count(*) as cnt FROM cc_files WHERE file_exists";
|
||||||
return $con->query($sql)->fetchColumn(0);
|
return Application_Common_Database::prepareAndExecute($sql, array(),
|
||||||
|
Application_Common_Database::COLUMN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1167,7 +1164,6 @@ SQL;
|
||||||
public static function getSoundCloudUploads()
|
public static function getSoundCloudUploads()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$con = Propel::getConnection();
|
|
||||||
|
|
||||||
$sql = <<<SQL
|
$sql = <<<SQL
|
||||||
SELECT soundcloud_id AS id,
|
SELECT soundcloud_id AS id,
|
||||||
|
@ -1178,7 +1174,7 @@ WHERE (id != -2
|
||||||
AND (soundcloud_upload_time >= (now() - (INTERVAL '1 day')))
|
AND (soundcloud_upload_time >= (now() - (INTERVAL '1 day')))
|
||||||
SQL;
|
SQL;
|
||||||
|
|
||||||
$rows = $con->query($sql)->fetchAll();
|
$rows = Application_Common_Database::prepareAndExecute($sql);
|
||||||
|
|
||||||
return count($rows);
|
return count($rows);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
@ -1349,12 +1345,12 @@ SQL;
|
||||||
|
|
||||||
public static function updatePastFilesIsScheduled()
|
public static function updatePastFilesIsScheduled()
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
|
||||||
$sql = <<<SQL
|
$sql = <<<SQL
|
||||||
SELECT file_id FROM cc_schedule
|
SELECT file_id FROM cc_schedule
|
||||||
WHERE ends < now() at time zone 'UTC'
|
WHERE ends < now() at time zone 'UTC'
|
||||||
SQL;
|
SQL;
|
||||||
$files = $con->query($sql)->fetchAll();
|
$files = Application_Common_Database::prepareAndExecute($sql);
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
if (!is_null($file['file_id'])) {
|
if (!is_null($file['file_id'])) {
|
||||||
self::setIsScheduled(null, false, $file['file_id']);
|
self::setIsScheduled(null, false, $file['file_id']);
|
||||||
|
|
|
@ -265,11 +265,12 @@ class Application_Model_StreamSetting
|
||||||
*/
|
*/
|
||||||
public static function setIndividualStreamSetting($data)
|
public static function setIndividualStreamSetting($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'";
|
$sql = "UPDATE cc_stream_setting SET value=:v WHERE keyname=:keyname";
|
||||||
$con->exec($sql);
|
$map = array(":v" => $v, ":keyname"=>$keyname);
|
||||||
|
|
||||||
|
$res = Application_Common_Database::prepareAndExecute($sql, $map,
|
||||||
|
Application_Common_Database::EXECUTE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,20 +20,25 @@ class Application_Model_Subjects
|
||||||
|
|
||||||
public static function increaseLoginAttempts($login)
|
public static function increaseLoginAttempts($login)
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
|
||||||
$sql = "UPDATE cc_subjs SET login_attempts = login_attempts+1"
|
$sql = "UPDATE cc_subjs SET login_attempts = login_attempts+1"
|
||||||
." WHERE login='$login'";
|
." WHERE login=:login";
|
||||||
$res = $con->exec($sql);
|
|
||||||
|
$map = array(":login" => $login);
|
||||||
|
|
||||||
|
$res = Application_Common_Database::prepareAndExecute($sql, $map,
|
||||||
|
Application_Common_Database::EXECUTE);
|
||||||
|
|
||||||
return (intval($res) > 0);
|
return (intval($res) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function resetLoginAttempts($login)
|
public static function resetLoginAttempts($login)
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
|
||||||
$sql = "UPDATE cc_subjs SET login_attempts = '0'"
|
$sql = "UPDATE cc_subjs SET login_attempts = '0'"
|
||||||
." WHERE login='$login'";
|
." WHERE login=:login";
|
||||||
$res = $con->exec($sql);
|
$map = array(":login" => $login);
|
||||||
|
|
||||||
|
$res = Application_Common_Database::prepareAndExecute($sql, $map,
|
||||||
|
Application_Common_Database::EXECUTE);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -297,10 +297,10 @@ class Application_Model_User
|
||||||
|
|
||||||
public static function getUserCount()
|
public static function getUserCount()
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
|
||||||
$sql_gen = "SELECT count(*) AS cnt FROM cc_subjs";
|
$sql_gen = "SELECT count(*) AS cnt FROM cc_subjs";
|
||||||
|
|
||||||
$query = $con->query($sql_gen)->fetchColumn(0);
|
$query = Application_Common_Database::prepareAndExecute($sql_gen, array(),
|
||||||
|
Application_Common_Database::COLUMN);
|
||||||
|
|
||||||
return ($query !== false) ? $query : null;
|
return ($query !== false) ? $query : null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue