CC-1927 Remove PEAR DB

* Removed all traces of PEAR functions.
* Fixed AirtimeInstall::GetVersionInstalled() to return the correct answer
  even when it cant connect to the database.  Also fixed return value to
  be consistent on failure.
* Fixed phone_home_stat.php and soundcloud-uploader.php
This commit is contained in:
paul.baranowski 2012-04-05 02:22:21 -04:00 committed by Martin Konecny
parent c0da27b445
commit 96b010e7f0
10 changed files with 65 additions and 120 deletions

View File

@ -123,7 +123,7 @@ class ApiController extends Zend_Controller_Action
if (ctype_alnum($file_id) && strlen($file_id) == 32)
{
$media = Application_Model_StoredFile::RecallByGunid($file_id);
if ( $media != null && !PEAR::isError($media))
if ( $media != null )
{
$filepath = $media->getFilePath();
if(is_file($filepath)){
@ -164,13 +164,13 @@ class ApiController extends Zend_Controller_Action
/**
* Reads the requested portion of a file and sends its contents to the client with the appropriate headers.
*
*
* This HTTP_RANGE compatible read file function is necessary for allowing streaming media to be skipped around in.
*
*
* @param string $location
* @param string $mimeType
* @return void
*
*
* @link https://groups.google.com/d/msg/jplayer/nSM2UmnSKKA/Hu76jDZS4xcJ
* @link http://php.net/manual/en/function.readfile.php#86244
*/
@ -178,17 +178,17 @@ class ApiController extends Zend_Controller_Action
{
$size= filesize($location);
$time= date('r', filemtime($location));
$fm = @fopen($location, 'rb');
if (!$fm)
{
header ("HTTP/1.1 505 Internal server error");
return;
}
$begin= 0;
$end= $size - 1;
if (isset($_SERVER['HTTP_RANGE']))
{
if (preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches))
@ -200,7 +200,7 @@ class ApiController extends Zend_Controller_Action
}
}
}
if (isset($_SERVER['HTTP_RANGE']))
{
header('HTTP/1.1 206 Partial Content');
@ -209,9 +209,9 @@ class ApiController extends Zend_Controller_Action
{
header('HTTP/1.1 200 OK');
}
header("Content-Type: $mimeType");
header("Content-Type: $mimeType");
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: no-cache');
header('Pragma: no-cache');
header('Accept-Ranges: bytes');
header('Content-Length:' . (($end - $begin) + 1));
if (isset($_SERVER['HTTP_RANGE']))
@ -225,7 +225,7 @@ class ApiController extends Zend_Controller_Action
//keep looping until all have been disabled!!!
//http://www.php.net/manual/en/function.ob-end-flush.php
while (@ob_end_flush());
$cur = $begin;
fseek($fm, $begin, 0);
@ -235,7 +235,7 @@ class ApiController extends Zend_Controller_Action
$cur += 1024 * 16;
}
}
/**
* Retrieve the currently playing show as well as upcoming shows.
* Number of shows returned and the time interval in which to
@ -342,8 +342,6 @@ class ApiController extends Zend_Controller_Action
exit;
}
//PEAR::setErrorHandling(PEAR_ERROR_RETURN);
$data = Application_Model_Schedule::GetScheduledPlaylists();
echo json_encode($data, JSON_FORCE_OBJECT);
}
@ -368,12 +366,7 @@ class ApiController extends Zend_Controller_Action
$schedule_group_id = $this->_getParam("schedule_id");
$media_id = $this->_getParam("media_id");
$result = Application_Model_Schedule::UpdateMediaPlayedStatus($media_id);
if (!PEAR::isError($result)) {
echo json_encode(array("status"=>1, "message"=>""));
} else {
echo json_encode(array("status"=>0, "message"=>"DB Error:".$result->getMessage()));
}
echo json_encode(array("status"=>1, "message"=>""));
}
public function recordedShowsAction()
@ -429,7 +422,7 @@ class ApiController extends Zend_Controller_Action
$fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
$result = Application_Model_StoredFile::copyFileToStor($upload_dir, $fileName, $tempFileName);
if (!is_null($result)){
die('{"jsonrpc" : "2.0", "error" : {"code": '.$result[code].', "message" : "'.$result[message].'"}}');
}
@ -780,7 +773,7 @@ class ApiController extends Zend_Controller_Action
print 'You are not allowed to access this resource.';
exit;
}
$info = Application_Model_StreamSetting::getStreamSetting();
$this->view->msg = $info;
}
@ -836,7 +829,7 @@ class ApiController extends Zend_Controller_Action
Application_Model_StreamSetting::setLiquidsoapError($stream_id, $msg, $boot_time);
}
public function updateSourceStatusAction(){
$request = $this->getRequest();
@ -945,13 +938,13 @@ class ApiController extends Zend_Controller_Action
$dir = base64_decode($request->getParam('dir'));
Application_Model_MusicDir::removeWatchedDir($dir, false);
}
/* This action is for use by our dev scripts, that make
* a change to the database and we want rabbitmq to send
* out a message to pypo that a potential change has been made. */
public function rabbitmqDoPushAction(){
global $CC_CONFIG;
$request = $this->getRequest();
$api_key = $request->getParam('api_key');
if (!in_array($api_key, $CC_CONFIG["apiKey"]) &&
@ -962,10 +955,10 @@ class ApiController extends Zend_Controller_Action
exit;
}
Logging::log("Notifying RabbitMQ to send message to pypo");
Application_Model_RabbitMq::PushSchedule();
}
public function getBootstrapInfoAction(){
$live_dj = Application_Model_Preference::GetSourceSwitchStatus('live_dj');
$master_dj = Application_Model_Preference::GetSourceSwitchStatus('master_dj');
@ -977,14 +970,14 @@ class ApiController extends Zend_Controller_Action
$this->view->stream_label = Application_Model_Preference::GetStreamLabelFormat();
$this->view->transition_fade = Application_Model_Preference::GetDefaultTransitionFade();
}
/* This is used but Liquidsoap to check authentication of live streams*/
public function checkLiveStreamAuthAction(){
global $CC_CONFIG;
$request = $this->getRequest();
$api_key = $request->getParam('api_key');
$username = $request->getParam('username');
$password = $request->getParam('password');
$djtype = $request->getParam('djtype');
@ -996,7 +989,7 @@ class ApiController extends Zend_Controller_Action
print 'You are not allowed to access this resource.';
exit;
}
if($djtype == 'master'){
//check against master
if($username == Application_Model_Preference::GetLiveSteamMasterUsername() && $password == Application_Model_Preference::GetLiveSteamMasterPassword()){
@ -1011,15 +1004,15 @@ class ApiController extends Zend_Controller_Action
if(isset($showInfo[0]['id'])){
$current_show_id = $showInfo[0]['id'];
$CcShow = CcShowQuery::create()->findPK($current_show_id);
// get custom pass info from the show
$custom_user = $CcShow->getDbLiveStreamUser();
$custom_pass = $CcShow->getDbLiveStreamPass();
// get hosts ids
$show = new Application_Model_Show($current_show_id);
$hosts_ids = $show->getHostsIds();
// check against hosts auth
if($CcShow->getDbLiveStreamUsingAirtimeAuth()){
foreach( $hosts_ids as $host){

View File

@ -822,9 +822,6 @@ Logging::log("getting media! - 2");
$result = null;
if ($duplicate) {
if (PEAR::isError($duplicate)) {
$result = array("code" => 105, "message" => $duplicate->getMessage());
}
if (file_exists($duplicate->getFilePath())) {
$duplicateName = $duplicate->getMetadataValue('MDATA_KEY_TITLE');
$result = array( "code" => 106, "message" => "An identical audioclip named '$duplicateName' already exists on the server.");

View File

@ -3,7 +3,6 @@ set_include_path(get_include_path() . PATH_SEPARATOR . $path);
$WHITE_SCREEN_OF_DEATH = false;
require_once(dirname(__FILE__).'/../../configs/conf.php');
require_once('DB.php');
require_once('PHPUnit.php');
require_once 'StoredFileTests.php';
require_once 'SchedulerTests.php';

View File

@ -46,9 +46,6 @@ class SchedulerTests extends PHPUnit_TestCase {
function testAddAndRemoveAudioFile() {
$i = new Application_Model_ScheduleGroup();
$this->groupIdCreated = $i->add('2010-10-10 01:30:23', $this->storedFile->getId());
if (PEAR::isError($this->groupIdCreated)) {
$this->fail("Failed to create scheduled item: ". $this->groupIdCreated->getMessage());
}
$i = new Application_Model_ScheduleGroup($this->groupIdCreated);
$result = $i->remove();
@ -67,9 +64,6 @@ class SchedulerTests extends PHPUnit_TestCase {
$i = new Application_Model_ScheduleGroup();
$this->groupIdCreated = $i->add('2010-11-11 01:30:23', null, $playlist->getId());
if (PEAR::isError($this->groupIdCreated)) {
$this->fail("Failed to create scheduled item: ". $this->groupIdCreated->getMessage());
}
$group = new Application_Model_ScheduleGroup($this->groupIdCreated);
if ($group->count() != 3) {
$this->fail("Wrong number of items added.");
@ -90,10 +84,6 @@ class SchedulerTests extends PHPUnit_TestCase {
function testIsScheduleEmptyInRange() {
$i = new Application_Model_ScheduleGroup();
$this->groupIdCreated = $i->add('2011-10-10 01:30:23', $this->storedFile->getId());
if (PEAR::isError($this->groupIdCreated)) {
$this->fail($this->groupIdCreated->getMessage());
return;
}
if (Application_Model_Schedule::isScheduleEmptyInRange('2011-10-10 01:30:23', '00:00:12.555')) {
$this->fail("Reporting empty schedule when it isnt.");
return;

View File

@ -1,14 +1,6 @@
<?php
require_once(dirname(__FILE__).'/../StoredFile.php');
$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);
class StoredFileTest extends PHPUnit_TestCase {
function __construct($name) {
@ -21,10 +13,6 @@ class StoredFileTest extends PHPUnit_TestCase {
function testGetAudioMetadata() {
$filePath = dirname(__FILE__)."/ex1.mp3";
$metadata = Metadata::LoadFromFile($filePath);
if (PEAR::isError($metadata)) {
$this->fail($metadata->getMessage());
return;
}
if (($metadata["dc:description"] != "Tmu sem tam videla ...")
|| ($metadata["audio"]["dataformat"] != "mp3")
|| ($metadata["dc:type"] != "Speech")) {
@ -52,10 +40,6 @@ class StoredFileTest extends PHPUnit_TestCase {
$values = array("filepath" => $filePath,
"dc:description" => "Unit test ".time());
$storedFile = Application_Model_StoredFile::Insert($values, false);
if (PEAR::isError($storedFile)) {
$this->fail("Failed to create StoredFile: ".$storedFile->getMessage());
return;
}
//var_dump($storedFile);
$id = $storedFile->getId();
if (!is_numeric($id)) {

View File

@ -38,10 +38,20 @@ class AirtimeInstall
}
}
/**
* Return the version of Airtime currently installed.
* If not installed, return null.
*
* @return NULL|string
*/
public static function GetVersionInstalled()
{
global $CC_CONFIG;
$con = Propel::getConnection();
try {
$con = Propel::getConnection();
} catch (PropelException $e) {
return null;
}
if (file_exists('/etc/airtime/airtime.conf')) {
$values = parse_ini_file('/etc/airtime/airtime.conf', true);
@ -66,7 +76,7 @@ class AirtimeInstall
//echo "Airtime Version: ".$version." ".PHP_EOL;
}
else {
$version = false;
$version = null;
}
}

View File

@ -23,7 +23,7 @@ $version = AirtimeInstall::GetVersionInstalled();
// The current version is already installed.
echo "* Checking for existing Airtime installation...".PHP_EOL;
if (isset($version)){
if ($version === false){
if (is_null($version)){
//version of Airtime older than 1.7.0 detected
exit(3);
} else {

View File

@ -15,7 +15,6 @@ set_include_path(APPLICATION_PATH . get_include_path() . PATH_SEPARATOR . '/cont
require_once APPLICATION_PATH.'/configs/conf.php';
require_once 'DB.php';
require_once(APPLICATION_PATH.'/../library/propel/runtime/lib/Propel.php');
require_once 'Soundcloud.php';
@ -31,17 +30,6 @@ require_once 'Preference.php';
// Initialize Propel with the runtime configuration
Propel::init(__DIR__."/../../../application/configs/airtime-conf.php");
$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);
$playlistName = "pypo_playlist_test";
$secondsFromNow = 30;
@ -70,10 +58,6 @@ if (is_null($mediaFile)) {
echo "Adding test audio clip to the database.\n";
$v = array("filepath" => __DIR__."/../../../audio_samples/vorbis.com/Hydrate-Kenny_Beltrey.ogg");
$mediaFile = Application_Model_StoredFile::Insert($v);
if (PEAR::isError($mediaFile)) {
var_dump($mediaFile);
exit();
}
}
$pl->addAudioClip($mediaFile->getId());
echo "done.\n";

View File

@ -29,6 +29,12 @@ 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')
)));
require_once($CC_CONFIG['phpDir'].'/application/models/User.php');
require_once($CC_CONFIG['phpDir'].'/application/models/StoredFile.php');
require_once($CC_CONFIG['phpDir'].'/application/models/Playlist.php');
@ -38,50 +44,39 @@ 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('DB.php');
$CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
if (PEAR::isError($CC_DBC)) {
/*echo $CC_DBC->getMessage().PHP_EOL;
echo $CC_DBC->getUserInfo().PHP_EOL;
echo "Database connection problem.".PHP_EOL;
echo "Check if database '{$CC_CONFIG['dsn']['database']}' exists".
" with corresponding permissions.".PHP_EOL;*/
exit(1);
} else {
//echo "* Connected to database".PHP_EOL;
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
}
require_once 'propel/runtime/lib/Propel.php';
Propel::init($CC_CONFIG['phpDir']."/application/configs/airtime-conf-production.php");
if(Application_Model_Preference::GetSupportFeedback() == '1'){
$infoArray = Application_Model_Preference::GetSystemInfo(true);
$url = 'http://stat.sourcefabric.org/index.php?p=airtime';
//$url = 'http://stat-dev.sourcefabric.org/index.php?p=airtime';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = json_encode($infoArray);
$dataArray = array("data" => $data );
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';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
if(curl_errno($ch)) {
echo "curl error: " . curl_error($ch) . "\n";
} else {
@ -89,7 +84,7 @@ if(Application_Model_Preference::GetPlanLevel() == 'disabled'){
Application_Model_Preference::SetLatestVersion($resultArray[0]);
Application_Model_Preference::SetLatestLink($resultArray[1]);
}
curl_close($ch);
}

View File

@ -24,6 +24,12 @@ 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')
)));
require_once($CC_CONFIG['phpDir'].'/application/models/StoredFile.php');
require_once($CC_CONFIG['phpDir'].'/application/models/Preference.php');
require_once($CC_CONFIG['phpDir'].'/application/models/MusicDir.php');
@ -35,21 +41,8 @@ set_include_path($CC_CONFIG['phpDir']."/application/models" . PATH_SEPARATOR . g
require_once($CC_CONFIG['phpDir']."/library/propel/runtime/lib/Propel.php");
Propel::init($CC_CONFIG['phpDir']."/application/configs/airtime-conf.php");
require_once('DB.php');
$CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
if (PEAR::isError($CC_DBC)) {
/*echo $CC_DBC->getMessage().PHP_EOL;
echo $CC_DBC->getUserInfo().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);
}
} else {
//echo "* Connected to database".PHP_EOL;
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
}
require_once 'propel/runtime/lib/Propel.php';
Propel::init($CC_CONFIG['phpDir']."/application/configs/airtime-conf-production.php");
if(count($argv) != 2){
exit;