Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
Naomi Aro 2012-09-17 16:28:36 -07:00
commit f50fccaf5f
15 changed files with 320 additions and 280 deletions

View file

@ -5,7 +5,12 @@ class ApiController extends Zend_Controller_Action
public function init() public function init()
{ {
$ignoreAuth = array("live-info", "week-info");
$params = $this->getRequest()->getParams();
if (!in_array($params['action'], $ignoreAuth)) {
$this->checkAuth(); $this->checkAuth();
}
/* Initialize action controller here */ /* Initialize action controller here */
$context = $this->_helper->getHelper('contextSwitch'); $context = $this->_helper->getHelper('contextSwitch');
$context->addActionContext('version' , 'json') $context->addActionContext('version' , 'json')
@ -41,7 +46,6 @@ class ApiController extends Zend_Controller_Action
public function checkAuth() public function checkAuth()
{ {
global $CC_CONFIG; global $CC_CONFIG;
$api_key = $this->_getParam('api_key'); $api_key = $this->_getParam('api_key');
if (!in_array($api_key, $CC_CONFIG["apiKey"]) && if (!in_array($api_key, $CC_CONFIG["apiKey"]) &&
@ -298,7 +302,7 @@ class ApiController extends Zend_Controller_Action
$result = array(); $result = array();
for ($i=0; $i<7; $i++) { for ($i=0; $i<7; $i++) {
$utcDayEnd = Application_Common_DateHelper::GetDayEndTimestamp($utcDayStart); $utcDayEnd = Application_Common_DateHelper::GetDayEndTimestamp($utcDayStart);
$shows = Application_Model_Show::getNextShows($utcDayStart, "0", $utcDayEnd); $shows = Application_Model_Show::getNextShows($utcDayStart, "ALL", $utcDayEnd);
$utcDayStart = $utcDayEnd; $utcDayStart = $utcDayEnd;
Application_Model_Show::convertToLocalTimeZone($shows, Application_Model_Show::convertToLocalTimeZone($shows,
@ -307,9 +311,10 @@ class ApiController extends Zend_Controller_Action
$result[$dow[$i]] = $shows; $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"); header("Content-type: text/javascript");
Logging::info($result);
// If a callback is not given, then just provide the raw JSON. // If a callback is not given, then just provide the raw JSON.
echo isset($_GET['callback']) ? $_GET['callback'].'('.json_encode($result).')' : json_encode($result); echo isset($_GET['callback']) ? $_GET['callback'].'('.json_encode($result).')' : json_encode($result);
} else { } else {

View file

@ -217,7 +217,6 @@ class ScheduleController extends Zend_Controller_Action
$file = $show_inst->getRecordedFile(); $file = $show_inst->getRecordedFile();
$id = $file->getId(); $id = $file->getId();
//$res = exec("/usr/lib/airtime/utils/soundcloud-uploader $id > /dev/null &");
Application_Model_Soundcloud::uploadSoundcloud($id); Application_Model_Soundcloud::uploadSoundcloud($id);
// we should die with ui info // we should die with ui info
die(); die();

View file

@ -77,8 +77,21 @@ class Application_Model_Datatables
// map that maps dbname to searchTerm // map that maps dbname to searchTerm
$dbname2searchTerm = array(); $dbname2searchTerm = array();
foreach ($current2dbname as $currentPos => $dbname) { foreach ($current2dbname as $currentPos => $dbname) {
$dbname2searchTerm[$dbname] = $new_index = $librarySetting($currentPos);
$orig2searchTerm[$librarySetting($currentPos)]; // TODO : Fix this retarded hack later. Just a band aid for
// now at least we print some warnings so that we don't
// forget about this -- cc-4462
if ( array_key_exists($new_index, $orig2searchTerm) ) {
$dbname2searchTerm[$dbname] = $orig2searchTerm[$new_index];
} else {
Logging::warn("Trying to reorder to unknown index
printing as much debugging as possible...");
$debug = array(
'$new_index' => $new_index,
'$currentPos' => $currentPos,
'$orig2searchTerm' => $orig2searchTerm);
Logging::warn($debug);
}
} }
$where = array(); $where = array();

View file

@ -1101,7 +1101,7 @@ class Application_Model_Preference
} else { } else {
$ds = unserialize($v); $ds = unserialize($v);
return function ($x) use ($ds) { return function ($x) use ($ds) {
if ( in_array($x, $ds['ColReorder'] ) ) { if ( array_key_exists($x, $ds['ColReorder'] ) ) {
return $ds['ColReorder'][$x]; return $ds['ColReorder'][$x];
} else { } else {
Logging::warn("Index $x does not exist preferences"); Logging::warn("Index $x does not exist preferences");

View file

@ -2060,8 +2060,6 @@ SQL;
// been specified // been specified
if ($timeEnd == "") { if ($timeEnd == "") {
$timeEnd = "'$timeStart' + INTERVAL '2 days'"; $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 //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 si.starts < :timeEnd::timestamp
AND modified_instance != TRUE AND modified_instance != TRUE
ORDER BY si.starts ORDER BY si.starts
LIMIT :lim
SQL; 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, ':timeStart' => $timeStart,
':timeEnd' => $timeEnd, ':timeEnd' => $timeEnd,
':lim' => $limit), 'all'); ':lim' => $limit);
} else {
$params = array(
':timeStart' => $timeStart,
':timeEnd' => $timeEnd);
}
return Application_Common_Database::prepareAndExecute( $sql, $params, 'all');
} }
/** /**

View file

@ -129,6 +129,7 @@ class Application_Model_ShowBuilder
* 0 = past * 0 = past
* 1 = current * 1 = current
* 2 = future * 2 = future
* TODO : change all of the above to real constants -- RG
*/ */
private function getScheduledStatus($p_epochItemStart, $p_epochItemEnd, &$row) private function getScheduledStatus($p_epochItemStart, $p_epochItemEnd, &$row)
{ {
@ -157,6 +158,14 @@ class Application_Model_ShowBuilder
//item is in the future. //item is in the future.
else if ($this->epoch_now < $p_epochItemStart) { else if ($this->epoch_now < $p_epochItemStart) {
$row["scheduled"] = 2; $row["scheduled"] = 2;
} else {
Logging::warn("No-op? is this what should happen...printing
debug just in case");
$d = array(
'$p_epochItemStart' => $p_epochItemStart,
'$p_epochItemEnd' => $p_epochItemEnd,
'$row' => $row);
Logging::warn($d);
} }
} }
@ -189,10 +198,13 @@ class Application_Model_ShowBuilder
$row["record"] = true; $row["record"] = true;
if (Application_Model_Preference::GetUploadToSoundcloudOption()) { if (Application_Model_Preference::GetUploadToSoundcloudOption()) {
$file = Application_Model_StoredFile::Recall($p_item["si_file_id"]); Logging::info('$p_item contains:');
Logging::info($p_item);
$file = Application_Model_StoredFile::Recall(
$p_item['si_file_id']);
if (isset($file)) { if (isset($file)) {
$sid = $file->getSoundCloudId(); $sid = $file->getSoundCloudId();
$row["soundcloud_id"] = $sid; $row['soundcloud_id'] = $sid;
} }
} }
} }
@ -444,9 +456,12 @@ class Application_Model_ShowBuilder
//make the last footer if there were any scheduled items. //make the last footer if there were any scheduled items.
if (count($scheduled_items) > 0) { if (count($scheduled_items) > 0) {
$display_items[] = $this->makeFooterRow($scheduled_items[count($scheduled_items)-1]); $display_items[] = $this->makeFooterRow($scheduled_items[
count($scheduled_items)-1]);
} }
return array("schedule" => $display_items, "showInstances" => $this->showInstances); return array(
"schedule" => $display_items,
"showInstances" => $this->showInstances);
} }
} }

View file

@ -407,11 +407,12 @@ SQL;
*/ */
public function getFileExtension() public function getFileExtension()
{ {
return "";
// TODO : what's the point of having this function? Can we not just use // TODO : what's the point of having this function? Can we not just use
// the extension from the file_path column from cc_files? // the extension from the file_path column from cc_files?
$mime = $this->_file->getDbMime(); $mime = $this->_file->getDbMime();
if ($mime == "audio/vorbis" || $mime == "application/ogg") { if ($mime == "audio/ogg" || $mime == "application/ogg") {
return "ogg"; return "ogg";
} elseif ($mime == "audio/mp3" || $mime == "audio/mpeg") { } elseif ($mime == "audio/mp3" || $mime == "audio/mpeg") {
return "mp3"; return "mp3";
@ -505,8 +506,6 @@ SQL;
*/ */
public function getRelativeFileUrl($baseUrl) public function getRelativeFileUrl($baseUrl)
{ {
Logging::info("getting media!");
return $baseUrl."/api/get-media/file/".$this->getId().".".$this->getFileExtension(); return $baseUrl."/api/get-media/file/".$this->getId().".".$this->getFileExtension();
} }

View file

@ -106,12 +106,12 @@ class Application_Model_StreamSetting
public static function getStreamData($p_streamId) public static function getStreamData($p_streamId)
{ {
$con = Propel::getConnection(); $con = Propel::getConnection();
$streamId = pg_escape_string($p_streamId);
$sql = "SELECT * " $sql = "SELECT * "
."FROM cc_stream_setting " ."FROM cc_stream_setting "
."WHERE keyname LIKE :stream_id"; ."WHERE keyname LIKE '{$streamId}_%'";
$stmt = $con->prepare($sql); $stmt = $con->prepare($sql);
$stmt->bindParam(':stream_id', "${p_streamId}_%");
if ($stmt->execute()) { if ($stmt->execute()) {
$rows = $stmt->fetchAll(); $rows = $stmt->fetchAll();

View file

@ -215,6 +215,15 @@ class AirtimeInstall
$database = $CC_CONFIG['dsn']['database']; $database = $CC_CONFIG['dsn']['database'];
$username = $CC_CONFIG['dsn']['username']; $username = $CC_CONFIG['dsn']['username'];
#$command = "echo \"CREATE DATABASE $database OWNER $username\" | su postgres -c psql 2>/dev/null"; #$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\""; $command = "su postgres -c \"createdb $database --encoding UTF8 --owner $username\"";
@exec($command, $output, $results); @exec($command, $output, $results);
@ -320,7 +329,8 @@ class AirtimeInstall
{ {
$con = Propel::getConnection(); $con = Propel::getConnection();
// we need to run php as commandline because we want to get the timezone in cli php.ini file // 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("php -r 'echo date_default_timezone_get().PHP_EOL;'");
$defaultTimezone = exec("cat /etc/timezone");
$defaultTimezone = trim($defaultTimezone); $defaultTimezone = trim($defaultTimezone);
if((!in_array($defaultTimezone, DateTimeZone::listIdentifiers()))){ if((!in_array($defaultTimezone, DateTimeZone::listIdentifiers()))){
$defaultTimezone = "UTC"; $defaultTimezone = "UTC";

View file

@ -101,6 +101,7 @@ CREATE TABLE cc_webstream (
creator_id integer NOT NULL, creator_id integer NOT NULL,
mtime timestamp(6) without time zone NOT NULL, mtime timestamp(6) without time zone NOT NULL,
utime timestamp(6) without time zone NOT NULL, utime timestamp(6) without time zone NOT NULL,
lptime timestamp(6) without time zone,
mime character varying(255) mime character varying(255)
); );
@ -113,10 +114,13 @@ CREATE TABLE cc_webstream_metadata (
ALTER TABLE cc_files ALTER TABLE cc_files
DROP COLUMN gunid, DROP COLUMN gunid,
ADD COLUMN replay_gain character varying(16), ADD COLUMN replay_gain numeric,
ADD COLUMN owner_id integer, ADD COLUMN owner_id integer,
ALTER COLUMN bpm TYPE integer using airtime_to_int(bpm) /* TYPE change - table: cc_files original: character varying(8) new: integer */; ALTER COLUMN bpm TYPE integer using airtime_to_int(bpm) /* TYPE change - table: cc_files original: character varying(8) new: integer */;
ALTER TABLE cc_files
ADD CONSTRAINT cc_files_owner_fkey FOREIGN KEY (owner_id) REFERENCES cc_subjs(id);
ALTER TABLE cc_playlistcontents ALTER TABLE cc_playlistcontents
ADD COLUMN block_id integer, ADD COLUMN block_id integer,
ADD COLUMN stream_id integer, ADD COLUMN stream_id integer,

View file

@ -35,23 +35,21 @@ get_include_path(),
realpath($CC_CONFIG['phpDir'] . '/library') realpath($CC_CONFIG['phpDir'] . '/library')
))); )));
function __autoload($classname){ function my_autoload($classname){
global $CC_CONFIG; global $CC_CONFIG;
$info = explode('_', $classname); $info = explode('_', $classname);
if (isset($info[2])) { if (isset($info[1]) && isset($info[2])) {
$filename = $info[2].".php"; $filename = $info[2].".php";
require_once($CC_CONFIG['phpDir'].'/application/models/'.$filename); if ($info[1] == "Model") {
$folderName = "models";
} else if ($info[1] == "Common") {
$folderName = "common";
}
require_once($CC_CONFIG['phpDir'].'/application/'.$folderName.'/'.$filename);
} }
} }
require_once($CC_CONFIG['phpDir'].'/application/models/User.php');
require_once($CC_CONFIG['phpDir'].'/application/models/StoredFile.php'); spl_autoload_register('my_autoload');
require_once($CC_CONFIG['phpDir'].'/application/models/Playlist.php');
require_once($CC_CONFIG['phpDir'].'/application/models/Schedule.php');
require_once($CC_CONFIG['phpDir'].'/application/models/Show.php');
require_once($CC_CONFIG['phpDir'].'/application/models/ShowInstance.php');
require_once($CC_CONFIG['phpDir'].'/application/models/Preference.php');
require_once($CC_CONFIG['phpDir'].'/application/models/StreamSetting.php');
require_once($CC_CONFIG['phpDir'].'/application/models/LiveLog.php');
require_once 'propel/runtime/lib/Propel.php'; require_once 'propel/runtime/lib/Propel.php';
Propel::init($CC_CONFIG['phpDir']."/application/configs/airtime-conf-production.php"); Propel::init($CC_CONFIG['phpDir']."/application/configs/airtime-conf-production.php");
@ -64,20 +62,7 @@ if (file_exists('/usr/share/php/libzend-framework-php')){
require_once('Zend/Loader/Autoloader.php'); require_once('Zend/Loader/Autoloader.php');
$autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader = Zend_Loader_Autoloader::getInstance();
try { $infoArray = Application_Model_Preference::GetSystemInfo(true);
$opts = new Zend_Console_Getopt(
array(
'test|t' => "Keep broadcast log data\n"
)
);
$opts->parse();
}
catch (Zend_Console_Getopt_Exception $e) {
print $e->getMessage() .PHP_EOL;
exit(1);
}
$infoArray = Application_Model_Preference::GetSystemInfo(true, isset($opts->t));
if(Application_Model_Preference::GetSupportFeedback() == '1'){ if(Application_Model_Preference::GetSupportFeedback() == '1'){
$url = 'http://stat.sourcefabric.org/index.php?p=airtime'; $url = 'http://stat.sourcefabric.org/index.php?p=airtime';