Removed even more old code, getting closer to a clean code base!
Added (temporary file) for SQL upgrade script to remove unused database tables.
This commit is contained in:
parent
90b46d8eb3
commit
1c2ff6c150
|
@ -1,183 +0,0 @@
|
|||
<?
|
||||
/**
|
||||
* AccessRecur class
|
||||
*
|
||||
* Handles recursive accessPlaylist/releasePlaylist.
|
||||
* Should be 'required_once' from LocStor.php only.
|
||||
*
|
||||
* @package Airtime
|
||||
* @subpackage StorageServer
|
||||
* @copyright 2010 Sourcefabric O.P.S.
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
*/
|
||||
class AccessRecur {
|
||||
public $ls;
|
||||
public $sessid;
|
||||
|
||||
public function __construct(&$ls, $sessid)
|
||||
{
|
||||
$this->ls =& $ls;
|
||||
$this->sessid = $sessid;
|
||||
}
|
||||
|
||||
|
||||
public static function accessPlaylist(&$ls, $sessid, $plid, $parent='0')
|
||||
{
|
||||
$ppa = new AccessRecur($ls, $sessid);
|
||||
$r = $ls->accessPlaylist($sessid, $plid, FALSE, $parent);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
$plRes = $r;
|
||||
$r = StoredFile::RecallByGunid($plid);
|
||||
if (is_null($r) || PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
$ac = $r;
|
||||
$r = $ac->md->genPhpArray();
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
$pla = $r;
|
||||
$r = $ppa->processPlaylist($pla, $plRes['token']);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
$plRes['content'] = $r;
|
||||
return $plRes;
|
||||
}
|
||||
|
||||
|
||||
public static function releasePlaylist(&$ls, $sessid, $token)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$ppa = new AccessRecur($ls, $sessid);
|
||||
$r = $CC_DBC->getAll("
|
||||
SELECT to_hex(token)as token2, to_hex(gunid)as gunid
|
||||
FROM ".$CC_CONFIG['accessTable']."
|
||||
WHERE parent=x'{$token}'::bigint
|
||||
");
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
$arr = $r;
|
||||
foreach ($arr as $i => $item) {
|
||||
extract($item); // token2, gunid
|
||||
$r = BasicStor::GetType($gunid);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
$ftype = $r;
|
||||
# echo "$ftype/$token2\n";
|
||||
switch (strtolower($ftype)) {
|
||||
case "audioclip":
|
||||
$r = $ppa->ls->releaseRawAudioData($ppa->sessid, $token2);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
# var_dump($r);
|
||||
break;
|
||||
case "playlist":
|
||||
$r = $ppa->releasePlaylist($ppa->ls, $ppa->sessid, $token2);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
# var_dump($r);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
$r = $ppa->ls->releasePlaylist($ppa->sessid, $token, FALSE);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
|
||||
private function processPlaylist($pla, $parent)
|
||||
{
|
||||
$res = array();
|
||||
foreach ($pla['children'] as $ple) {
|
||||
switch ($ple['elementname']) {
|
||||
case "playlistElement":
|
||||
$r = $this->processPlaylistElement($ple, $parent);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
// $res = array_merge($res, $r);
|
||||
$res[] = $r;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
private function processAudioClip($gunid, $parent)
|
||||
{
|
||||
$r = $this->ls->accessRawAudioData($this->sessid, $gunid, $parent);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
|
||||
private function processPlaylistElement($ple, $parent='0')
|
||||
{
|
||||
foreach ($ple['children'] as $ac) {
|
||||
switch ($ac['elementname']) {
|
||||
case "audioClip":
|
||||
$r = $this->processAudioClip($ac['attrs']['id'], $parent);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
return $r;
|
||||
case "playlist":
|
||||
// if(empty($ac['children'])){
|
||||
$r = $this->accessPlaylist($this->ls, $this->sessid,
|
||||
$ac['attrs']['id'], $parent);
|
||||
if (PEAR::isError($r)) {
|
||||
if ($r->getCode() != GBERR_NOTF) {
|
||||
return $r;
|
||||
} else {
|
||||
$r = $this->processPlaylist($ac, $parent);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
$r = array(
|
||||
'content' => $r,
|
||||
'url' => NULL,
|
||||
'token' => NULL,
|
||||
'chsum' => NULL,
|
||||
'size' => NULL,
|
||||
'warning' => 'inline playlist?',
|
||||
);
|
||||
}
|
||||
}
|
||||
return $r;
|
||||
/*
|
||||
}else{
|
||||
$r = $this->processPlaylist($ac, $parent);
|
||||
if(PEAR::isError($r)) return $r;
|
||||
$res = array(
|
||||
'content' => $r,
|
||||
'url' => NULL,
|
||||
'token' => NULL,
|
||||
'chsum' => NULL,
|
||||
'size' => NULL,
|
||||
'warning' => 'inline playlist',
|
||||
);
|
||||
return $res;
|
||||
}
|
||||
*/
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
} // class AccessRecur
|
|
@ -56,7 +56,6 @@ define('GBERR_NOTIMPL', 69);
|
|||
|
||||
require_once(dirname(__FILE__)."/Alib.php");
|
||||
require_once(dirname(__FILE__)."/StoredFile.php");
|
||||
require_once(dirname(__FILE__)."/Transport.php");
|
||||
require_once(dirname(__FILE__)."/Playlist.php");
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,156 +0,0 @@
|
|||
<?php
|
||||
if (isset($WHITE_SCREEN_OF_DEATH) && $WHITE_SCREEN_OF_DEATH) {
|
||||
echo __FILE__.':line '.__LINE__.": Greenbox begin<br>";
|
||||
}
|
||||
require_once("BasicStor.php");
|
||||
if (isset($WHITE_SCREEN_OF_DEATH) && $WHITE_SCREEN_OF_DEATH) {
|
||||
echo __FILE__.':line '.__LINE__.": Loaded BasicStor<br>";
|
||||
}
|
||||
require_once("Playlist.php");
|
||||
require_once('Prefs.php');
|
||||
require_once("Transport.php");
|
||||
|
||||
/**
|
||||
* GreenBox class
|
||||
*
|
||||
* File storage module.
|
||||
*
|
||||
* @package Airtime
|
||||
* @subpackage StorageServer
|
||||
* @copyright 2010 Sourcefabric O.P.S.
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
*/
|
||||
class GreenBox extends BasicStor {
|
||||
|
||||
/* ====================================================== storage methods */
|
||||
/* ------------------------------------------------------------- metadata */
|
||||
|
||||
/**
|
||||
* Search in local metadata database.
|
||||
*
|
||||
* @param array $criteria
|
||||
* with following structure:<br>
|
||||
* <ul>
|
||||
* <li>filetype - string, type of searched files,
|
||||
* meaningful values: 'audioclip', 'webstream', 'playlist', 'all'</li>
|
||||
* <li>operator - string, type of conditions join
|
||||
* (any condition matches / all conditions match),
|
||||
* meaningful values: 'and', 'or', ''
|
||||
* (may be empty or ommited only with less then 2 items in
|
||||
* "conditions" field)
|
||||
* </li>
|
||||
* <li>limit : int - limit for result arrays (0 means unlimited)</li>
|
||||
* <li>offset : int - starting point (0 means without offset)</li>
|
||||
* <li>orderby : string - metadata category for sorting (optional)
|
||||
* or array of strings for multicolumn orderby
|
||||
* [default: dc:creator, dc:source, dc:title]
|
||||
* </li>
|
||||
* <li>desc : boolean - flag for descending order (optional)
|
||||
* or array of boolean for multicolumn orderby
|
||||
* (it corresponds to elements of orderby field)
|
||||
* [default: all ascending]
|
||||
* </li>
|
||||
* <li>conditions - array of hashes with structure:
|
||||
* <ul>
|
||||
* <li>cat - string, metadata category name</li>
|
||||
* <li>op - string, operator - meaningful values:
|
||||
* 'full', 'partial', 'prefix', '=', '<',
|
||||
* '<=', '>', '>='</li>
|
||||
* <li>val - string, search value</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* </ul>
|
||||
* @param string $sessid
|
||||
* session id
|
||||
* @return array of hashes, fields:
|
||||
* <ul>
|
||||
* <li>cnt : integer - number of matching gunids
|
||||
* of files have been found</li>
|
||||
* <li>results : array of hashes:
|
||||
* <ul>
|
||||
* <li>gunid: string</li>
|
||||
* <li>type: string - audioclip | playlist | webstream</li>
|
||||
* <li>title: string - dc:title from metadata</li>
|
||||
* <li>creator: string - dc:creator from metadata</li>
|
||||
* <li>length: string - dcterms:extent in extent format</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* </ul>
|
||||
* @see BasicStor::bsLocalSearch
|
||||
*/
|
||||
public function localSearch($criteria, $sessid='')
|
||||
{
|
||||
$limit = intval(isset($criteria['limit']) ? $criteria['limit'] : 0);
|
||||
$offset = intval(isset($criteria['offset']) ? $criteria['offset'] : 0);
|
||||
return $this->bsLocalSearch($criteria, $limit, $offset);
|
||||
} // fn localSearch
|
||||
|
||||
|
||||
/*====================================================== playlist methods */
|
||||
/**
|
||||
* Close import-handle and import playlist
|
||||
*
|
||||
* @param string $token
|
||||
* import token obtained by importPlaylistOpen method
|
||||
* @return int
|
||||
* result file local id (or error object)
|
||||
*/
|
||||
public function importPlaylistClose($token)
|
||||
{
|
||||
$arr = $this->bsClosePut($token);
|
||||
if (PEAR::isError($arr)) {
|
||||
return $arr;
|
||||
}
|
||||
$fname = $arr['fname'];
|
||||
$owner = $arr['owner'];
|
||||
$res = $this->bsImportPlaylist($fname, $owner);
|
||||
if (file_exists($fname)) {
|
||||
@unlink($fname);
|
||||
}
|
||||
return $res;
|
||||
} // fn importPlaylistClose
|
||||
|
||||
|
||||
/* ========================================================= info methods */
|
||||
/* ==================================================== redefined methods */
|
||||
|
||||
/**
|
||||
* Change user password.
|
||||
*
|
||||
* ('superuser mode'= superuser is changing some password without
|
||||
* knowledge of the old password)
|
||||
*
|
||||
* @param string $login
|
||||
* @param string $oldpass
|
||||
* old password
|
||||
* (should be null or empty for 'superuser mode')
|
||||
* @param string $pass
|
||||
* @param string $sessid
|
||||
* session id, required for 'superuser mode'
|
||||
* @return boolean/err
|
||||
*/
|
||||
public function passwd($login, $oldpass=null, $pass='', $sessid='')
|
||||
{
|
||||
if (is_null($oldpass) || ($oldpass == '') ) {
|
||||
if (($res = BasicStor::Authorize('subjects', $this->rootId, $sessid)) !== TRUE) {
|
||||
sleep(2);
|
||||
return $res;
|
||||
} else {
|
||||
$oldpass = null;
|
||||
}
|
||||
} else {
|
||||
if (FALSE === Subjects::Authenticate($login, $oldpass)) {
|
||||
sleep(2);
|
||||
return PEAR::raiseError(
|
||||
"GreenBox::passwd: access denied (oldpass)", GBERR_DENY);
|
||||
}
|
||||
}
|
||||
$res = Subjects::Passwd($login, $oldpass, $pass);
|
||||
if (PEAR::isError($res)) {
|
||||
return $res;
|
||||
}
|
||||
return TRUE;
|
||||
} // fn passwd
|
||||
|
||||
|
||||
} // class GreenBox
|
File diff suppressed because it is too large
Load Diff
|
@ -1,10 +1,7 @@
|
|||
<?php
|
||||
|
||||
define('INDCH', ' ');
|
||||
|
||||
/**
|
||||
* Auxiliary class for GreenBox playlist editing methods.
|
||||
*
|
||||
* remark: dcterms:extent format: hh:mm:ss.ssssss
|
||||
*
|
||||
* @package Airtime
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
<?php
|
||||
|
||||
require_once("GreenBox.php");
|
||||
|
||||
/**
|
||||
* Preference storage class.
|
||||
*
|
||||
|
@ -14,17 +11,11 @@ require_once("GreenBox.php");
|
|||
/* ================== Prefs ================== */
|
||||
class Prefs {
|
||||
|
||||
public $gb;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param GreenBox $gb
|
||||
* GreenBox object reference
|
||||
*/
|
||||
public function __construct(&$gb)
|
||||
public function __construct()
|
||||
{
|
||||
$this->gb =& $gb;
|
||||
}
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,419 +0,0 @@
|
|||
<?php
|
||||
|
||||
define('TR_LEAVE_CLOSED', TRUE);
|
||||
|
||||
/**
|
||||
* Auxiliary class for transport records
|
||||
*
|
||||
* @package Airtime
|
||||
* @subpackage StorageServer
|
||||
* @copyright 2010 Sourcefabric O.P.S.
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
*/
|
||||
class TransportRecord
|
||||
{
|
||||
/**
|
||||
* @var DB
|
||||
*/
|
||||
//public $dbc;
|
||||
|
||||
/**
|
||||
* @var GreenBox
|
||||
*/
|
||||
private $gb;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
//private $config;
|
||||
|
||||
/**
|
||||
* @var Transport
|
||||
*/
|
||||
private $tr;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
private $recalled = FALSE;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
private $dropped = FALSE;
|
||||
|
||||
|
||||
/**
|
||||
* @param Transport $tr
|
||||
* @return TransportRecord
|
||||
*/
|
||||
public function __construct(&$tr)
|
||||
{
|
||||
$this->tr =& $tr;
|
||||
$this->gb =& $tr->gb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Factory method
|
||||
*
|
||||
* @param Transport $tr
|
||||
* @param string $trtype
|
||||
* transport type (see Transport::install)
|
||||
* @param string $direction
|
||||
* 'up' | 'down'
|
||||
* @param array $defaults
|
||||
* default parameters (optional, internal use)
|
||||
* @return TransportRecord
|
||||
*/
|
||||
function create(&$tr, $trtype, $direction='up', $defaults=array())
|
||||
{
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
$trec = new TransportRecord($tr);
|
||||
$trec->trtok = $trtok = $tr->_createTransportToken();
|
||||
$trec->row = array_merge($defaults,
|
||||
array('trtype'=>$trtype, 'direction'=>$direction));
|
||||
$trec->recalled = TRUE;
|
||||
if (!isset($defaults['title'])) {
|
||||
$defaults['title'] = $trec->getTitle();
|
||||
if (PEAR::isError($defaults['title'])) {
|
||||
return $defaults['title'];
|
||||
}
|
||||
}
|
||||
$id = $CC_DBC->nextId($CC_CONFIG['transSequence']);
|
||||
$names = "id, trtok, direction, state, trtype, start, ts";
|
||||
$values = "$id, '$trtok', '$direction', 'init', '$trtype', now(), now()";
|
||||
foreach ($defaults as $k => $v) {
|
||||
$sqlVal = $trec->_getSqlVal($k, $v);
|
||||
$names .= ", $k";
|
||||
$values .= ", $sqlVal";
|
||||
}
|
||||
$query = "
|
||||
INSERT INTO ".$CC_CONFIG['transTable']."
|
||||
($names)
|
||||
VALUES
|
||||
($values)
|
||||
";
|
||||
$res = $CC_DBC->query($query);
|
||||
if (PEAR::isError($res)) {
|
||||
return $res;
|
||||
}
|
||||
return $trec;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Recall transport record from DB
|
||||
*
|
||||
* @param Transport $tr
|
||||
* @param string $trtok
|
||||
* transport token
|
||||
* @return TransportRecord
|
||||
*/
|
||||
function recall(&$tr, $trtok)
|
||||
{
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
$trec = new TransportRecord($tr);
|
||||
$trec->trtok = $trtok;
|
||||
$row = $CC_DBC->getRow("
|
||||
SELECT
|
||||
id, trtok, state, trtype, direction,
|
||||
to_hex(gunid)as gunid, to_hex(pdtoken)as pdtoken,
|
||||
fname, localfile, url, rtrtok, mdtrtok, uid,
|
||||
expectedsize, realsize, expectedsum, realsum,
|
||||
errmsg, title, jobpid
|
||||
FROM ".$CC_CONFIG['transTable']."
|
||||
WHERE trtok='$trtok'
|
||||
");
|
||||
if (PEAR::isError($row)) {
|
||||
return $row;
|
||||
}
|
||||
if (is_null($row)) {
|
||||
return PEAR::raiseError("TransportRecord::recall:".
|
||||
" invalid transport token ($trtok)", TRERR_TOK
|
||||
);
|
||||
}
|
||||
$row['pdtoken'] = StoredFile::NormalizeGunid($row['pdtoken']);
|
||||
$row['gunid'] = StoredFile::NormalizeGunid($row['gunid']);
|
||||
$trec->row = $row;
|
||||
$trec->recalled = TRUE;
|
||||
return $trec;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set state of transport record
|
||||
*
|
||||
* @param string $newState
|
||||
* @param array $data
|
||||
* other data fields to set
|
||||
* @param string $oldState
|
||||
* check old state and do nothing if differ
|
||||
* @param boolean $lock
|
||||
* check lock and do nothing if differ
|
||||
* @return boolean success
|
||||
*/
|
||||
function setState($newState, $data=array(), $oldState=NULL, $lock=NULL)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$set = " state='$newState', ts=now()";
|
||||
if (!is_null($lock)) {
|
||||
$slock = ($lock ? 'Y' : 'N');
|
||||
$nlock = (!$lock);
|
||||
$snlock = ($nlock ? 'Y' : 'N');
|
||||
$set .= ", lock='$snlock'";
|
||||
}
|
||||
foreach ($data as $k => $v) {
|
||||
$set .= ", $k=".$this->_getSqlVal($k, $v);
|
||||
}
|
||||
$r = $CC_DBC->query("
|
||||
UPDATE ".$CC_CONFIG['transTable']."
|
||||
SET $set
|
||||
WHERE trtok='{$this->trtok}'".
|
||||
(is_null($oldState) ? '' : " AND state='$oldState'").
|
||||
(is_null($lock) ? '' : " AND lock = '$slock'")
|
||||
);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
// return TRUE;
|
||||
$affRows = $CC_DBC->affectedRows();
|
||||
if (PEAR::isError($affRows)) {
|
||||
return $affRows;
|
||||
}
|
||||
return ($affRows == 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return state of transport record
|
||||
*
|
||||
* @return string
|
||||
* state
|
||||
*/
|
||||
function getState()
|
||||
{
|
||||
if (!$this->recalled) {
|
||||
return PEAR::raiseError("TransportRecord::getState:".
|
||||
" not recalled ({$this->trtok})", TRERR_TOK
|
||||
);
|
||||
}
|
||||
return $this->row['state'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set lock on transport record and save/clear process id
|
||||
*
|
||||
* @param boolean $lock
|
||||
* lock if true, release lock if false
|
||||
* @param int $pid
|
||||
* process id
|
||||
* @return mixed
|
||||
* true or error
|
||||
*/
|
||||
function setLock($lock, $pid=NULL)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$pidsql = (is_null($pid) ? "NULL" : "$pid" );
|
||||
if ($this->dropped) {
|
||||
return TRUE;
|
||||
}
|
||||
$slock = ($lock ? 'Y' : 'N');
|
||||
$nlock = (!$lock);
|
||||
$snlock = ($nlock ? 'Y' : 'N');
|
||||
$r = $CC_DBC->query("
|
||||
UPDATE ".$CC_CONFIG['transTable']."
|
||||
SET lock='$slock', jobpid=$pidsql, ts=now()
|
||||
WHERE trtok='{$this->trtok}' AND lock = '$snlock'"
|
||||
);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
$affRows = $CC_DBC->affectedRows();
|
||||
if (PEAR::isError($affRows)) {
|
||||
return $affRows;
|
||||
}
|
||||
if ($affRows === 0) {
|
||||
$ltxt = ($lock ? 'lock' : 'unlock' );
|
||||
return PEAR::raiseError(
|
||||
"TransportRecord::setLock: can't $ltxt ({$this->trtok})"
|
||||
);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return type of transport
|
||||
*
|
||||
* @return string
|
||||
* Transport type
|
||||
*/
|
||||
function getTransportType()
|
||||
{
|
||||
if (!$this->recalled) {
|
||||
return PEAR::raiseError("TransportRecord::getTransportType:".
|
||||
" not recalled ({$this->trtok})", TRERR_TOK
|
||||
);
|
||||
}
|
||||
return $this->row['trtype'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Kill transport job (on pause or cancel)
|
||||
*
|
||||
* @return string
|
||||
* Transport type
|
||||
*/
|
||||
function killJob()
|
||||
{
|
||||
if (!$this->recalled) {
|
||||
return PEAR::raiseError("TransportRecord::getTransportType:".
|
||||
" not recalled ({$this->trtok})", TRERR_TOK
|
||||
);
|
||||
}
|
||||
$jobpid = $this->row['jobpid'];
|
||||
$res = system("pkill -P $jobpid", $status);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set state to failed and set error message in transport record
|
||||
*
|
||||
* @param string $txt
|
||||
* base part of error message
|
||||
* @param PEAR_Error $eo
|
||||
* (opt.) error msg can be construct from it
|
||||
* @return mixed
|
||||
* boolean true or error
|
||||
*/
|
||||
function fail($txt='', $eo=NULL)
|
||||
{
|
||||
if (!$this->recalled) {
|
||||
return PEAR::raiseError("TransportRecord::fail:".
|
||||
" not recalled ({$this->trtok})", TRERR_TOK
|
||||
);
|
||||
}
|
||||
$msg = $txt;
|
||||
if (!is_null($eo)) {
|
||||
$msg .= $eo->getMessage()." ".$eo->getUserInfo().
|
||||
" [".$eo->getCode()."]";
|
||||
}
|
||||
$r = $this->setState('failed', array('errmsg'=>$msg));
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Close transport record
|
||||
*
|
||||
* @return mixed
|
||||
* boolean true or error
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
if (!$this->recalled) {
|
||||
return PEAR::raiseError("TransportRecord::close:".
|
||||
" not recalled ({$this->trtok})", TRERR_TOK
|
||||
);
|
||||
}
|
||||
if (TR_LEAVE_CLOSED) {
|
||||
$r = $this->setState('closed');
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
} else {
|
||||
$r = $CC_DBC->query("
|
||||
DELETE FROM ".$CC_CONFIG['transTable']."
|
||||
WHERE trtok='{$this->trtok}'
|
||||
");
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
$this->recalled = FALSE;
|
||||
$this->dropped = TRUE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add field specific envelopes to values (e.g. ' around strings)
|
||||
*
|
||||
* @param string $fldName
|
||||
* field name
|
||||
* @param mixed $fldVal
|
||||
* field value
|
||||
* @return string
|
||||
*/
|
||||
function _getSqlVal($fldName, $fldVal)
|
||||
{
|
||||
switch ($fldName) {
|
||||
case 'realsize':
|
||||
case 'expectedsize':
|
||||
case 'uid':
|
||||
return ("$fldVal"!='' ? "$fldVal" : "NULL");
|
||||
break;
|
||||
case 'gunid':
|
||||
case 'pdtoken':
|
||||
return "x'$fldVal'::bigint";
|
||||
break;
|
||||
default:
|
||||
$fldVal = pg_escape_string($fldVal);
|
||||
return "'$fldVal'";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get title from transported object's metadata (if exists)
|
||||
*
|
||||
* @return string
|
||||
* the title or descriptive string
|
||||
*/
|
||||
function getTitle()
|
||||
{
|
||||
$defStr = 'unknown';
|
||||
$trtype = $this->getTransportType(); //contains recall check
|
||||
if (PEAR::isError($trtype)) {
|
||||
return $trtype;
|
||||
}
|
||||
switch ($trtype) {
|
||||
case "audioclip":
|
||||
case "playlist":
|
||||
case "playlistPkg":
|
||||
case "metadata":
|
||||
$title = $this->gb->bsGetTitle(NULL, $this->row['gunid']);
|
||||
if (is_null($title)) {
|
||||
$title = $defStr;
|
||||
}
|
||||
if (PEAR::isError($title)) {
|
||||
if ($title->getCode() == GBERR_FOBJNEX) {
|
||||
$title = $defStr;
|
||||
} else {
|
||||
return $title;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "searchjob":
|
||||
$title = 'searchjob';
|
||||
break;
|
||||
case "file":
|
||||
$title = ( isset($this->row['localfile']) ?
|
||||
basename($this->row['localfile']) : 'regular file');
|
||||
break;
|
||||
default:
|
||||
$title = $defStr;
|
||||
}
|
||||
return $title;
|
||||
}
|
||||
|
||||
} // class TransportRecord
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
#!/usr/bin/php
|
||||
<?php
|
||||
require_once(dirname(__FILE__).'/../../conf.php');
|
||||
require_once('DB.php');
|
||||
require_once(dirname(__FILE__).'/../LocStor.php');
|
||||
|
||||
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
||||
$CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE);
|
||||
$CC_DBC->setErrorHandling(PEAR_ERROR_RETURN);
|
||||
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
|
||||
$gb = new LocStor();
|
||||
$tr = new Transport($gb);
|
||||
|
||||
$r = $tr->cronMain();
|
||||
if (!$r) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
exit(0);
|
|
@ -1,41 +0,0 @@
|
|||
#!/usr/bin/php
|
||||
<?php
|
||||
require_once(dirname(__FILE__).'/../conf.php');
|
||||
require_once('DB.php');
|
||||
require_once(dirname(__FILE__).'/../LocStor.php');
|
||||
|
||||
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
||||
$CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE);
|
||||
$CC_DBC->setErrorHandling(PEAR_ERROR_RETURN);
|
||||
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
|
||||
$gb = new LocStor();
|
||||
$tr = new Transport($gb);
|
||||
|
||||
$pid = getmypid();
|
||||
list(, $trtok) = $_SERVER['argv'];
|
||||
if (TR_LOG_LEVEL > 1) {
|
||||
$tr->trLog("transportCronJob($pid) start ($trtok)");
|
||||
}
|
||||
|
||||
// 4-pass on job:
|
||||
$cnt = 4;
|
||||
for ($i = 0; $i < $cnt; $i++, sleep(1)) {
|
||||
// run the action:
|
||||
$r = $tr->cronCallMethod($trtok);
|
||||
if (PEAR::isError($r)) {
|
||||
$tr->trLogPear("transportCronJob($pid): ($trtok): ", $r);
|
||||
} else {
|
||||
# $tr->trLog("X transportCronJob: ".var_export($r, TRUE));
|
||||
if ($r !== TRUE) {
|
||||
$tr->trLog("transportCronJob($pid): ($trtok): nonTRUE returned");
|
||||
}
|
||||
}
|
||||
#if(!$r) exit(1);
|
||||
#sleep(2);
|
||||
}
|
||||
|
||||
if (TR_LOG_LEVEL>1) {
|
||||
$tr->trLog("transportCronJob($pid) end ($trtok)");
|
||||
}
|
||||
exit(0);
|
|
@ -1,123 +0,0 @@
|
|||
<?php
|
||||
|
||||
$path = dirname(__FILE__).'/../../library/pear';
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
|
||||
|
||||
require_once(dirname(__FILE__).'/../../../library/propel/runtime/lib/Propel.php');
|
||||
// Initialize Propel with the runtime configuration
|
||||
Propel::init(__DIR__."/../../configs/propel-config.php");
|
||||
|
||||
// Add the generated 'classes' directory to the include path
|
||||
set_include_path(dirname(__FILE__)."/../" . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
require_once('DB.php');
|
||||
require_once('PHPUnit.php');
|
||||
|
||||
require_once(dirname(__FILE__).'/../../configs/conf.php');
|
||||
require_once(dirname(__FILE__).'/../GreenBox.php');
|
||||
require_once(dirname(__FILE__).'/../Playlist.php');
|
||||
|
||||
$tz = ini_get('date.timezone') ? ini_get('date.timezone') : 'America/Toronto';
|
||||
date_default_timezone_set($tz);
|
||||
|
||||
//old database connection still needed to get a session instance.
|
||||
$dsn = $CC_CONFIG['dsn'];
|
||||
$CC_DBC = DB::connect($dsn, TRUE);
|
||||
if (PEAR::isError($CC_DBC)) {
|
||||
echo "ERROR: ".$CC_DBC->getMessage()." ".$CC_DBC->getUserInfo()."\n";
|
||||
exit(1);
|
||||
}
|
||||
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
|
||||
class PlaylistTests extends PHPUnit_TestCase {
|
||||
|
||||
private $greenbox;
|
||||
private $storedFile;
|
||||
private $storedFile2;
|
||||
|
||||
function __construct($name) {
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
function setup() {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$this->greenbox = new GreenBox();
|
||||
|
||||
// Add a file
|
||||
$values = array("filepath" => dirname(__FILE__)."/test10001.mp3");
|
||||
$this->storedFile = StoredFile::Insert($values, false);
|
||||
|
||||
// Add a file
|
||||
$values = array("filepath" => dirname(__FILE__)."/test10002.mp3");
|
||||
$this->storedFile2 = StoredFile::Insert($values, false);
|
||||
|
||||
}
|
||||
|
||||
function testGBCreatePlaylist() {
|
||||
|
||||
$pl = new Playlist();
|
||||
$pl_id = $pl->create("Playlist UnitTest: create ".date("g:i a"));
|
||||
|
||||
if (!is_int($pl_id)) {
|
||||
$this->fail("problems creating playlist.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function testGBLock() {
|
||||
$pl = new Playlist();
|
||||
$pl_id = $pl->create("Playlist Metadata: lock ".date("g:i a"));
|
||||
|
||||
$sessid = Alib::Login('root', 'q');
|
||||
|
||||
$res = $this->greenbox->lockPlaylistForEdit($pl_id, $sessid);
|
||||
|
||||
if($res !== TRUE) {
|
||||
$this->fail("problems locking playlist for editing.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function testGBUnLock() {
|
||||
$pl = new Playlist();
|
||||
$pl_id = $pl->create("Playlist UnitTest: unlock ".date("g:i a"));
|
||||
|
||||
$sessid = Alib::Login('root', 'q');
|
||||
|
||||
$this->greenbox->lockPlaylistForEdit($pl_id, $sessid);
|
||||
$res = $this->greenbox->releaseLockedPlaylist($pl_id, $sessid);
|
||||
|
||||
if($res !== TRUE) {
|
||||
$this->fail("problems unlocking playlist.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function testGBSetPLMetaData() {
|
||||
$pl = new Playlist();
|
||||
$pl_id = $pl->create("Playlist UnitTest: Set Metadata ".date("g:i a"));
|
||||
|
||||
$res = $this->greenbox->setPLMetadataValue($pl_id, "dc:title", "Playlist Unit Test: Updated Title ".date("g:i a"));
|
||||
|
||||
if($res !== TRUE) {
|
||||
$this->fail("problems setting playlist metadata.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function testGBGetPLMetaData() {
|
||||
$pl = new Playlist();
|
||||
$name = "Playlist UnitTest: GetMetadata ".date("g:i a");
|
||||
$pl_id = $pl->create($name);
|
||||
|
||||
$res = $this->greenbox->getPLMetadataValue($pl_id, "dc:title");
|
||||
|
||||
if($res !== $name) {
|
||||
$this->fail("problems getting playlist metadata.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
#!/usr/bin/php -q
|
||||
<?php
|
||||
header("Content-type: text/plain");
|
||||
echo "TEST\n";
|
||||
|
||||
#$gunid = "5716b53127c3761f92fddde3412c7773";
|
||||
$gunid = $argv[1];
|
||||
echo "GUNID: $gunid\n";
|
||||
|
||||
require_once('../../conf.php');
|
||||
require_once('DB.php');
|
||||
require_once('../GreenBox.php');
|
||||
|
||||
$rmd = new StoredFile($gunid, '../stor/'.substr($gunid, 0, 3));
|
||||
$r = $rmd->analyzeFile();
|
||||
|
||||
echo "r=$r (".gettype($r).")\n";
|
||||
if (PEAR::isError($r)) {
|
||||
echo "ERR: ".$r->getMessage()."\n".$r->getUserInfo()."\n";
|
||||
}
|
||||
if (is_array($r)) {
|
||||
print_r($r);
|
||||
}
|
||||
echo"\n";
|
|
@ -13,7 +13,7 @@ error_reporting(E_ALL);
|
|||
set_error_handler("camp_import_error_handler", E_ALL & !E_NOTICE);
|
||||
|
||||
require_once(dirname(__FILE__)."/../application/configs/conf.php");
|
||||
require_once(dirname(__FILE__)."/../application/models/GreenBox.php");
|
||||
require_once(dirname(__FILE__)."/../application/models/StoredFile.php");
|
||||
require_once('DB.php');
|
||||
require_once('Console/Getopt.php');
|
||||
|
||||
|
@ -104,8 +104,6 @@ function camp_import_audio_file($p_filepath, $p_importMode = null, $p_testOnly =
|
|||
return;
|
||||
}
|
||||
|
||||
$greenbox = new GreenBox();
|
||||
|
||||
$fileCount = 0;
|
||||
$duplicates = 0;
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
DROP TABLE cc_backup;
|
||||
DROP TABLE cc_trans;
|
Loading…
Reference in New Issue