Merge branch 'devel' of dev.sourcefabric.org:airtime into devel
This commit is contained in:
commit
1c736d6366
|
@ -366,56 +366,56 @@ class Application_Common_DateHelper
|
|||
return $retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is used for calculations! Don't modify for display purposes!
|
||||
*
|
||||
* Convert playlist time value to float seconds
|
||||
*
|
||||
* @param string $plt
|
||||
* playlist interval value (HH:mm:ss.dddddd)
|
||||
* @return int
|
||||
* seconds
|
||||
*/
|
||||
public static function playlistTimeToSeconds($plt)
|
||||
{
|
||||
$arr = preg_split('/:/', $plt);
|
||||
if (isset($arr[2])) {
|
||||
return (intval($arr[0])*60 + intval($arr[1]))*60 + floatval($arr[2]);
|
||||
}
|
||||
if (isset($arr[1])) {
|
||||
return intval($arr[0])*60 + floatval($arr[1]);
|
||||
}
|
||||
|
||||
return floatval($arr[0]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function is used for calculations! Don't modify for display purposes!
|
||||
*
|
||||
* Convert float seconds value to playlist time format
|
||||
*
|
||||
* @param float $seconds
|
||||
* @return string
|
||||
* interval in playlist time format (HH:mm:ss.d)
|
||||
*/
|
||||
public static function secondsToPlaylistTime($p_seconds)
|
||||
{
|
||||
$info = explode('.', $p_seconds);
|
||||
$seconds = $info[0];
|
||||
if (!isset($info[1])) {
|
||||
$milliStr = 0;
|
||||
} else {
|
||||
$milliStr = $info[1];
|
||||
}
|
||||
$hours = floor($seconds / 3600);
|
||||
$seconds -= $hours * 3600;
|
||||
$minutes = floor($seconds / 60);
|
||||
$seconds -= $minutes * 60;
|
||||
|
||||
$res = sprintf("%02d:%02d:%02d.%s", $hours, $minutes, $seconds, $milliStr);
|
||||
|
||||
return $res;
|
||||
/**
|
||||
* This function is used for calculations! Don't modify for display purposes!
|
||||
*
|
||||
* Convert playlist time value to float seconds
|
||||
*
|
||||
* @param string $plt
|
||||
* playlist interval value (HH:mm:ss.dddddd)
|
||||
* @return int
|
||||
* seconds
|
||||
*/
|
||||
public static function playlistTimeToSeconds($plt)
|
||||
{
|
||||
$arr = preg_split('/:/', $plt);
|
||||
if (isset($arr[2])) {
|
||||
return (intval($arr[0])*60 + intval($arr[1]))*60 + floatval($arr[2]);
|
||||
}
|
||||
if (isset($arr[1])) {
|
||||
return intval($arr[0])*60 + floatval($arr[1]);
|
||||
}
|
||||
|
||||
return floatval($arr[0]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function is used for calculations! Don't modify for display purposes!
|
||||
*
|
||||
* Convert float seconds value to playlist time format
|
||||
*
|
||||
* @param float $seconds
|
||||
* @return string
|
||||
* interval in playlist time format (HH:mm:ss.d)
|
||||
*/
|
||||
public static function secondsToPlaylistTime($p_seconds)
|
||||
{
|
||||
$info = explode('.', $p_seconds);
|
||||
$seconds = $info[0];
|
||||
if (!isset($info[1])) {
|
||||
$milliStr = 0;
|
||||
} else {
|
||||
$milliStr = $info[1];
|
||||
}
|
||||
$hours = floor($seconds / 3600);
|
||||
$seconds -= $hours * 3600;
|
||||
$minutes = floor($seconds / 60);
|
||||
$seconds -= $minutes * 60;
|
||||
|
||||
$res = sprintf("%02d:%02d:%02d.%s", $hours, $minutes, $seconds, $milliStr);
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,12 @@ class ApiController extends Zend_Controller_Action
|
|||
|
||||
public function init()
|
||||
{
|
||||
$this->checkAuth();
|
||||
$ignoreAuth = array("live-info", "week-info");
|
||||
|
||||
$params = $this->getRequest()->getParams();
|
||||
if (!in_array($params['action'], $ignoreAuth)) {
|
||||
$this->checkAuth();
|
||||
}
|
||||
/* Initialize action controller here */
|
||||
$context = $this->_helper->getHelper('contextSwitch');
|
||||
$context->addActionContext('version' , 'json')
|
||||
|
@ -41,7 +46,6 @@ class ApiController extends Zend_Controller_Action
|
|||
public function checkAuth()
|
||||
{
|
||||
global $CC_CONFIG;
|
||||
|
||||
$api_key = $this->_getParam('api_key');
|
||||
|
||||
if (!in_array($api_key, $CC_CONFIG["apiKey"]) &&
|
||||
|
@ -298,7 +302,7 @@ class ApiController extends Zend_Controller_Action
|
|||
$result = array();
|
||||
for ($i=0; $i<7; $i++) {
|
||||
$utcDayEnd = Application_Common_DateHelper::GetDayEndTimestamp($utcDayStart);
|
||||
$shows = Application_Model_Show::getNextShows($utcDayStart, "0", $utcDayEnd);
|
||||
$shows = Application_Model_Show::getNextShows($utcDayStart, "ALL", $utcDayEnd);
|
||||
$utcDayStart = $utcDayEnd;
|
||||
|
||||
Application_Model_Show::convertToLocalTimeZone($shows,
|
||||
|
@ -307,9 +311,10 @@ class ApiController extends Zend_Controller_Action
|
|||
|
||||
$result[$dow[$i]] = $shows;
|
||||
}
|
||||
$result['AIRTIME_API_VERSION'] = AIRTIME_API_VERSION; //used by caller to determine if the airtime they are running or widgets in use is out of date.
|
||||
|
||||
//used by caller to determine if the airtime they are running or widgets in use is out of date.
|
||||
$result['AIRTIME_API_VERSION'] = AIRTIME_API_VERSION;
|
||||
header("Content-type: text/javascript");
|
||||
Logging::info($result);
|
||||
// If a callback is not given, then just provide the raw JSON.
|
||||
echo isset($_GET['callback']) ? $_GET['callback'].'('.json_encode($result).')' : json_encode($result);
|
||||
} else {
|
||||
|
|
|
@ -2060,8 +2060,6 @@ SQL;
|
|||
// been specified
|
||||
if ($timeEnd == "") {
|
||||
$timeEnd = "'$timeStart' + INTERVAL '2 days'";
|
||||
} else {
|
||||
$timeEnd = "'$timeEnd'";
|
||||
}
|
||||
|
||||
//TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin
|
||||
|
@ -2083,12 +2081,24 @@ WHERE si.show_id = s.id
|
|||
AND si.starts < :timeEnd::timestamp
|
||||
AND modified_instance != TRUE
|
||||
ORDER BY si.starts
|
||||
LIMIT :lim
|
||||
SQL;
|
||||
return Application_Common_Database::prepareAndExecute( $sql, array(
|
||||
|
||||
//PDO won't accept "ALL" as a limit value (complains it is not an
|
||||
//integer, and so we must completely remove the limit clause if we
|
||||
//want to show all results - MK
|
||||
if ($limit != "ALL") {
|
||||
$sql .= PHP_EOL."LIMIT :lim";
|
||||
$params = array(
|
||||
':timeStart' => $timeStart,
|
||||
':timeEnd' => $timeEnd,
|
||||
':lim' => $limit), 'all');
|
||||
':lim' => $limit);
|
||||
} else {
|
||||
$params = array(
|
||||
':timeStart' => $timeStart,
|
||||
':timeEnd' => $timeEnd);
|
||||
}
|
||||
|
||||
return Application_Common_Database::prepareAndExecute( $sql, $params, 'all');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -407,11 +407,12 @@ SQL;
|
|||
*/
|
||||
public function getFileExtension()
|
||||
{
|
||||
return "";
|
||||
// TODO : what's the point of having this function? Can we not just use
|
||||
// the extension from the file_path column from cc_files?
|
||||
$mime = $this->_file->getDbMime();
|
||||
|
||||
if ($mime == "audio/vorbis" || $mime == "application/ogg") {
|
||||
if ($mime == "audio/ogg" || $mime == "application/ogg") {
|
||||
return "ogg";
|
||||
} elseif ($mime == "audio/mp3" || $mime == "audio/mpeg") {
|
||||
return "mp3";
|
||||
|
@ -505,8 +506,6 @@ SQL;
|
|||
*/
|
||||
public function getRelativeFileUrl($baseUrl)
|
||||
{
|
||||
Logging::info("getting media!");
|
||||
|
||||
return $baseUrl."/api/get-media/file/".$this->getId().".".$this->getFileExtension();
|
||||
}
|
||||
|
||||
|
|
|
@ -106,12 +106,12 @@ class Application_Model_StreamSetting
|
|||
public static function getStreamData($p_streamId)
|
||||
{
|
||||
$con = Propel::getConnection();
|
||||
$streamId = pg_escape_string($p_streamId);
|
||||
$sql = "SELECT * "
|
||||
."FROM cc_stream_setting "
|
||||
."WHERE keyname LIKE :stream_id";
|
||||
."WHERE keyname LIKE '{$streamId}_%'";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindParam(':stream_id', "${p_streamId}_%");
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$rows = $stmt->fetchAll();
|
||||
|
|
|
@ -14,82 +14,82 @@
|
|||
* @package propel.generator.airtime
|
||||
*/
|
||||
class CcBlockcontents extends BaseCcBlockcontents {
|
||||
/**
|
||||
* Get the [optionally formatted] temporal [fadein] column value.
|
||||
*
|
||||
* @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
|
||||
* @throws PropelException - if unable to parse/validate the date/time value.
|
||||
*/
|
||||
public function getDbFadein($format = "s.u")
|
||||
{
|
||||
return parent::getDbFadein($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [optionally formatted] temporal [fadein] column value.
|
||||
*
|
||||
* @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
|
||||
* @throws PropelException - if unable to parse/validate the date/time value.
|
||||
*/
|
||||
public function getDbFadeout($format = "s.u")
|
||||
{
|
||||
return parent::getDbFadeout($format);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param String in format SS.uuuuuu, Datetime, or DateTime accepted string.
|
||||
*
|
||||
* @return CcBlockcontents The current object (for fluent API support)
|
||||
*/
|
||||
public function setDbFadein($v)
|
||||
{
|
||||
if ($v instanceof DateTime) {
|
||||
$dt = $v;
|
||||
}
|
||||
else if (preg_match('/^[0-9]{1,2}(\.\d{1,6})?$/', $v)) {
|
||||
$dt = DateTime::createFromFormat("s.u", $v);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
$dt = new DateTime($v);
|
||||
} catch (Exception $x) {
|
||||
throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
|
||||
}
|
||||
}
|
||||
|
||||
$this->fadein = $dt->format('H:i:s.u');
|
||||
$this->modifiedColumns[] = CcBlockcontentsPeer::FADEIN;
|
||||
|
||||
return $this;
|
||||
} // setDbFadein()
|
||||
|
||||
/**
|
||||
*
|
||||
* @param String in format SS.uuuuuu, Datetime, or DateTime accepted string.
|
||||
*
|
||||
* @return CcBlockcontents The current object (for fluent API support)
|
||||
*/
|
||||
public function setDbFadeout($v)
|
||||
{
|
||||
if ($v instanceof DateTime) {
|
||||
$dt = $v;
|
||||
}
|
||||
else if (preg_match('/^[0-9]{1,2}(\.\d{1,6})?$/', $v)) {
|
||||
$dt = DateTime::createFromFormat("s.u", $v);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
$dt = new DateTime($v);
|
||||
} catch (Exception $x) {
|
||||
throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
|
||||
}
|
||||
}
|
||||
|
||||
$this->fadeout = $dt->format('H:i:s.u');
|
||||
$this->modifiedColumns[] = CcBlockcontentsPeer::FADEOUT;
|
||||
|
||||
return $this;
|
||||
/**
|
||||
* Get the [optionally formatted] temporal [fadein] column value.
|
||||
*
|
||||
* @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
|
||||
* @throws PropelException - if unable to parse/validate the date/time value.
|
||||
*/
|
||||
public function getDbFadein($format = "s.u")
|
||||
{
|
||||
return parent::getDbFadein($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [optionally formatted] temporal [fadein] column value.
|
||||
*
|
||||
* @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
|
||||
* @throws PropelException - if unable to parse/validate the date/time value.
|
||||
*/
|
||||
public function getDbFadeout($format = "s.u")
|
||||
{
|
||||
return parent::getDbFadeout($format);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param String in format SS.uuuuuu, Datetime, or DateTime accepted string.
|
||||
*
|
||||
* @return CcBlockcontents The current object (for fluent API support)
|
||||
*/
|
||||
public function setDbFadein($v)
|
||||
{
|
||||
if ($v instanceof DateTime) {
|
||||
$dt = $v;
|
||||
}
|
||||
else if (preg_match('/^[0-9]{1,2}(\.\d{1,6})?$/', $v)) {
|
||||
$dt = DateTime::createFromFormat("s.u", $v);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
$dt = new DateTime($v);
|
||||
} catch (Exception $x) {
|
||||
throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
|
||||
}
|
||||
}
|
||||
|
||||
$this->fadein = $dt->format('H:i:s.u');
|
||||
$this->modifiedColumns[] = CcBlockcontentsPeer::FADEIN;
|
||||
|
||||
return $this;
|
||||
} // setDbFadein()
|
||||
|
||||
/**
|
||||
*
|
||||
* @param String in format SS.uuuuuu, Datetime, or DateTime accepted string.
|
||||
*
|
||||
* @return CcBlockcontents The current object (for fluent API support)
|
||||
*/
|
||||
public function setDbFadeout($v)
|
||||
{
|
||||
if ($v instanceof DateTime) {
|
||||
$dt = $v;
|
||||
}
|
||||
else if (preg_match('/^[0-9]{1,2}(\.\d{1,6})?$/', $v)) {
|
||||
$dt = DateTime::createFromFormat("s.u", $v);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
$dt = new DateTime($v);
|
||||
} catch (Exception $x) {
|
||||
throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
|
||||
}
|
||||
}
|
||||
|
||||
$this->fadeout = $dt->format('H:i:s.u');
|
||||
$this->modifiedColumns[] = CcBlockcontentsPeer::FADEOUT;
|
||||
|
||||
return $this;
|
||||
} // setDbFadeout()
|
||||
|
||||
} // CcBlockcontents
|
||||
|
|
|
@ -139,40 +139,40 @@ class CcShowInstances extends BaseCcShowInstances {
|
|||
$this->save($con);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the value of the aggregate column time_filled
|
||||
*
|
||||
* @param PropelPDO $con A connection object
|
||||
*
|
||||
* @return mixed The scalar result from the aggregate query
|
||||
*/
|
||||
public function computeDbTimeFilled(PropelPDO $con)
|
||||
{
|
||||
$stmt = $con->prepare('SELECT SUM(clip_length) FROM "cc_schedule" WHERE cc_schedule.INSTANCE_ID = :p1');
|
||||
$stmt->bindValue(':p1', $this->getDbId());
|
||||
$stmt->execute();
|
||||
return $stmt->fetchColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the aggregate column time_filled
|
||||
*
|
||||
* @param PropelPDO $con A connection object
|
||||
*/
|
||||
public function updateDbTimeFilled(PropelPDO $con)
|
||||
/**
|
||||
* Computes the value of the aggregate column time_filled
|
||||
*
|
||||
* @param PropelPDO $con A connection object
|
||||
*
|
||||
* @return mixed The scalar result from the aggregate query
|
||||
*/
|
||||
public function computeDbTimeFilled(PropelPDO $con)
|
||||
{
|
||||
$stmt = $con->prepare('SELECT SUM(clip_length) FROM "cc_schedule" WHERE cc_schedule.INSTANCE_ID = :p1');
|
||||
$stmt->bindValue(':p1', $this->getDbId());
|
||||
$stmt->execute();
|
||||
return $stmt->fetchColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the aggregate column time_filled
|
||||
*
|
||||
* @param PropelPDO $con A connection object
|
||||
*/
|
||||
public function updateDbTimeFilled(PropelPDO $con)
|
||||
{
|
||||
$timefilled = $this->computeDbTimeFilled($con);
|
||||
if(is_null($timefilled)){
|
||||
$timefilled = "00:00:00";
|
||||
}
|
||||
$this->setDbTimeFilled($timefilled);
|
||||
$this->save($con);
|
||||
}
|
||||
$this->setDbTimeFilled($timefilled);
|
||||
$this->save($con);
|
||||
}
|
||||
|
||||
public function preInsert(PropelPDO $con = null) {
|
||||
$now = new DateTime("now", new DateTimeZone("UTC"));
|
||||
$this->setDbCreated($now);
|
||||
return true;
|
||||
$now = new DateTime("now", new DateTimeZone("UTC"));
|
||||
$this->setDbCreated($now);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // CcShowInstances
|
||||
|
|
|
@ -107,16 +107,16 @@ class AirtimeInstall
|
|||
echo "done.\n";
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo "Error!\n".$e->getMessage()."\n";
|
||||
echo " SQL statement was:\n";
|
||||
echo "Error!\n".$e->getMessage()."\n";
|
||||
echo " SQL statement was:\n";
|
||||
echo " ".$sql."\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
public static function DropSequence($p_sequenceName)
|
||||
{
|
||||
public static function DropSequence($p_sequenceName)
|
||||
{
|
||||
AirtimeInstall::InstallQuery("DROP SEQUENCE IF EXISTS $p_sequenceName");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to connect to the database. Return true on success, false on failure.
|
||||
|
@ -130,12 +130,12 @@ class AirtimeInstall
|
|||
try {
|
||||
$con = Propel::getConnection();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage().PHP_EOL;
|
||||
echo "Database connection problem.".PHP_EOL;
|
||||
echo "Check if database '{$CC_CONFIG['dsn']['database']}' exists".
|
||||
" with corresponding permissions.".PHP_EOL;
|
||||
if ($p_exitOnError) {
|
||||
exit(1);
|
||||
echo $e->getMessage().PHP_EOL;
|
||||
echo "Database connection problem.".PHP_EOL;
|
||||
echo "Check if database '{$CC_CONFIG['dsn']['database']}' exists".
|
||||
" with corresponding permissions.".PHP_EOL;
|
||||
if ($p_exitOnError) {
|
||||
exit(1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -215,6 +215,15 @@ class AirtimeInstall
|
|||
$database = $CC_CONFIG['dsn']['database'];
|
||||
$username = $CC_CONFIG['dsn']['username'];
|
||||
#$command = "echo \"CREATE DATABASE $database OWNER $username\" | su postgres -c psql 2>/dev/null";
|
||||
|
||||
$command = "su postgres -c \"psql -l | cut -f2 -d' ' | grep -w 'airtime'\";";
|
||||
exec($command, $output, $rv);
|
||||
|
||||
if ($rv == 0) {
|
||||
//database already exists
|
||||
return true;
|
||||
}
|
||||
|
||||
$command = "su postgres -c \"createdb $database --encoding UTF8 --owner $username\"";
|
||||
|
||||
@exec($command, $output, $results);
|
||||
|
@ -305,7 +314,7 @@ class AirtimeInstall
|
|||
|
||||
public static function SetUniqueId()
|
||||
{
|
||||
$con = Propel::getConnection();
|
||||
$con = Propel::getConnection();
|
||||
$uniqueId = md5(uniqid("", true));
|
||||
|
||||
$sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('uniqueId', '$uniqueId')";
|
||||
|
@ -319,8 +328,9 @@ class AirtimeInstall
|
|||
public static function SetDefaultTimezone()
|
||||
{
|
||||
$con = Propel::getConnection();
|
||||
// we need to run php as commandline because we want to get the timezone in cli php.ini file
|
||||
$defaultTimezone = exec("php -r 'echo date_default_timezone_get().PHP_EOL;'");
|
||||
// we need to run php as commandline because we want to get the timezone in cli php.ini file
|
||||
//$defaultTimezone = exec("php -r 'echo date_default_timezone_get().PHP_EOL;'");
|
||||
$defaultTimezone = exec("cat /etc/timezone");
|
||||
$defaultTimezone = trim($defaultTimezone);
|
||||
if((!in_array($defaultTimezone, DateTimeZone::listIdentifiers()))){
|
||||
$defaultTimezone = "UTC";
|
||||
|
@ -335,7 +345,7 @@ class AirtimeInstall
|
|||
|
||||
public static function SetImportTimestamp()
|
||||
{
|
||||
$con = Propel::getConnection();
|
||||
$con = Propel::getConnection();
|
||||
$sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('import_timestamp', '0')";
|
||||
$result = $con->exec($sql);
|
||||
if ($result < 1) {
|
||||
|
|
|
@ -11,7 +11,7 @@ require_once(__DIR__.'/airtime-constants.php');
|
|||
|
||||
require_once(AirtimeInstall::GetAirtimeSrcDir().'/application/configs/conf.php');
|
||||
require_once 'propel/runtime/lib/Propel.php';
|
||||
Propel::init(AirtimeInstall::GetAirtimeSrcDir()."/application/configs/airtime-conf-production.php");
|
||||
Propel::init(AirtimeInstall::GetAirtimeSrcDir()."/application/configs/airtime-conf-production.php");
|
||||
|
||||
echo PHP_EOL."* Database Installation".PHP_EOL;
|
||||
|
||||
|
|
Loading…
Reference in New Issue