diff --git a/airtime_mvc/application/models/LiveLog.php b/airtime_mvc/application/models/LiveLog.php index fffa35074..c3a254062 100644 --- a/airtime_mvc/application/models/LiveLog.php +++ b/airtime_mvc/application/models/LiveLog.php @@ -3,14 +3,14 @@ class Application_Model_LiveLog { - public static function GetLiveShowDuration() { + public static function GetLiveShowDuration($p_keepData=false) { try { $con = Propel::getConnection(); $sql = "SELECT * FROM CC_LIVE_LOG" - ." WHERE state = 'L'" - ." and (start_time >= (now() - INTERVAL '1 day'))" - ." ORDER BY id"; + ." WHERE state = 'L'" + ." and (start_time >= (now() - INTERVAL '1 day'))" + ." ORDER BY id"; $rows = $con->query($sql)->fetchAll(); @@ -32,7 +32,7 @@ class Application_Model_LiveLog $duration = $start->diff($end); $duration = $duration->format("%H:%i:%s"); $intervals = explode(":", $duration); - // Trim milliseconds (DateInteral does not support) + // Trim milliseconds (DateInterval does not support) $sec = explode(".", $intervals[2]); $intervals[2] = $sec[0]; @@ -50,16 +50,19 @@ class Application_Model_LiveLog $hours += $intervals[0]; - // Delete data we just used to start a new log history - $sql_delete = "DELETE FROM CC_LIVE_LOG" - ." WHERE id = '{$row['id']}'"; - $con->exec($sql_delete); + if (!$p_keepData) { + // Delete data we just used to start a new log history + $sql_delete = "DELETE FROM CC_LIVE_LOG" + ." WHERE id = '{$row['id']}'"; + $con->exec($sql_delete); + } } - + //Trim milliseconds $seconds = explode(".", $seconds); - $duration = new DateInterval("PT". $hours . "H" . $minutes . "M" . $seconds[0] ."S"); - return $duration->format("%H:%i:%s"); - return $duration; + $minutes = (double)(($hours*60)+$minutes . "." . $seconds[0]); + //$duration = new DateInterval("PT" . $minutes . "M" . $seconds[0] ."S"); + //return $duration->format("%i.%s"); + return $minutes; } catch (Exception $e) { header('HTTP/1.0 503 Service Unavailable'); Logging::log("GetLiveShowDuration - Could not connect to database."); @@ -67,14 +70,15 @@ class Application_Model_LiveLog } } - public static function GetScheduledDuration() { + public static function GetScheduledDuration($p_keepData = false) + { try { $con = Propel::getConnection(); $sql_get_logs = "SELECT * FROM CC_LIVE_LOG" - ." WHERE state = 'S'" - ." and (start_time >= (now() - INTERVAL '1 day'))" - ." ORDER BY id"; + ." WHERE state = 'S'" + ." and (start_time >= (now() - INTERVAL '1 day'))" + ." ORDER BY id"; $rows = $con->query($sql_get_logs)->fetchAll(); @@ -95,10 +99,10 @@ class Application_Model_LiveLog */ foreach ($rows as $row) { $sql_get_tracks = "SELECT * FROM cc_schedule" - ." WHERE starts >= '{$row['start_time']}'" - ." AND starts < '{$row['end_time']}'" - ." AND file_id IS NOT NULL" - ." AND media_item_played IS TRUE"; + ." WHERE starts >= '{$row['start_time']}'" + ." AND starts < '{$row['end_time']}'" + ." AND file_id IS NOT NULL" + ." AND media_item_played IS TRUE"; $tracks = $con->query($sql_get_tracks)->fetchAll(); foreach ($tracks as $track) { if ($track['ends'] > $row['end_time']) { @@ -167,17 +171,20 @@ class Application_Model_LiveLog $hours += $intervals[0]; } - //Delete row because we do not need data anymore - $sql_delete = "DELETE FROM CC_LIVE_LOG" - ." WHERE id = '{$row['id']}'"; - $con->exec($sql_delete); - + if (!$p_keepData) { + //Delete row because we do not need data anymore + $sql_delete = "DELETE FROM CC_LIVE_LOG" + ." WHERE id = '{$row['id']}'"; + $con->exec($sql_delete); + } } $seconds = explode(".", $seconds); - $duration = new DateInterval("PT". $hours . "H" . $minutes . "M" . $seconds[0] ."S"); - return $duration->format("%H:%i:%s"); + $minutes = (double)(($hours*60)+$minutes . "." . $seconds[0]); + //$duration = new DateInterval("PT". $minutes . "M" . $seconds[0] ."S"); + //return $duration->format("%i.%s"); + return $minutes; } catch (Exception $e) { header('HTTP/1.0 503 Service Unavailable'); Logging::log("GetScheduledDuration - Could not connect to database."); @@ -208,12 +215,12 @@ class Application_Model_LiveLog * has ended */ $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='L' and end_time is NULL) or (state='S' and end_time is NULL)"; $id = $con->query($sql_select)->fetchColumn(0); if ($id == null) { $sql_insert = "INSERT INTO CC_LIVE_LOG (state, start_time)" - ." VALUES ('$state', '{$dateTime->format("Y-m-d H:i:s")}')"; + ." VALUES ('$state', '{$dateTime->format("Y-m-d H:i:s")}')"; $con->exec($sql_insert); } diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index 8f690ddcd..93b42384c 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -397,7 +397,8 @@ class Application_Model_Preference return $out; } - public static function GetSystemInfo($returnArray=false){ + public static function GetSystemInfo($returnArray=false, $p_testing) + { exec('/usr/bin/airtime-check-system --no-color', $output); $output = preg_replace('/\s+/', ' ', $output); @@ -414,8 +415,8 @@ class Application_Model_Preference $outputArray = array(); - $outputArray['LIVE_DURATION'] = Application_Model_LiveLog::GetLiveShowDuration(); - $outputArray['SCHEDULED_DURATION'] = Application_Model_LiveLog::GetScheduledDuration(); + $outputArray['LIVE_DURATION'] = Application_Model_LiveLog::GetLiveShowDuration($p_testing); + $outputArray['SCHEDULED_DURATION'] = Application_Model_LiveLog::GetScheduledDuration($p_testing); $outputArray['SOUNDCLOUD_ENABLED'] = self::GetUploadToSoundcloudOption(); if ($outputArray['SOUNDCLOUD_ENABLED']) { $outputArray['NUM_SOUNDCLOUD_TRACKS_UPLOADED'] = Application_Model_StoredFile::getSoundCloudUploads(); diff --git a/utils/phone_home_stat.php b/utils/phone_home_stat.php index a55d3da6c..23ef83ed2 100644 --- a/utils/phone_home_stat.php +++ b/utils/phone_home_stat.php @@ -29,11 +29,11 @@ require_once($CC_CONFIG['phpDir'].'/application/configs/conf.php'); $CC_CONFIG['phpDir'] = $values['general']['airtime_dir']; -// Ensure library/ is on include_path -set_include_path(implode(PATH_SEPARATOR, array( - get_include_path(), - realpath($CC_CONFIG['phpDir'] . '/library') -))); +// Ensure library/ is on include_path +set_include_path(implode(PATH_SEPARATOR, array( +get_include_path(), +realpath($CC_CONFIG['phpDir'] . '/library') +))); require_once($CC_CONFIG['phpDir'].'/application/models/User.php'); require_once($CC_CONFIG['phpDir'].'/application/models/StoredFile.php'); @@ -43,15 +43,38 @@ 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'; -Propel::init($CC_CONFIG['phpDir']."/application/configs/airtime-conf-production.php"); +require_once 'propel/runtime/lib/Propel.php'; +Propel::init($CC_CONFIG['phpDir']."/application/configs/airtime-conf-production.php"); + +//Zend framework +if (file_exists('/usr/share/php/libzend-framework-php')){ + set_include_path('/usr/share/php/libzend-framework-php' . PATH_SEPARATOR . get_include_path()); +} + +require_once('Zend/Loader/Autoloader.php'); +$autoloader = Zend_Loader_Autoloader::getInstance(); + +try { + $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); +} if(Application_Model_Preference::GetSupportFeedback() == '1'){ - $infoArray = Application_Model_Preference::GetSystemInfo(true); + + $infoArray = Application_Model_Preference::GetSystemInfo(true, isset($opts->t)); $url = 'http://stat.sourcefabric.org/index.php?p=airtime'; - //$url = 'http://stat-dev.sourcefabric.org/index.php?p=airtime'; + //$url = 'http://localhost:9999/index.php?p=airtime'; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @@ -64,13 +87,13 @@ if(Application_Model_Preference::GetSupportFeedback() == '1'){ curl_setopt($ch, CURLOPT_POSTFIELDS, $dataArray); $result = curl_exec($ch); - curl_close($ch); } // Get latest version from stat server and store to db if(Application_Model_Preference::GetPlanLevel() == 'disabled'){ $url = 'http://stat.sourcefabric.org/airtime-stats/airtime_latest_version'; + //$url = 'http://localhost:9999/index.php?p=airtime'; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @@ -81,8 +104,12 @@ if(Application_Model_Preference::GetPlanLevel() == 'disabled'){ echo "curl error: " . curl_error($ch) . "\n"; } else { $resultArray = explode("\n", $result); - Application_Model_Preference::SetLatestVersion($resultArray[0]); - Application_Model_Preference::SetLatestLink($resultArray[1]); + if (isset($resultArray[0])) { + Application_Model_Preference::SetLatestVersion($resultArray[0]); + } + if (isset($resultArray[1])) { + Application_Model_Preference::SetLatestLink($resultArray[1]); + } } curl_close($ch);