Merge branch 'master' of dev.sourcefabric.org:campcaster

Conflicts:
	backend/tests/PlaylistTests.php
This commit is contained in:
naomiaro 2010-11-15 11:01:00 -05:00
commit 65a823561d
32 changed files with 2225 additions and 1997 deletions

View file

@ -288,42 +288,42 @@ class Backup
*/
private function setFilenames()
{
if ($this->loglevel=='debug') {
$this->addLogItem("-I- ".date("Ymd-H:i:s")." setFilenames\n");
}
if (is_array($this->ids)) {
foreach ($this->ids as $i => $item) {
$gunid = $item['gunid'];
// get a stored file object of this gunid
$sf = StoredFile::RecallByGunid($gunid);
if (is_null($sf) || PEAR::isError($sf)) {
return $sf;
}
$lid = BasicStor::IdFromGunid($gunid);
if (($res = BasicStor::Authorize('read', $lid, $this->sessid)) !== TRUE) {
$this->addLogItem("-E- ".date("Ymd-H:i:s")." setFilenames - authorize gunid:$gunid\n");
return PEAR::raiseError('Backup::setFilenames : Authorize ... error.');
}
// if the file is a playlist then it has only a meta file
if (strtolower($sf->md->format) != 'playlist') {
$this->filenames[] = array(
'filename' => $sf->getRealFileName(),
'format' => $sf->md->format
);
}
$this->filenames[] = array(
'filename' => $sf->getRealMetadataFileName(),
'format' => $sf->md->format
);
if ($this->loglevel=='debug') {
$this->addLogItem("-I- ".date("Ymd-H:i:s")." setFilenames - add file: {$sf->md->format}|".$sf->getRealMetadataFileName()."\n");
}
}
return $this->filenames;
} else {
$this->addLogItem("-E- ".date("Ymd-H:i:s")." setFilenames - The IDs variable isn't array.\n");
return PEAR::raiseError('Backup::setFilenames : The IDs variable isn\'t array.');
}
// if ($this->loglevel=='debug') {
// $this->addLogItem("-I- ".date("Ymd-H:i:s")." setFilenames\n");
// }
// if (is_array($this->ids)) {
// foreach ($this->ids as $i => $item) {
// $gunid = $item['gunid'];
// // get a stored file object of this gunid
// $sf = StoredFile::RecallByGunid($gunid);
// if (is_null($sf) || PEAR::isError($sf)) {
// return $sf;
// }
// $lid = BasicStor::IdFromGunid($gunid);
// if (($res = BasicStor::Authorize('read', $lid, $this->sessid)) !== TRUE) {
// $this->addLogItem("-E- ".date("Ymd-H:i:s")." setFilenames - authorize gunid:$gunid\n");
// return PEAR::raiseError('Backup::setFilenames : Authorize ... error.');
// }
// // if the file is a playlist then it has only a meta file
// if (strtolower($sf->md->format) != 'playlist') {
// $this->filenames[] = array(
// 'filename' => $sf->getRealFileName(),
// 'format' => $sf->md->format
// );
// }
// $this->filenames[] = array(
// 'filename' => $sf->getRealMetadataFileName(),
// 'format' => $sf->md->format
// );
// if ($this->loglevel=='debug') {
// $this->addLogItem("-I- ".date("Ymd-H:i:s")." setFilenames - add file: {$sf->md->format}|".$sf->getRealMetadataFileName()."\n");
// }
// }
// return $this->filenames;
// } else {
// $this->addLogItem("-E- ".date("Ymd-H:i:s")." setFilenames - The IDs variable isn't array.\n");
// return PEAR::raiseError('Backup::setFilenames : The IDs variable isn\'t array.');
// }
}

File diff suppressed because it is too large Load diff

View file

@ -1,12 +1,11 @@
<?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("LocStor.php");
if (isset($WHITE_SCREEN_OF_DEATH) && $WHITE_SCREEN_OF_DEATH) {
echo __FILE__.':line '.__LINE__.": Loaded LocStor<br>";
}
require_once("Playlist.php");
require_once("Renderer.php");
require_once('Prefs.php');
@ -51,7 +50,7 @@ class GreenBox extends BasicStor {
if (($res = BasicStor::Authorize('write', null, $p_sessionId)) !== TRUE) {
return $res;
}
$storedFile = $this->bsPutFile($p_values);
$storedFile = StoredFile::Insert($p_values);
return $storedFile;
} // fn putFile
@ -87,12 +86,11 @@ class GreenBox extends BasicStor {
"gunid" => $gunid,
"filetype" => "webstream"
);
$storedFile = $this->bsPutFile($values);
$storedFile = StoredFile::Insert($values);
if (PEAR::isError($storedFile)) {
return $storedFile;
}
$oid = $storedFile->getId();
$r = $this->bsSetMetadataValue($oid, 'ls:url', $url);
$r = $storedFile->setMetadataValue('ls:url', $url);
if (PEAR::isError($r)) {
return $r;
}
@ -152,13 +150,13 @@ class GreenBox extends BasicStor {
* Session id
* @return array
*/
public function analyzeFile($id, $sessid='')
{
if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) {
return $res;
}
return $this->bsAnalyzeFile($id);
} // fn analyzeFile
// public function analyzeFile($id, $sessid='')
// {
// if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) {
// return $res;
// }
// return $this->bsAnalyzeFile($id);
// }
/**
@ -171,13 +169,13 @@ class GreenBox extends BasicStor {
* Session id
* @return boolean|PEAR_Error
*/
public function renameFile($id, $newName, $sessid='')
{
if (($res = BasicStor::Authorize('write', $id, $sessid)) !== TRUE) {
return $res;
}
return $this->bsRenameFile($id, $newName);
} // fn renameFile
// public function renameFile($id, $newName, $sessid='')
// {
// if (($res = BasicStor::Authorize('write', $id, $sessid)) !== TRUE) {
// return $res;
// }
// return $this->bsRenameFile($id, $newName);
// }
/**
@ -193,23 +191,23 @@ class GreenBox extends BasicStor {
* session id
* @return TRUE|PEAR_Error
*/
public function replaceFile($id, $mediaFileLP, $mdataFileLP, $sessid='')
{
if (($res = BasicStor::Authorize('write', $id, $sessid)) !== TRUE) {
return $res;
}
return $this->bsReplaceFile($id, $mediaFileLP, $mdataFileLP);
} // fn replaceFile
// public function replaceFile($id, $mediaFileLP, $mdataFileLP, $sessid='')
// {
// if (($res = BasicStor::Authorize('write', $id, $sessid)) !== TRUE) {
// return $res;
// }
// return $this->bsReplaceFile($id, $mediaFileLP, $mdataFileLP);
// }
/**
* Delete file
*
* @param int $id
* virt.file's local id
* local id
* @param int $sessid
* @param boolean $forced
* if true don't use trash
* if true don't use trash -- now ignored
* @return true|PEAR_Error
*/
public function deleteFile($id, $sessid='', $forced=FALSE)
@ -217,8 +215,9 @@ class GreenBox extends BasicStor {
if (($res = BasicStor::Authorize('write', $id, $sessid)) !== TRUE) {
return $res;
}
return $this->bsDeleteFile($id, $forced);
} // fn deleteFile
$f = StoredFile::Recall($id);
return $f->delete(true);
}
/* ------------------------------------------------------------- metadata */
@ -260,7 +259,8 @@ class GreenBox extends BasicStor {
if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) {
return $res;
}
return $this->bsGetMetadata($id);
$f = StoredFile::Recall($id);
return $f->getMetadata();
}
@ -345,8 +345,9 @@ class GreenBox extends BasicStor {
if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) {
return $res;
}
return $this->bsGetMetadataValue($id, $category);
} // fn getMetadataValue
$f = StoredFile::Recall($id);
return $f->getMetadataValue($category);
}
/**
@ -367,7 +368,8 @@ class GreenBox extends BasicStor {
if (($res = BasicStor::Authorize('write', $id, $sessid)) !== TRUE) {
return $res;
}
return $this->bsSetMetadataValue($id, $category, $value);
$f = StoredFile::Recall($id);
return $f->setMetadataValue($category, $value);
} // fn setMetadataValue
@ -560,7 +562,7 @@ class GreenBox extends BasicStor {
return;
$res = $pl->lock($sessid);
return $res;
}
@ -743,10 +745,6 @@ class GreenBox extends BasicStor {
* current playtime (hh:mm:ss.ssssss)
* @param int $distance
* 0=current clip; 1=next clip ...
* @param string $lang
* xml:lang value for select language version
* @param string $deflang
* xml:lang for default language
* @return array of matching clip info:
* <ul>
* <li>gunid string, global unique id of clip</li>
@ -755,10 +753,9 @@ class GreenBox extends BasicStor {
* <li>duration string, total playlength of clip </li>
* </ul>
*/
public function displayPlaylistClipAtOffset($sessid, $plid, $offset, $distance=0,
$lang=NULL, $deflang=NULL)
public function displayPlaylistClipAtOffset($sessid, $plid, $offset, $distance=0)
{
$pl = StoredFile::RecallByGunid($plid);
$pl = Playlist::Recall($plid);
if (is_null($pl) || PEAR::isError($pl)) {
return $pl;
}
@ -767,23 +764,17 @@ class GreenBox extends BasicStor {
return $res;
}
$res['title'] = NULL;
$id = BasicStor::IdFromGunid($res['gunid']);
if (PEAR::isError($id)) {
return $id;
}
if (!is_null($id)) {
$res['title'] = $this->bsGetMetadataValue($id, "dc:title");
$f = StoredFile::RecallByGunid($res['gunid']);
if (PEAR::isError($f)) {
return $f;
}
$res['title'] = $f->getMetadataValue("dc:title");
$res['playlist_title'] = NULL;
$id = BasicStor::IdFromGunid($plid);
if (PEAR::isError($id)) {
return $id;
}
if (!is_null($id)) {
$res['playlist'] = $this->bsGetMetadataValue($id, "dc:title");
}
$pl = Playlist::Recall($plid);
$res['playlist'] = $pl->getName();
return $res;
} // fn displayPlaylistClipAtOffset
}
/**
@ -1100,7 +1091,7 @@ class GreenBox extends BasicStor {
$fakeFile = $CC_CONFIG['accessDir']."/$token.rss";
if ($token != '123456789abcdeff' || !file_exists($fakeFile)){
return PEAR::raiseError(
"LocStor::renderPlaylistToRSSCheck: invalid token ($token)"
"renderPlaylistToRSSCheck: invalid token ($token)"
);
}
return array(
@ -1592,20 +1583,6 @@ class GreenBox extends BasicStor {
/* ========================================================= info methods */
/**
* Get type of stored file (by local id)
*
* @param int $id
* local id
* @return string|PEAR_Error
*/
public static function getFileType($id)
{
$type = BasicStor::GetObjType($id);
return $type;
} // fn getFileType
/**
* Check if file gunid exists in the storage and
* user have permission to read it
@ -1619,12 +1596,11 @@ class GreenBox extends BasicStor {
*/
public function existsFile($sessid, $gunid, $ftype=NULL)
{
$id = BasicStor::IdFromGunid($gunid);
$ex = $this->bsExistsFile($id, $ftype);
if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) {
return $res;
}
return $ex;
if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) {
return $res;
}
$f = StoredFile::RecallByGunid($gunid);
return $f->existsFile();
} // fn existsFile

View file

@ -1,4 +1,7 @@
<?php
if (isset($WHITE_SCREEN_OF_DEATH) && $WHITE_SCREEN_OF_DEATH) {
echo __FILE__.':line '.__LINE__.": LocStor loading<br>";
}
require_once("BasicStor.php");
if (isset($WHITE_SCREEN_OF_DEATH) && $WHITE_SCREEN_OF_DEATH) {
echo __FILE__.':line '.__LINE__.": Loaded BasicStor<br>";
@ -107,10 +110,7 @@ class LocStor extends BasicStor {
if ($fname == '') {
$fname = "newFile";
}
$res = $this->bsRenameFile($storedFile->id, $fname);
if (PEAR::isError($res)) {
return $res;
}
$storedFile->setName($fname);
return $this->bsOpenPut($chsum, $storedFile->gunid);
}
@ -194,8 +194,7 @@ class LocStor extends BasicStor {
if (is_null($storedFile) || PEAR::isError($storedFile)) {
return $storedFile;
}
$oid = $storedFile->getId();
$r = $this-> bsSetMetadataValue($oid, 'ls:url', $url);
$r = $storedFile->setMetadataValue('ls:url', $url);
if (PEAR::isError($r)) {
return $r;
}
@ -263,7 +262,8 @@ class LocStor extends BasicStor {
if (PEAR::isError($ex)) {
return $ex;
}
$id = BasicStor::IdFromGunid($gunid);
$media = StoredFile::RecallByGunid($gunid);
$id = $media->getId();
if (is_null($id) || !$ex) {
return PEAR::raiseError(
"LocStor::downloadRawAudioDataOpen: gunid not found ($gunid)",
@ -306,7 +306,8 @@ class LocStor extends BasicStor {
{
// $res = $this->existsAudioClip($sessid, $gunid);
// if(PEAR::isError($res)) return $res;
$id = BasicStor::IdFromGunid($gunid);
$media = StoredFile::RecallByGunid($gunid)
$id = $media->getGunid();
if (is_null($id)) {
return PEAR::raiseError(
"LocStor::downloadMetadataOpen: gunid not found ($gunid)"
@ -351,7 +352,7 @@ class LocStor extends BasicStor {
if (($res = BasicStor::Authorize('read', $storedFile->getId(), $sessid)) !== TRUE) {
return $res;
}
$md = $this->bsGetMetadata($storedFile->getId());
$md = $storedFile->getMetadata();
if (PEAR::isError($md)) {
return $md;
}
@ -504,15 +505,14 @@ class LocStor extends BasicStor {
*/
protected function existsFile($sessid, $gunid, $ftype=NULL)
{
$id = BasicStor::IdFromGunid($gunid);
if (is_null($id)) {
return FALSE;
}
if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) {
return $res;
}
$ex = $this->bsExistsFile($id, $ftype);
return $ex;
$f = StoredFile::RecallByGunid($gunid);
if (PEAR::isError($f)) {
return FALSE;
}
return $f->existsFile();
}
@ -540,7 +540,7 @@ class LocStor extends BasicStor {
if (($res = BasicStor::Authorize('write', $storedFile->getId(), $sessid)) !== TRUE) {
return $res;
}
$res = $this->bsDeleteFile($storedFile->getId(), $forced);
$res = $storedFile->delete();
if (PEAR::isError($res)) {
return $res;
}
@ -602,26 +602,14 @@ class LocStor extends BasicStor {
"metadata" => dirname(__FILE__).'/emptyPlaylist.xml',
"gunid" => $playlistId,
"filetype" => "playlist");
// This is all wrong now.
$storedFile = StoredFile::Insert($values);
if (PEAR::isError($storedFile)) {
$res = BasicStor::RemoveObj($oid);
return $storedFile;
}
if ($fname == '') {
$fname = "newFile.xml";
}
$res = $this->bsRenameFile($oid, $fname);
if (PEAR::isError($res)) {
return $res;
}
$res = $storedFile->setState('ready');
if (PEAR::isError($res)) {
return $res;
}
$res = $storedFile->setMime('application/smil');
if (PEAR::isError($res)) {
return $res;
}
$storedFile->setName($fname);
$storedFile->setState('ready');
$storedFile->setMime('application/smil');
return $storedFile->gunid;
}
@ -775,7 +763,7 @@ class LocStor extends BasicStor {
if (($res = BasicStor::Authorize('write', $storedFile->getId(), $sessid)) !== TRUE) {
return $res;
}
$res = $this->bsDeleteFile($storedFile->getId(), $forced);
$res = $storedFile->delete();
if (PEAR::isError($res)) {
return $res;
}
@ -803,32 +791,32 @@ class LocStor extends BasicStor {
* }
*/
public function accessPlaylist($sessid, $playlistId, $recursive=FALSE, $parent='0')
{
if ($recursive) {
require_once("AccessRecur.php");
$r = AccessRecur::accessPlaylist($this, $sessid, $playlistId);
if (PEAR::isError($r)) {
return $r;
}
return $r;
}
$ex = $this->existsPlaylist($sessid, $playlistId);
if (PEAR::isError($ex)) {
return $ex;
}
if (!$ex) {
return PEAR::raiseError(
"LocStor::accessPlaylist: playlist not found ($playlistId)",
GBERR_NOTF
);
}
$id = BasicStor::IdFromGunid($playlistId);
if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) {
return $res;
}
$res = $this->bsOpenDownload($id, 'metadata', $parent);
#unset($res['filename']);
return $res;
// {
// if ($recursive) {
// require_once("AccessRecur.php");
// $r = AccessRecur::accessPlaylist($this, $sessid, $playlistId);
// if (PEAR::isError($r)) {
// return $r;
// }
// return $r;
// }
// $ex = $this->existsPlaylist($sessid, $playlistId);
// if (PEAR::isError($ex)) {
// return $ex;
// }
// if (!$ex) {
// return PEAR::raiseError(
// "LocStor::accessPlaylist: playlist not found ($playlistId)",
// GBERR_NOTF
// );
// }
// $id = BasicStor::IdFromGunid($playlistId);
// if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) {
// return $res;
// }
// $res = $this->bsOpenDownload($id, 'metadata', $parent);
// #unset($res['filename']);
// return $res;
}
@ -953,7 +941,8 @@ class LocStor extends BasicStor {
if (PEAR::isError($res)) {
return $res;
}
return BasicStor::GunidFromId($res);
$media = StoredFile::Recall($id);
return $media->getGunId();
}
@ -1444,7 +1433,7 @@ class LocStor extends BasicStor {
"gunid" => $pars['gunid'],
"filetype" => "audioclip"
);
$storedFile = $this->bsPutFile($values);
$storedFile = StoredFile::Insert($values);
if (PEAR::isError($storedFile)) {
return $storedFile;
}
@ -1462,7 +1451,7 @@ class LocStor extends BasicStor {
"gunid" => $pars['gunid'],
"filetype" => "playlist"
);
$storedFile = $this->bsPutFile($values);
$storedFile = StoredFile::Insert($values);
if (PEAR::isError($storedFile)) {
return $storedFile;
}
@ -1534,97 +1523,99 @@ class LocStor extends BasicStor {
*/
function downloadOpen($sessid, $trtype, $pars=array())
{
global $CC_CONFIG;
switch ($trtype) {
case "unknown":
case "audioclip":
case "metadata":
case "playlist":
case "playlistPkg":
if (!isset($pars['gunid'])) {
return PEAR::raiseError("Archive::downloadOpen: gunid not set");
}
break;
}
$gunid = $pars['gunid'];
// resolve trtype by object type:
if ( ($trtype == 'unknown') || ($trtype == 'playlistPkg') ) {
$trtype2 = BasicStor::GetType($gunid);
if (PEAR::isError($trtype2)) {
return $trtype2;
}
// required with content:
$trtype = ( ($trtype2 == 'playlist') && ($trtype == 'playlistPkg') ?
'playlistPkg' : $trtype2);
//return PEAR::raiseError("Archive::downloadOpen: TT=$trtype TT2=$trtype2 G=$gunid");
}
switch ($trtype) {
case "audioclip":
$res = $this->downloadRawAudioDataOpen($sessid, $gunid);
break;
case "metadata":
$res = $this->downloadMetadataOpen($sessid, $gunid);
break;
case "playlist":
$res = $this->accessPlaylist($sessid, $gunid);
break;
case "playlistPkg":
$res = $this->bsExportPlaylistOpen($gunid);
if (PEAR::isError($res)) {
return $res;
}
$tmpn = tempnam($CC_CONFIG['transDir'], 'plExport_');
$plfpath = "$tmpn.lspl";
copy($res['fname'], $plfpath);
$res = $this->bsExportPlaylistClose($res['token']);
if (PEAR::isError($res)) {
return $res;
}
$fname = "transported_playlist.lspl";
$id = BasicStor::IdFromGunid($gunid);
$acc = BasicStor::bsAccess($plfpath, 'lspl', NULL, 'download');
if (PEAR::isError($acc)) {
return $acc;
}
$url = BasicStor::GetUrlPart()."access/".basename($acc['fname']);
$chsum = md5_file($plfpath);
$size = filesize($plfpath);
$res = array(
'url'=>$url, 'token'=>$acc['token'],
'chsum'=>$chsum, 'size'=>$size,
'filename'=>$fname
);
break;
case "searchjob":
$res = $pars;
break;
case "file":
$res = array();
break;
default:
return PEAR::raiseError("Archive::downloadOpen: NotImpl ($trtype)");
}
if (PEAR::isError($res)) {
return $res;
}
switch ($trtype) {
case "audioclip":
case "metadata":
case "playlist":
case "playlistPkg":
$title = $this->bsGetTitle(NULL, $gunid);
break;
case "searchjob":
$title = 'searchjob';
break;
case "file":
$title = 'regular file';
break;
default:
}
$res['title'] = $title;
$res['trtype'] = $trtype;
return $res;
// global $CC_CONFIG;
// switch ($trtype) {
// case "unknown":
// case "audioclip":
// case "metadata":
// case "playlist":
// case "playlistPkg":
// if (!isset($pars['gunid'])) {
// return PEAR::raiseError("Archive::downloadOpen: gunid not set");
// }
// break;
// }
// $gunid = $pars['gunid'];
// // resolve trtype by object type:
// if ( ($trtype == 'unknown') || ($trtype == 'playlistPkg') ) {
// $media = StoredFile::RecallByGunid($gunid);
// $trtype2 = $media->getType();
// if (PEAR::isError($trtype2)) {
// return $trtype2;
// }
// // required with content:
// $trtype = ( ($trtype2 == 'playlist') && ($trtype == 'playlistPkg') ?
// 'playlistPkg' : $trtype2);
// //return PEAR::raiseError("Archive::downloadOpen: TT=$trtype TT2=$trtype2 G=$gunid");
// }
// switch ($trtype) {
// case "audioclip":
// $res = $this->downloadRawAudioDataOpen($sessid, $gunid);
// break;
// case "metadata":
// $res = $this->downloadMetadataOpen($sessid, $gunid);
// break;
// case "playlist":
// $res = $this->accessPlaylist($sessid, $gunid);
// break;
// case "playlistPkg":
// $res = $this->bsExportPlaylistOpen($gunid);
// if (PEAR::isError($res)) {
// return $res;
// }
// $tmpn = tempnam($CC_CONFIG['transDir'], 'plExport_');
// $plfpath = "$tmpn.lspl";
// copy($res['fname'], $plfpath);
// $res = $this->bsExportPlaylistClose($res['token']);
// if (PEAR::isError($res)) {
// return $res;
// }
// $fname = "transported_playlist.lspl";
// $id = BasicStor::IdFromGunid($gunid);
// $acc = BasicStor::bsAccess($plfpath, 'lspl', NULL, 'download');
// if (PEAR::isError($acc)) {
// return $acc;
// }
// $url = BasicStor::GetUrlPart()."access/".basename($acc['fname']);
// $chsum = md5_file($plfpath);
// $size = filesize($plfpath);
// $res = array(
// 'url'=>$url, 'token'=>$acc['token'],
// 'chsum'=>$chsum, 'size'=>$size,
// 'filename'=>$fname
// );
// break;
// case "searchjob":
// $res = $pars;
// break;
// case "file":
// $res = array();
// break;
// default:
// return PEAR::raiseError("Archive::downloadOpen: NotImpl ($trtype)");
// }
// if (PEAR::isError($res)) {
// return $res;
// }
// switch ($trtype) {
// case "audioclip":
// case "metadata":
// case "playlist":
// case "playlistPkg":
// $f = StoredFile::RecallByGunid($gunid);
// $title = $f->getTitle();
// break;
// case "searchjob":
// $title = 'searchjob';
// break;
// case "file":
// $title = 'regular file';
// break;
// default:
// }
// $res['title'] = $title;
// $res['trtype'] = $trtype;
// return $res;
}

View file

@ -73,65 +73,65 @@ class M3uPlaylist {
*/
function import(&$gb, $aPath, $rPath, &$gunids, $plid, $subjid=NULL)
{
$path = realpath("$aPath/$rPath");
if (FALSE === $path) {
return PEAR::raiseError(
"M3uPlaylist::import: file doesn't exist ($aPath/$rPath)"
);
}
$arr = M3uPlaylist::parse($path);
if (PEAR::isError($arr)) {
return $arr;
}
require_once("Playlist.php");
$pl =& Playlist::create($gb, $plid, "imported_M3U");
if (PEAR::isError($pl)) {
return $pl;
}
$r = $pl->lock($gb, $subjid);
if (PEAR::isError($r)) {
return $r;
}
foreach ($arr as $i => $it) {
list($md, $uri) = preg_split("|\n|", $it);
list($length, $title) = preg_split("|, *|", $md);
// $gunid = StoredFile::CreateGunid();
$gunid = ( isset($gunids[basename($uri)]) ? $gunids[basename($uri)] : NULL);
$acId = BasicStor::IdFromGunid($gunid);
if (PEAR::isError($acId)) {
return $acId;
}
$length = Playlist::secondsToPlaylistTime($length);
$offset = '???';
if (preg_match("|\.([a-zA-Z0-9]+)$|", $uri, $va)) {
switch (strtolower($ext = $va[1])) {
case "lspl":
case "xml":
case "smil":
case "m3u":
$acId = $gb->bsImportPlaylistRaw($gunid,
$aPath, $uri, $ext, $gunids, $subjid);
if (PEAR::isError($acId)) {
break;
}
//no break!
default:
if (is_null($gunid)) {
return PEAR::raiseError(
"M3uPlaylist::import: no gunid");
}
$r = $pl->addAudioClip($acId);
if (PEAR::isError($r)) {
return $r;
}
}
}
}
$r = $pl->unlock($gb);
if (PEAR::isError($r)) {
return $r;
}
return $pl;
// $path = realpath("$aPath/$rPath");
// if (FALSE === $path) {
// return PEAR::raiseError(
// "M3uPlaylist::import: file doesn't exist ($aPath/$rPath)"
// );
// }
// $arr = M3uPlaylist::parse($path);
// if (PEAR::isError($arr)) {
// return $arr;
// }
// require_once("Playlist.php");
// $pl =& Playlist::create($gb, $plid, "imported_M3U");
// if (PEAR::isError($pl)) {
// return $pl;
// }
// $r = $pl->lock($gb, $subjid);
// if (PEAR::isError($r)) {
// return $r;
// }
// foreach ($arr as $i => $it) {
// list($md, $uri) = preg_split("|\n|", $it);
// list($length, $title) = preg_split("|, *|", $md);
// // $gunid = StoredFile::CreateGunid();
// $gunid = ( isset($gunids[basename($uri)]) ? $gunids[basename($uri)] : NULL);
// $acId = BasicStor::IdFromGunid($gunid);
// if (PEAR::isError($acId)) {
// return $acId;
// }
// $length = Playlist::secondsToPlaylistTime($length);
// $offset = '???';
// if (preg_match("|\.([a-zA-Z0-9]+)$|", $uri, $va)) {
// switch (strtolower($ext = $va[1])) {
// case "lspl":
// case "xml":
// case "smil":
// case "m3u":
// $acId = $gb->bsImportPlaylistRaw($gunid,
// $aPath, $uri, $ext, $gunids, $subjid);
// if (PEAR::isError($acId)) {
// break;
// }
// //no break!
// default:
// if (is_null($gunid)) {
// return PEAR::raiseError(
// "M3uPlaylist::import: no gunid");
// }
// $r = $pl->addAudioClip($acId);
// if (PEAR::isError($r)) {
// return $r;
// }
// }
// }
// }
// $r = $pl->unlock($gb);
// if (PEAR::isError($r)) {
// return $r;
// }
// return $pl;
}
/**

View file

@ -68,7 +68,7 @@ class Playlist {
$storedPlaylist = new Playlist();
$storedPlaylist->name = isset($p_values['filename']) ? $p_values['filename'] : date("H:i:s");
$storedPlaylist->mtime = new DateTime("now");
$pl = new CcPlaylist();
$pl->setDbName($storedPlaylist->name);
$pl->setDbState("incomplete");
@ -79,20 +79,30 @@ class Playlist {
$storedPlaylist->setState('ready');
return $storedPlaylist->id;
}
public static function Delete($id) {
$pl = CcPlaylistQuery::create()->findPK($id);
$pl = CcPlaylistQuery::create()->findPK($id);
if($pl === NULL)
return FALSE;
$pl->delete();
return FALSE;
return TRUE;
$pl->delete();
return TRUE;
}
/**
/**
* Delete the file from all playlists.
* @param string $p_fileId
*/
public static function DeleteFileFromAllPlaylists($p_fileId)
{
CcPlaylistcontentsQuery::create()->filterByDbFileId($p_fileId)->delete();
}
/**
* Fetch instance of Playlist object.<br>
*
* @param string $id
@ -126,10 +136,10 @@ class Playlist {
public function setName($p_newname)
{
$pl = CcPlaylistQuery::create()->findPK($this->id);
if($pl === NULL)
return FALSE;
$pl->setDbName($p_newname);
$pl->setDbMtime(new DateTime("now"));
$pl->save();
@ -153,7 +163,7 @@ class Playlist {
$pl = CcPlaylistQuery::create()->findPK($id);
if($pl === NULL)
return FALSE;
return $pl->getDbName();
}
@ -169,18 +179,18 @@ class Playlist {
public function setState($p_state, $p_editedby=NULL)
{
$pl = CcPlaylistQuery::create()->findPK($this->id);
if($pl === NULL)
return FALSE;
return FALSE;
$pl->setDbState($p_state);
$pl->setDbMtime(new DateTime("now"));
$eb = (!is_null($p_editedby) ? $p_editedby : NULL);
$pl->setDbEditedby($eb);
$pl->save();
$this->state = $p_state;
$this->editedby = $p_editedby;
return TRUE;
@ -199,11 +209,11 @@ class Playlist {
if (is_null($id)) {
return $this->state;
}
$pl = CcPlaylistQuery::create()->findPK($id);
$pl = CcPlaylistQuery::create()->findPK($id);
if($pl === NULL)
return FALSE;
return $pl->getDbState();
}
@ -237,15 +247,15 @@ class Playlist {
if (is_null($id)) {
return ($this->currentlyaccessing > 0);
}
$pl = CcPlaylistQuery::create()->findPK($id);
$pl = CcPlaylistQuery::create()->findPK($id);
if (is_null($pl)) {
return PEAR::raiseError(
"StoredPlaylist::isAccessed: invalid id ($id)",
GBERR_FOBJNEX
);
}
return ($pl->getDbCurrentlyaccessing() > 0);
}
@ -309,7 +319,7 @@ class Playlist {
}
private function getNextPos() {
$res = CcPlaylistQuery::create()
->findPK($this->id)
->computeLastPosition();
@ -325,24 +335,21 @@ class Playlist {
* @return array
*/
public function getContents() {
$files;
$files = array();
$rows = CcPlaylistcontentsQuery::create()
->joinWith('CcFiles')
->orderByDbPosition()
->filterByDbPlaylistId($this->id)
->find();
foreach ($rows as $row) {
$files[] = $row->toArray(BasePeer::TYPE_PHPNAME, true, true);
$files[] = $row->toArray(BasePeer::TYPE_PHPNAME, true, true);
}
return $files;
}
public function getLength() {
$res = CcPlaylistQuery::create()
->findPK($this->id)
->computeLength();
@ -426,9 +433,8 @@ class Playlist {
*/
public function addAudioClip($ac_id, $p_position=NULL, $p_fadeIn=NULL, $p_fadeOut=NULL, $p_clipLength=NULL, $p_cuein=NULL, $p_cueout=NULL)
{
$_SESSION['debug'] = "in add";
//get audio clip.
$ac = StoredFile::Recall($ac_id);
if (is_null($ac) || PEAR::isError($ac)) {
@ -451,7 +457,7 @@ class Playlist {
return $p_position;
}
// insert default values if parameter was empty
// insert default values if parameter was empty
$p_cuein = !is_null($p_cuein) ? $p_cuein : '00:00:00.000000';
$p_cueout = !is_null($p_cueout) ? $p_cueout : $acLen;
@ -463,7 +469,7 @@ class Playlist {
$clipLengthS = $clipLengthS - ($acLengthS - self::playlistTimeToSeconds($p_cueout));
}
$p_clipLength = self::secondsToPlaylistTime($clipLengthS);
$res = $this->insertPlaylistElement($this->id, $ac_id, $p_position, $p_clipLength, $p_cuein, $p_cueout, $p_fadeIn, $p_fadeOut);
if (PEAR::isError($res)) {
return $res;
@ -483,12 +489,12 @@ class Playlist {
{
if($pos < 0 || $pos >= $this->getNextPos())
return FALSE;
$row = CcPlaylistcontentsQuery::create()
->filterByDbPlaylistId($this->id)
->filterByDbPosition($pos)
->findOne();
if(is_null($row))
return FALSE;
@ -536,21 +542,21 @@ class Playlist {
public function changeFadeInfo($pos, $fadeIn, $fadeOut)
{
$errArray= array();
if(is_null($pos) || $pos < 0 || $pos >= $this->getNextPos()) {
$errArray["error"]="Invalid position.";
return $errArray;
}
$row = CcPlaylistcontentsQuery::create()
->filterByDbPlaylistId($this->id)
->filterByDbPosition($pos)
->findOne();
$clipLength = $row->getDbCliplength();
if(!is_null($fadeIn) && !is_null($fadeOut)) {
if(Playlist::playlistTimeToSeconds($fadeIn) > Playlist::playlistTimeToSeconds($clipLength)) {
$errArray["error"]="Fade In can't be larger than overall playlength.";
return $errArray;
@ -559,29 +565,29 @@ class Playlist {
$errArray["error"]="Fade Out can't be larger than overall playlength.";
return $errArray;
}
$row->setDbFadein($fadeIn);
$row->setDbFadeout($fadeOut);
}
else if(!is_null($fadeIn)) {
if(Playlist::playlistTimeToSeconds($fadeIn) > Playlist::playlistTimeToSeconds($clipLength)) {
$errArray["error"]="Fade In can't be larger than overall playlength.";
return $errArray;
}
$row->setDbFadein($fadeIn);
}
else if(!is_null($fadeOut)){
if(Playlist::playlistTimeToSeconds($fadeOut) > Playlist::playlistTimeToSeconds($clipLength)) {
$errArray["error"]="Fade Out can't be larger than overall playlength.";
return $errArray;
}
$row->setDbFadeout($fadeOut);
}
$row->save();
return array("fadeIn"=>$fadeIn, "fadeOut"=>$fadeOut);
@ -601,34 +607,34 @@ class Playlist {
public function changeClipLength($pos, $cueIn, $cueOut)
{
$errArray= array();
if(is_null($cueIn) && is_null($cueOut)) {
$errArray["error"]="Cue in and cue out are null.";
return $errArray;
}
if(is_null($pos) || $pos < 0 || $pos >= $this->getNextPos()) {
$errArray["error"]="Invalid position.";
return $errArray;
}
$row = CcPlaylistcontentsQuery::create()
->joinWith(CcFiles)
->filterByDbPlaylistId($this->id)
->filterByDbPosition($pos)
->findOne();
$oldCueIn = $row->getDBCuein();
$oldCueOut = $row->getDbCueout();
$fadeIn = $row->getDbFadein();
$fadeOut = $row->getDbFadeout();
$file = $row->getCcFiles();
$origLength = $file->getDbLength();
if(!is_null($cueIn) && !is_null($cueOut)){
if($cueOut === ""){
$cueOut = $origLength;
}
@ -640,58 +646,58 @@ class Playlist {
$errArray["error"] = "Can't set cue out to be greater than file length.";
return $errArray;
}
$row->setDbCuein($cueIn);
$row->setDbCueout($cueOut);
$row->setDBCliplength(Playlist::secondsToPlaylistTime(Playlist::playlistTimeToSeconds($cueOut)
$row->setDBCliplength(Playlist::secondsToPlaylistTime(Playlist::playlistTimeToSeconds($cueOut)
- Playlist::playlistTimeToSeconds($cueIn)));
}
else if(!is_null($cueIn)) {
if(Playlist::playlistTimeToSeconds($cueIn) > Playlist::playlistTimeToSeconds($oldCueOut)) {
$errArray["error"] = "Can't set cue in to be larger than cue out.";
return $errArray;
}
$row->setDbCuein($cueIn);
$row->setDBCliplength(Playlist::secondsToPlaylistTime(Playlist::playlistTimeToSeconds($oldCueOut)
$row->setDBCliplength(Playlist::secondsToPlaylistTime(Playlist::playlistTimeToSeconds($oldCueOut)
- Playlist::playlistTimeToSeconds($cueIn)));
}
else if(!is_null($cueOut)) {
if($cueOut === ""){
$cueOut = $origLength;
}
if(Playlist::playlistTimeToSeconds($cueOut) < Playlist::playlistTimeToSeconds($oldCueIn)) {
$errArray["error"] ="Can't set cue out to be smaller than cue in.";
return $errArray;
}
if(Playlist::playlistTimeToSeconds($cueOut) > Playlist::playlistTimeToSeconds($origLength)){
$errArray["error"] ="Can't set cue out to be greater than file length.";
return $errArray;
}
$row->setDbCueout($cueOut);
$row->setDBCliplength(Playlist::secondsToPlaylistTime(Playlist::playlistTimeToSeconds($cueOut)
$row->setDBCliplength(Playlist::secondsToPlaylistTime(Playlist::playlistTimeToSeconds($cueOut)
- Playlist::playlistTimeToSeconds($oldCueIn)));
}
$cliplength = $row->getDbCliplength();
if(Playlist::playlistTimeToSeconds($fadeIn) > Playlist::playlistTimeToSeconds($cliplength)){
$fadeIn = $cliplength;
$row->setDbFadein($fadeIn);
}
if(Playlist::playlistTimeToSeconds($fadeOut) > Playlist::playlistTimeToSeconds($cliplength)){
$fadeOut = $cliplength;
$row->setDbFadein($fadeOut);
}
$row->save();
return array("cliplength"=>$cliplength, "cueIn"=>$cueIn, "cueOut"=>$cueOut, "length"=>$this->getLength(),
@ -721,12 +727,12 @@ class Playlist {
public function getPLMetaData($category)
{
$cat = $this->categories[$category];
if($cat === 'length') {
return $this->getLength();
}
$row = CcPlaylistQuery::create()->findPK($this->id);
$row = CcPlaylistQuery::create()->findPK($this->id);
$method = 'get' . $cat;
return $row->$method();
}
@ -735,7 +741,7 @@ class Playlist {
{
$cat = $this->categories[$category];
$row = CcPlaylistQuery::create()->findPK($this->id);
$row = CcPlaylistQuery::create()->findPK($this->id);
$method = 'set' . $cat;
$row->$method($value);
$row->save();
@ -753,7 +759,7 @@ class Playlist {
*/
public function export()
{
}
@ -809,7 +815,7 @@ class Playlist {
*/
public function outputToSmil($toString=TRUE)
{
}
@ -824,7 +830,7 @@ class Playlist {
*/
public function outputToM3u($toString=TRUE)
{
}
@ -839,15 +845,15 @@ class Playlist {
*/
public function outputToRss($toString=TRUE)
{
}
/**
* Get audioClip length and title
*
* @param int $acId
* local id of audioClip inserted to playlist
* @param StoredFile $p_media
*
* @return array with fields:
* <ul>
* <li>acGunid, string - audioClip gunid</li>
@ -856,24 +862,24 @@ class Playlist {
* <li>elType string - audioClip | playlist</li>
* </ul>
*/
private function getAudioClipInfo($ac)
private function getAudioClipInfo($p_media)
{
$ac_id = BasicStor::IdFromGunid($ac->gunid);
$ac_id = $p_media->getId();
$r = $ac->md['dcterms:extent'];
$r = $p_media->getMetadataValue('dcterms:extent');
if (isset($r)) {
$acLen = $r;
} else {
$acLen = '00:00:00.000000';
}
$r = $ac->md['dc:title'];
$r = $p_media->getMetadataValue('dc:title');
if (isset($r)) {
$acTit = $r;
} else {
$acTit = $acGunid;
}
$elType = BasicStor::GetObjType($ac_id);
$elType = $p_media->getType();
$trTbl = array('audioclip'=>'audioClip', 'webstream'=>'audioClip','playlist'=>'playlist');
$elType = $trTbl[$elType];
@ -921,7 +927,7 @@ class Playlist {
$fadeIn = '00:00:00.000';
if(is_null($fadeOut))
$fadeOut = '00:00:00.000';
$row = new CcPlaylistcontents();
$row->setDbPlaylistId($plId);
$row->setDbFileId($fileId);
@ -1384,21 +1390,21 @@ class PlaylistAudioClipExport
public static function OutputToRss(&$pl, $plac, $ind='')
{
$gunid = $plac['attrs']['id'];
$ac = StoredFile::RecallByGunid($gunid);
if (is_null($ac) || PEAR::isError($ac)) {
return $ac;
$id = $plac['attrs']['id'];
$playlist = Playlist::Recall($id);
if (is_null($playlist) || PEAR::isError($playlist)) {
return $playlist;
}
$RADext = $ac->getFileExtension();
$RADext = $playlist->getFileExtension();
if (PEAR::isError($RADext)) {
return $RADext;
}
$title = $pl->gb->bsGetMetadataValue($ac->getId(), 'dc:title');
$desc = $pl->gb->bsGetMetadataValue($ac->getId(), 'dc:description');
$title = $playlist->getName();
$desc = $playlist->getPLMetaData("dc:description");
return array(
'type' => 'audioclip',
'gunid' => $gunid,
'src' => "http://XXX/YY/$gunid.$RADext",
'gunid' => $id,
'src' => "http://XXX/YY/$id.$RADext",
'playlength' => $plac['attrs']['playlength'],
'title' => $title,
'desc' => $desc,

View file

@ -205,36 +205,36 @@ class Renderer
*/
function rnRender2StorageCore(&$gb, $token)
{
$r = BasicStor::bsRelease($token, 'render');
if (PEAR::isError($r)) {
return $r;
}
$realOgg = $r['realFname'];
$owner = $r['owner'];
$gunid = $r['gunid'];
$fileName = 'rendered_playlist';
$id = BasicStor::IdFromGunid($gunid);
if (PEAR::isError($id)) {
return $id;
}
$mdata = '';
foreach (array('dc:title', 'dcterms:extent', 'dc:creator', 'dc:description') as $item) {
$val = $gb->bsGetMetadataValue($id, $item);
$mdata .= " <$item>$val</$item>\n";
}
$mdata = "<audioClip>\n <metadata>\n$mdata </metadata>\n</audioClip>\n";
//$mdata = "<audioClip>\n <metadata>\n$mdata<dcterms:extent>0</dcterms:extent>\n</metadata>\n</audioClip>\n";
$values = array(
"filename" => $fileName,
"filepath" => $realOgg,
"metadata" => $mdata,
"filetype" => "audioclip"
);
$storedFile = $gb->bsPutFile($values);
if (PEAR::isError($storedFile)) {
return $storedFile;
}
return array('gunid' => $storedFile->getGunid());
// $r = BasicStor::bsRelease($token, 'render');
// if (PEAR::isError($r)) {
// return $r;
// }
// $realOgg = $r['realFname'];
// $owner = $r['owner'];
// $gunid = $r['gunid'];
// $fileName = 'rendered_playlist';
// $id = BasicStor::IdFromGunid($gunid);
// if (PEAR::isError($id)) {
// return $id;
// }
// $mdata = '';
// foreach (array('dc:title', 'dcterms:extent', 'dc:creator', 'dc:description') as $item) {
// $val = $gb->bsGetMetadataValue($id, $item);
// $mdata .= " <$item>$val</$item>\n";
// }
// $mdata = "<audioClip>\n <metadata>\n$mdata </metadata>\n</audioClip>\n";
// //$mdata = "<audioClip>\n <metadata>\n$mdata<dcterms:extent>0</dcterms:extent>\n</metadata>\n</audioClip>\n";
// $values = array(
// "filename" => $fileName,
// "filepath" => $realOgg,
// "metadata" => $mdata,
// "filetype" => "audioclip"
// );
// $storedFile = $gb->bsPutFile($values);
// if (PEAR::isError($storedFile)) {
// return $storedFile;
// }
// return array('gunid' => $storedFile->getGunid());
}

View file

@ -265,83 +265,83 @@ class Restore {
* @return mixed
* true if success or PEAR_error
*/
function addFileToStorage($file,$type,$gunid)
{
if ($this->loglevel=='debug') {
$this->addLogItem("-I- ".date("Ymd-H:i:s")." addFileToStorage - file:$file | type:$type | id:$gunid\n");
}
require_once("XmlParser.php");
$tree = XmlParser::parse($file);
$mediaFileLP = str_replace('.xml','',$file);
$mediaFileLP = ($type=='audioClip' && is_file($mediaFileLP))?$mediaFileLP:'';
$ex = $this->gb->existsFile($this->sessid,$gunid);
if (PEAR::isError($ex)) {
$this->addLogItem("-E- ".date("Ymd-H:i:s").
" addFileToStorage - existsFile($gunid) ".
"(".$ex->getMessage()."/".$ex->getUserInfo().")\n"
);
}
if (!PEAR::isError($ex) && $ex) { // file is exists in storage server
//replace it
$id = BasicStor::IdFromGunid($gunid);
$replace = $this->gb->replaceFile(
$id, # id int, virt.file's local id
$mediaFileLP, # mediaFileLP string, local path of media file
$file, # mdataFileLP string, local path of metadata file
$this->sessid); # sessid string, session id
if (PEAR::isError($replace)) {
$this->addLogItem("-E- ".date("Ymd-H:i:s").
" addFileToStorage - replaceFile Error ".
"(".$replace->getMessage()."/".$replace->getUserInfo().")\n"
);
file_put_contents($this->statusFile, 'fault|'.$replace->getMessage()."/".$replace->getUserInfo());
return $replace;
}
#$this->addLogItem("replace it \n");
} else {
// add as new
$name = $tree->children[0]->children[0]->content;
if (empty($name)) {
$name = $tree->attrs['title']->val;
}
if (empty($name)) {
$name = '???';
}
if ($this->loglevel=='debug') {
$this->addLogItem("-I- ".date("Ymd-H:i:s")." putFile\n".
"$name, $mediaFileLP, $file, {$this->sessid}, $gunid, $type \n"
);
}
$values = array(
"filename" => $name,
"filepath" => $mediaFileLP,
"metadata" => $file,
"gunid" => $gunid,
"filetype" => $type
);
$put = $this->gb->putFile($values, $this->sessid);
//$this->addLogItem("add as new \n");
if (PEAR::isError($put)) {
$this->addLogItem("-E- ".date("Ymd-H:i:s").
" addFileToStorage - putFile Error ".
"(".$put->getMessage()."/".$put->getUserInfo().")\n"
."\n---\n".file_get_contents($file)."\n---\n"
);
file_put_contents($this->statusFile, 'fault|'.$put->getMessage()."/".$put->getUserInfo());
//$this->addLogItem("Error Object: ".print_r($put,true)."\n");
return $put;
}
}
$ac = StoredFile::RecallByGunid($gunid);
if (is_null($ac) || PEAR::isError($ac)) {
return $ac;
}
$res = $ac->setState('ready');
if (PEAR::isError($res)) {
return $res;
}
return true;
}
// function addFileToStorage($file,$type,$gunid)
// {
// if ($this->loglevel=='debug') {
// $this->addLogItem("-I- ".date("Ymd-H:i:s")." addFileToStorage - file:$file | type:$type | id:$gunid\n");
// }
// require_once("XmlParser.php");
// $tree = XmlParser::parse($file);
// $mediaFileLP = str_replace('.xml','',$file);
// $mediaFileLP = ($type=='audioClip' && is_file($mediaFileLP))?$mediaFileLP:'';
// $ex = $this->gb->existsFile($this->sessid,$gunid);
// if (PEAR::isError($ex)) {
// $this->addLogItem("-E- ".date("Ymd-H:i:s").
// " addFileToStorage - existsFile($gunid) ".
// "(".$ex->getMessage()."/".$ex->getUserInfo().")\n"
// );
// }
// if (!PEAR::isError($ex) && $ex) { // file is exists in storage server
// //replace it
// $id = BasicStor::IdFromGunid($gunid);
// $replace = $this->gb->replaceFile(
// $id, # id int, virt.file's local id
// $mediaFileLP, # mediaFileLP string, local path of media file
// $file, # mdataFileLP string, local path of metadata file
// $this->sessid); # sessid string, session id
// if (PEAR::isError($replace)) {
// $this->addLogItem("-E- ".date("Ymd-H:i:s").
// " addFileToStorage - replaceFile Error ".
// "(".$replace->getMessage()."/".$replace->getUserInfo().")\n"
// );
// file_put_contents($this->statusFile, 'fault|'.$replace->getMessage()."/".$replace->getUserInfo());
// return $replace;
// }
// #$this->addLogItem("replace it \n");
// } else {
// // add as new
// $name = $tree->children[0]->children[0]->content;
// if (empty($name)) {
// $name = $tree->attrs['title']->val;
// }
// if (empty($name)) {
// $name = '???';
// }
// if ($this->loglevel=='debug') {
// $this->addLogItem("-I- ".date("Ymd-H:i:s")." putFile\n".
// "$name, $mediaFileLP, $file, {$this->sessid}, $gunid, $type \n"
// );
// }
// $values = array(
// "filename" => $name,
// "filepath" => $mediaFileLP,
// "metadata" => $file,
// "gunid" => $gunid,
// "filetype" => $type
// );
// $put = $this->gb->putFile($values, $this->sessid);
// //$this->addLogItem("add as new \n");
// if (PEAR::isError($put)) {
// $this->addLogItem("-E- ".date("Ymd-H:i:s").
// " addFileToStorage - putFile Error ".
// "(".$put->getMessage()."/".$put->getUserInfo().")\n"
// ."\n---\n".file_get_contents($file)."\n---\n"
// );
// file_put_contents($this->statusFile, 'fault|'.$put->getMessage()."/".$put->getUserInfo());
// //$this->addLogItem("Error Object: ".print_r($put,true)."\n");
// return $put;
// }
// }
// $ac = StoredFile::RecallByGunid($gunid);
// if (is_null($ac) || PEAR::isError($ac)) {
// return $ac;
// }
// $res = $ac->setState('ready');
// if (PEAR::isError($res)) {
// return $res;
// }
// return true;
// }
/**

View file

@ -170,7 +170,7 @@ class ScheduleGroup {
}
$sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"]
." WHERE group_id = ".$this->groupId;
return $CC_DBC->query($sql);
}
@ -230,13 +230,32 @@ class Schedule {
return ($count == '0');
}
public function onAddTrackToPlaylist($playlistId, $audioTrackId) {
// public function onAddTrackToPlaylist($playlistId, $audioTrackId) {
//
// }
//
// public function onRemoveTrackFromPlaylist($playlistId, $audioTrackId) {
//
// }
/**
* Return TRUE if file is going to be played in the future.
*
* @param string $p_fileId
*/
public function IsFileScheduledInTheFuture($p_fileId)
{
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT COUNT(*) FROM ".$CC_CONFIG["scheduleTable"]
." WHERE file_id = {$p_fileId} AND starts > NOW()";
$count = $CC_DBC->GetOne($sql);
if (is_numeric($count) && ($count != '0')) {
return TRUE;
} else {
return FALSE;
}
}
public function onRemoveTrackFromPlaylist($playlistId, $audioTrackId) {
}
/**
* Returns array indexed numberically of:
@ -326,7 +345,7 @@ class Schedule {
$t = explode("-", $p_time);
return $t[0]."-".$t[1]."-".$t[2]." ".$t[3].":".$t[4].":00";
}
/**
* Export the schedule in json formatted for pypo (the liquidsoap scheduler)
*
@ -337,29 +356,29 @@ class Schedule {
*/
public static function ExportRangeAsJson($p_fromDateTime, $p_toDateTime)
{
global $CC_CONFIG, $CC_DBC;
$range_start = Schedule::PypoTimeToCcTime($p_fromDateTime);
$range_end = Schedule::PypoTimeToCcTime($p_toDateTime);
$range_dt = array('start' => $range_start, 'end' => $range_end);
global $CC_CONFIG, $CC_DBC;
$range_start = Schedule::PypoTimeToCcTime($p_fromDateTime);
$range_end = Schedule::PypoTimeToCcTime($p_toDateTime);
$range_dt = array('start' => $range_start, 'end' => $range_end);
//var_dump($range_dt);
// Scheduler wants everything in a playlist
$data = Schedule::GetItems($range_start, $range_end, true);
//echo "<pre>";var_dump($data);
$playlists = array();
$playlists = array();
if (is_array($data) && count($data) > 0)
{
foreach ($data as $dx)
{
// Is this the first item in the playlist?
// Is this the first item in the playlist?
$start = $dx['start'];
// chop off subseconds
$start = substr($start, 0, 19);
// Start time is the array key, needs to be in the format "YYYY-MM-DD-HH-mm-ss"
$pkey = Schedule::CcTimeToPypoTime($start);
$timestamp = strtotime($start);
$start = substr($start, 0, 19);
// Start time is the array key, needs to be in the format "YYYY-MM-DD-HH-mm-ss"
$pkey = Schedule::CcTimeToPypoTime($start);
$timestamp = strtotime($start);
$playlists[$pkey]['source'] = "PLAYLIST";
$playlists[$pkey]['x_ident'] = $dx["playlist_id"];
$playlists[$pkey]['subtype'] = '1'; // Just needs to be between 1 and 4 inclusive
@ -372,16 +391,16 @@ class Schedule {
foreach ($playlists as &$playlist)
{
$scheduleGroup = new ScheduleGroup($playlist["schedule_id"]);
$items = $scheduleGroup->getItems();
$scheduleGroup = new ScheduleGroup($playlist["schedule_id"]);
$items = $scheduleGroup->getItems();
$medias = array();
$playlist['subtype'] = '1';
foreach ($items as $item)
{
$storedFile = StoredFile::Recall($item["file_id"]);
$uri = $storedFile->getFileUrl();
$storedFile = StoredFile::Recall($item["file_id"]);
$uri = $storedFile->getFileUrl();
$medias[] = array(
'id' => $item["file_id"],
'id' => $storedFile->getGunid(), //$item["file_id"],
'uri' => $uri,
'fade_in' => $item["fade_in"],
'fade_out' => $item["fade_out"],

View file

@ -2,6 +2,53 @@
require_once("Playlist.php");
require_once(dirname(__FILE__)."/../3rd_party/getid3/var/getid3.php");
require_once("BasicStor.php");
require_once("Schedule.php");
$g_metadata_xml_to_db_mapping = array(
"dc:format" => "format",
"ls:bitrate" => "bit_rate",
"ls:samplerate" => "sample_rate",
"dcterms:extent" => "length",
"dc:title" => "track_title",
"dc:description" => "comments",
"dc:type" => "genre",
"dc:creator" => "artist_name",
"dc:source" => "album_title",
"ls:channels" => "channels",
"ls:filename" => "name",
"ls:year" => "year",
"ls:url" => "url",
"ls:track_num" => "track_number",
"ls:mood" => "mood",
"ls:bpm" => "bpm",
"ls:disc_num" => "disc_number",
"ls:rating" => "rating",
"ls:encoded_by" => "encoded_by",
"dc:publisher" => "label",
"ls:composer" => "composer",
"ls:encoder" => "encoder",
"ls:crc" => "checksum",
"ls:lyrics" => "lyrics",
"ls:orchestra" => "orchestra",
"ls:conductor" => "conductor",
"ls:lyricist" => "lyricist",
"ls:originallyricist" => "original_lyricist",
"ls:radiostationname" => "radio_station_name",
"ls:audiofileinfourl" => "info_url",
"ls:artisturl" => "artist_url",
"ls:audiosourceurl" => "audio_source_url",
"ls:radiostationurl" => "radio_station_url",
"ls:buycdurl" => "buy_this_url",
"ls:isrcnumber" => "isrc_number",
"ls:catalognumber" => "catalog_number",
"ls:originalartist" => "original_artist",
"dc:rights" => "copyright",
"dcterms:temporal" => "report_datetime",
"dcterms:spatial" => "report_location",
"dcterms:entity" => "report_organization",
"dc:subject" => "subject",
"dc:contributor" => "contributor",
"dc:language" => "language");
/**
* Track numbers in metadata tags can come in many formats:
@ -279,7 +326,7 @@ function camp_get_audio_metadata($p_filename, $p_testonly = false)
*/
class StoredFile {
// *** Variable stored in the database ***
// *** Variables stored in the database ***
/**
* @var int
@ -314,7 +361,7 @@ class StoredFile {
private $mime;
/**
* Can be 'playlist' or 'audioclip'.
* Can be 'audioclip'...others might be coming, like webstream.
*
* @var string
*/
@ -381,18 +428,49 @@ class StoredFile {
*/
public function __construct($p_gunid=NULL)
{
global $CC_CONFIG;
global $CC_DBC;
$this->gunid = $p_gunid;
if (empty($this->gunid)) {
$this->gunid = StoredFile::generateGunid();
}
//$this->resDir = $this->_getResDir($this->gunid);
//$this->filepath = "{$this->resDir}/{$this->gunid}";
$this->exists = is_file($this->filepath) && is_readable($this->filepath);
$this->md = $this->loadMetadata();
}
/**
* Convert XML name to database column name. Used for backwards compatibility
* with old code.
*
* @param string $p_category
* @return string|null
*/
public static function xmlCategoryToDbColumn($p_category)
{
global $g_metadata_xml_to_db_mapping;
if (array_key_exists($p_category, $g_metadata_xml_to_db_mapping)) {
return $g_metadata_xml_to_db_mapping[$p_category];
}
return null;
}
/**
* Convert database column name to XML name.
*
* @param string $p_dbColumn
* @return string|null
*/
public static function dbColumnToXmlCatagory($p_dbColumn)
{
global $g_metadata_xml_to_db_mapping;
$str = array_search($p_dbColumn, $g_metadata_xml_to_db_mapping);
// make return value consistent with xmlCategoryToDbColumn()
if ($str === FALSE) {
$str = null;
}
return $str;
}
/**
* GUNID needs to be set before you call this function.
*
@ -417,7 +495,7 @@ class StoredFile {
}
$compatibilityData = array();
foreach ($this->md as $key => $value) {
if ($xmlName = BasicStor::dbColumnToXmlCatagory($key)) {
if ($xmlName = StoredFile::dbColumnToXmlCatagory($key)) {
$compatibilityData[$xmlName] = $value;
}
}
@ -435,7 +513,7 @@ class StoredFile {
global $CC_CONFIG, $CC_DBC;
foreach ($p_values as $category => $value) {
$escapedValue = pg_escape_string($value);
$columnName = BasicStor::xmlCategoryToDbColumn($category);
$columnName = StoredFile::xmlCategoryToDbColumn($category);
if (!is_null($columnName)) {
$sql = "UPDATE ".$CC_CONFIG["filesTable"]
." SET $columnName='$escapedValue'"
@ -529,7 +607,6 @@ class StoredFile {
// Insert record into the database
$escapedName = pg_escape_string($storedFile->name);
$escapedFtype = pg_escape_string($storedFile->ftype);
$CC_DBC->query("BEGIN");
$sql = "INSERT INTO ".$CC_CONFIG['filesTable']
."(id, name, gunid, mime, state, ftype, mtime, md5)"
."VALUES ({$sqlId}, '{$escapedName}', "
@ -537,6 +614,7 @@ class StoredFile {
." '{$storedFile->mime}', 'incomplete', '$escapedFtype',"
." now(), '{$storedFile->md5}')";
//$_SESSION["debug"] .= "sql: ".$sql."<br>";
//echo $sql."\n";
$res = $CC_DBC->query($sql);
if (PEAR::isError($res)) {
$CC_DBC->query("ROLLBACK");
@ -548,16 +626,15 @@ class StoredFile {
$sql = "SELECT currval('".$CC_CONFIG["filesSequence"]."_seq')";
$storedFile->id = $CC_DBC->getOne($sql);
}
BasicStor::bsSetMetadataBatch($storedFile->id, $metadata);
$storedFile->setMetadataBatch($metadata);
// Save media file
$res = $storedFile->addFile($p_values['filepath'], $p_copyMedia);
if (PEAR::isError($res)) {
echo "StoredFile::Insert: ERROR adding file: '".$res->getMessage()."'\n";
$CC_DBC->query("ROLLBACK");
echo "StoredFile::Insert -- addFile(): '".$res->getMessage()."'\n";
return $res;
}
if (empty($storedFile->mime)) {
//echo "StoredFile::Insert: WARNING: Having to recalculate MIME value\n";
$storedFile->setMime($storedFile->getMime());
@ -566,13 +643,6 @@ class StoredFile {
// Save state
$storedFile->setState('ready');
// Commit changes
$res = $CC_DBC->query("COMMIT");
if (PEAR::isError($res)) {
$CC_DBC->query("ROLLBACK");
return $res;
}
// Recall the object to get all the proper values
$storedFile = StoredFile::RecallByGunid($storedFile->gunid);
return $storedFile;
@ -583,21 +653,21 @@ class StoredFile {
* Should be supplied with only ONE parameter, all the rest should
* be NULL.
*
* @param int $p_oid
* local object id in the tree
* @param int $p_id
* local id
* @param string $p_gunid
* global unique id of file
* @param string $p_md5sum
* MD5 sum of the file
* MD5 sum of the file
* @return StoredFile|Playlist|NULL
* Return NULL if the object doesnt exist in the DB.
* Return NULL if the object doesnt exist in the DB.
*/
public static function Recall($p_oid=null, $p_gunid=null, $p_md5sum=null)
public static function Recall($p_id=null, $p_gunid=null, $p_md5sum=null)
{
global $CC_DBC;
global $CC_CONFIG;
if (!is_null($p_oid)) {
$cond = "id='".intval($p_oid)."'";
if (!is_null($p_id)) {
$cond = "id='".intval($p_id)."'";
} elseif (!is_null($p_gunid)) {
$cond = "gunid='$p_gunid'";
} elseif (!is_null($p_md5sum)) {
@ -605,31 +675,16 @@ class StoredFile {
} else {
return null;
}
$sql = "SELECT id, gunid,"
." name, mime, ftype, state, currentlyaccessing, editedby, "
." mtime, md5"
$sql = "SELECT *"
." FROM ".$CC_CONFIG['filesTable']
." WHERE $cond";
//echo $sql;
$row = $CC_DBC->getRow($sql);
if (PEAR::isError($row)) {
if (PEAR::isError($row) || is_null($row)) {
return $row;
}
if (is_null($row)) {
return null;
}
$gunid = $row['gunid'];
if ($row['ftype'] == 'audioclip') {
$storedFile = new StoredFile($gunid);
} elseif ($row['ftype'] == 'playlist') {
$storedFile = new Playlist($gunid);
} else { // fallback
$storedFile = new StoredFile($gunid);
}
$storedFile->loadMetadata();
//$storedFile->gunidBigint = $row['gunid_bigint'];
//$storedFile->md->gunidBigint = $row['gunid_bigint'];
$storedFile->md["gunid"] = $row['gunid'];
$storedFile = new StoredFile($gunid);
$storedFile->id = $row['id'];
$storedFile->name = $row['name'];
$storedFile->mime = $row['mime'];
@ -639,6 +694,7 @@ class StoredFile {
$storedFile->editedby = $row['editedby'];
$storedFile->mtime = $row['mtime'];
$storedFile->md5 = $row['md5'];
$storedFile->filepath = $row['filepath'];
$storedFile->exists = TRUE;
$storedFile->setFormat($row['ftype']);
return $storedFile;
@ -757,6 +813,7 @@ class StoredFile {
$sql = "UPDATE ".$CC_CONFIG["filesTable"]
." SET filepath='{$sqlPath}'"
." WHERE id={$this->id}";
//echo $sql."\n";
$res = $CC_DBC->query($sql);
if (PEAR::isError($res)) {
return $res;
@ -803,25 +860,52 @@ class StoredFile {
/**
* Delete media file from filesystem
* Delete media file from filesystem.
* You cant delete a file if it is being accessed.
* You cant delete a file if it is scheduled to be played in the future.
* The file will be removed from all playlists it is a part of.
*
* @return boolean|PEAR_Error
*/
public function deleteFile()
{
global $CC_CONFIG;
if (!$this->exists) {
return FALSE;
}
if (!file_exists($this->filepath) || @unlink($this->filepath)) {
$this->exists = FALSE;
return TRUE;
} else {
return PEAR::raiseError(
"StoredFile::deleteFile: unlink failed ({$this->filepath})",
GBERR_FILEIO
if ($this->isAccessed()) {
return PEAR::raiseError(
'Cannot delete a file that is currently accessed.'
);
}
return $this->exists;
// Check if the file is scheduled to be played in the future
if (Schedule::IsFileScheduledInTheFuture($this->id)) {
return PEAR::raiseError(
'Cannot delete a file that is scheduled in the future.'
);
}
// Delete it from all playlists
//Playlist::DeleteFileFromAllPlaylists($this->id);
// Only delete the file from filesystem if it has been copied to the
// storage directory. (i.e. dont delete linked files)
if (substr($this->filepath, 0, strlen($CC_CONFIG["storageDir"])) == $CC_CONFIG["storageDir"]) {
// Delete the file
if (!file_exists($this->filepath) || @unlink($this->filepath)) {
$this->exists = FALSE;
return TRUE;
} else {
return PEAR::raiseError(
"StoredFile::deleteFile: unlink failed ({$this->filepath})",
GBERR_FILEIO
);
}
} else {
$this->exists = FALSE;
return TRUE;
}
}
@ -858,7 +942,7 @@ class StoredFile {
"id" => $p_nid,
"filename" => $p_src->name,
"filepath" => $p_src->getRealFileName(),
"filetype" => BasicStor::GetType($p_src->gunid)
"filetype" => $p_src->getType()
);
$storedFile = StoredFile::Insert($values);
if (PEAR::isError($storedFile)) {
@ -884,42 +968,42 @@ class StoredFile {
* 'file'|'string'
* @return TRUE|PEAR_Error
*/
public function replace($p_oid, $p_name, $p_localFilePath='', $p_metadata='',
$p_mdataLoc='file')
{
global $CC_CONFIG, $CC_DBC;
$CC_DBC->query("BEGIN");
$res = $this->setName($p_name);
if (PEAR::isError($res)) {
$CC_DBC->query("ROLLBACK");
return $res;
}
if ($p_localFilePath != '') {
$res = $this->setRawMediaData($p_localFilePath);
} else {
$res = $this->deleteFile();
}
if (PEAR::isError($res)) {
$CC_DBC->query("ROLLBACK");
return $res;
}
if ($p_metadata != '') {
$res = $this->setMetadata($p_metadata, $p_mdataLoc);
} else {
// $res = $this->md->delete();
$res = $this->clearMetadata();
}
if (PEAR::isError($res)) {
$CC_DBC->query("ROLLBACK");
return $res;
}
$res = $CC_DBC->query("COMMIT");
if (PEAR::isError($res)) {
$CC_DBC->query("ROLLBACK");
return $res;
}
return TRUE;
}
// public function replace($p_oid, $p_name, $p_localFilePath='', $p_metadata='',
// $p_mdataLoc='file')
// {
// global $CC_CONFIG, $CC_DBC;
// $CC_DBC->query("BEGIN");
// $res = $this->setName($p_name);
// if (PEAR::isError($res)) {
// $CC_DBC->query("ROLLBACK");
// return $res;
// }
// if ($p_localFilePath != '') {
// $res = $this->setRawMediaData($p_localFilePath);
// } else {
// $res = $this->deleteFile();
// }
// if (PEAR::isError($res)) {
// $CC_DBC->query("ROLLBACK");
// return $res;
// }
// if ($p_metadata != '') {
// $res = $this->setMetadata($p_metadata, $p_mdataLoc);
// } else {
//// $res = $this->md->delete();
// $res = $this->clearMetadata();
// }
// if (PEAR::isError($res)) {
// $CC_DBC->query("ROLLBACK");
// return $res;
// }
// $res = $CC_DBC->query("COMMIT");
// if (PEAR::isError($res)) {
// $CC_DBC->query("ROLLBACK");
// return $res;
// }
// return TRUE;
// }
/**
@ -989,6 +1073,17 @@ class StoredFile {
}
private static function NormalizeExtent($v)
{
if (!preg_match("|^\d{2}:\d{2}:\d{2}.\d{6}$|", $v)) {
$s = Playlist::playlistTimeToSeconds($v);
$t = Playlist::secondsToPlaylistTime($s);
return $t;
}
return $v;
}
/**
* Replace metadata with new XML file
*
@ -1002,25 +1097,110 @@ class StoredFile {
* (NULL = no validation)
* @return boolean
*/
public function setMetadata($p_metadata, $p_mdataLoc='file', $p_format=NULL)
{
global $CC_CONFIG, $CC_DBC;
$CC_DBC->query("BEGIN");
$res = $this->md->replace($p_metadata, $p_mdataLoc, $p_format);
if (PEAR::isError($res)) {
$CC_DBC->query("ROLLBACK");
return $res;
}
// $r = $this->md->regenerateXmlFile();
// if (PEAR::isError($r)) {
// public function setMetadata($p_metadata, $p_mdataLoc='file', $p_format=NULL)
// {
// global $CC_CONFIG, $CC_DBC;
// $CC_DBC->query("BEGIN");
// $res = $this->md->replace($p_metadata, $p_mdataLoc, $p_format);
// if (PEAR::isError($res)) {
// $CC_DBC->query("ROLLBACK");
// return $r;
// return $res;
// }
$res = $CC_DBC->query("COMMIT");
// $res = $CC_DBC->query("COMMIT");
// if (PEAR::isError($res)) {
// return $res;
// }
// return TRUE;
// }
/**
* Set metadata element value
*
* @param string $category
* Metadata element identification (e.g. dc:title)
* @param string $value
* value to store, if NULL then delete record
* @return boolean
*/
public function setMetadataValue($p_category, $p_value)
{
global $CC_CONFIG, $CC_DBC;
if (!is_string($p_category) || is_array($p_value)) {
return FALSE;
}
if ($p_category == 'dcterms:extent') {
$p_value = StoredFile::NormalizeExtent($p_value);
}
$columnName = StoredFile::xmlCategoryToDbColumn($p_category); // Get column name
if (!is_null($columnName)) {
$escapedValue = pg_escape_string($p_value);
$sql = "UPDATE ".$CC_CONFIG["filesTable"]
." SET $columnName='$escapedValue'"
." WHERE id=$p_id";
//var_dump($sql);
$res = $CC_DBC->query($sql);
if (PEAR::isError($res)) {
return $res;
return $res;
}
}
return TRUE;
}
/**
* Set metadata values in 'batch' mode
*
* @param array $values
* array of key/value pairs
* (e.g. 'dc:title'=>'New title')
* @return boolean
*/
public function setMetadataBatch($values)
{
global $CC_CONFIG, $CC_DBC;
if (!is_array($values)) {
$values = array($values);
}
if (count($values) == 0) {
return true;
}
foreach ($values as $category => $oneValue) {
$columnName = StoredFile::xmlCategoryToDbColumn($category);
if (!is_null($columnName)) {
if ($category == 'dcterms:extent') {
$oneValue = StoredFile::NormalizeExtent($oneValue);
}
// Since track_number is an integer, you cannot set
// it to be the empty string, so we NULL it instead.
if ($columnName == 'track_number' && empty($oneValue)) {
$sqlPart = "$columnName = NULL";
} elseif (($columnName == 'length') && (strlen($oneValue) > 8)) {
// Postgres doesnt like it if you try to store really large hour
// values. TODO: We need to fix the underlying problem of getting the
// right values.
$parts = explode(':', $oneValue);
$hour = intval($parts[0]);
if ($hour > 24) {
continue;
} else {
$sqlPart = "$columnName = '$oneValue'";
}
} else {
$escapedValue = pg_escape_string($oneValue);
$sqlPart = "$columnName = '$escapedValue'";
}
$sqlValues[] = $sqlPart;
}
}
if (count($sqlValues)==0) {
return TRUE;
}
$sql = "UPDATE ".$CC_CONFIG["filesTable"]
." SET ".join(",", $sqlValues)
." WHERE id=$id";
$CC_DBC->query($sql);
return TRUE;
}
@ -1034,6 +1214,20 @@ class StoredFile {
return $this->md;
}
/**
* Get one metadata value.
*
* @param string $p_name
* @return string
*/
public function getMetadataValue($p_name)
{
if (isset($this->md[$p_name])){
return $this->md[$p_name];
} else {
return "";
}
}
/**
* Rename stored virtual file
@ -1135,7 +1329,7 @@ class StoredFile {
* Delete stored virtual file
*
* @param boolean $p_deleteFile
* @see MetaData
*
* @return TRUE|PEAR_Error
*/
public function delete($p_deleteFile = true)
@ -1147,10 +1341,6 @@ class StoredFile {
return $res;
}
}
// $res = $this->md->delete();
// if (PEAR::isError($res)) {
// return $res;
// }
$sql = "SELECT to_hex(token)as token, ext "
." FROM ".$CC_CONFIG['accessTable']
." WHERE gunid='{$this->gunid}'";
@ -1178,27 +1368,25 @@ class StoredFile {
return TRUE;
}
/**
* Returns gunIds of the playlists the stored file is in.
* TODO update this to work with new tables.
*/
/*
/**
* Returns an array of playlist objects that this file is a part of.
* @return array
*/
public function getPlaylists() {
global $CC_CONFIG, $CC_DBC;
$_SESSION['delete'] = "gunid: " . $this->gunid;
$sql = "SELECT gunid "
." FROM ".$CC_CONFIG['mdataTable']
." WHERE object='{$this->gunid}'";
$_SESSION['delete'] = $sql;
$playlists = $CC_DBC->getAll($sql);
$sql = "SELECT playlist_id "
." FROM ".$CC_CONFIG['playistTable']
." WHERE file_id='{$this->id}'";
$ids = $CC_DBC->getAll($sql);
$playlists = array();
if (is_array($ids) && count($ids) > 0) {
foreach ($ids as $id) {
$playlists[] = Playlist::Recall($id);
}
}
return $playlists;
}
*/
/**
@ -1314,7 +1502,7 @@ class StoredFile {
if (is_null($indb)) {
return FALSE;
}
if (BasicStor::GetType($this->gunid) == 'audioclip') {
if ($this->ftype == 'audioclip') {
return $this->existsFile();
}
return TRUE;
@ -1394,7 +1582,7 @@ class StoredFile {
*
* @return string
*/
function getMime()
public function getMime()
{
$a = $this->analyzeFile();
if (PEAR::isError($a)) {
@ -1407,6 +1595,20 @@ class StoredFile {
}
/**
* Convenience function.
* @return string
*/
public function getTitle()
{
return $this->md["title"];
}
public function getType()
{
return $this->ftype;
}
/**
* Get storage-internal file state
*
@ -1482,8 +1684,8 @@ class StoredFile {
public function getFileUrl()
{
global $CC_CONFIG;
return "http://".$CC_CONFIG["storageUrlHost"].$CC_CONFIG["storageUrlPath"]
."/stor/".substr($this->gunid, 0, 3)."/{$this->gunid}";
return "http://".$CC_CONFIG["storageUrlHost"]
."api/get_media.php?file_id={$this->gunid}";
}
/**

View file

@ -1417,7 +1417,7 @@ class Transport
"gunid" => $row['gunid'],
"filetype" => "audioclip"
);
$storedFile = $this->gb->bsPutFile($values);
$storedFile = StoredFile::Insert($values);
if (PEAR::isError($storedFile)) {
$mdtrec->setLock(FALSE);
return $storedFile;
@ -1473,7 +1473,7 @@ class Transport
"gunid" => $row['gunid'],
"filetype" => "playlist"
);
$storedFile = $this->gb->bsPutFile($values);
$storedFile = StoredFile::Insert($values);
if (PEAR::isError($storedFile)) {
return $storedFile;
}

View file

@ -1,23 +1,25 @@
<?php
$path = dirname(__FILE__).'/../../3rd_party/php/pear';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
$WHITE_SCREEN_OF_DEATH = true;
require_once(dirname(__FILE__).'/../../conf.php');
require_once('DB.php');
require_once('PHPUnit.php');
//require_once 'BasicStorTests.php';
require_once 'StoredFileTests.php';
//require_once 'SchedulerTests.php';
//require_once 'SchedulerExportTests.php';
require_once 'PlayListTests.php';
require_once 'PlaylistTests.php';
$suite = new PHPUnit_TestSuite("PlayListTests");
//$suite = new PHPUnit_TestSuite("BasicStorTest");
//$suite = new PHPUnit_TestSuite("PlayListTests");
$suite = new PHPUnit_TestSuite("StoredFileTest");
//$suite = new PHPUnit_TestSuite("SchedulerTests");
//$suite->addTestSuite("BasicStorTest");
//$suite->addTestSuite("SchedulerTests");
//$suite->addTestSuite("SchedulerExportTests");
//$suite->addTestSuite("PlayListTests");
$suite->addTestSuite("PlaylistTests");
$result = PHPUnit::run($suite);
echo $result->toString();
?>
?>

View file

@ -10,7 +10,6 @@ Propel::init(dirname(__FILE__)."/../../backend/propel-db/build/conf/campcaster-c
// Add the generated 'classes' directory to the include path
set_include_path(dirname(__FILE__)."/../../backend/propel-db/build/classes" . PATH_SEPARATOR . get_include_path());
//require_once(dirname(__FILE__).'/../../conf.php');
require_once('DB.php');
require_once('PHPUnit.php');
@ -30,7 +29,7 @@ if (PEAR::isError($CC_DBC)) {
}
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
class PlayListTests extends PHPUnit_TestCase {
class PlaylistTests extends PHPUnit_TestCase {
private $greenbox;
@ -41,11 +40,11 @@ class PlayListTests extends PHPUnit_TestCase {
function setup() {
global $CC_CONFIG, $CC_DBC;
$this->greenbox = new GreenBox();
}
function testGBCreatePlaylist() {
$pl = new Playlist();
$pl_id = $pl->create("create");
@ -54,32 +53,32 @@ class PlayListTests extends PHPUnit_TestCase {
return;
}
}
function testGBLock() {
$pl = new Playlist();
$pl_id = $pl->create("lock test");
$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("unlock test");
$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.");
$this->fail("problems unlocking playlist.");
return;
}
}
@ -87,66 +86,77 @@ class PlayListTests extends PHPUnit_TestCase {
function testGBSetPLMetaData() {
$pl = new Playlist();
$pl_id = $pl->create("set meta data test");
$res = $this->greenbox->setPLMetadataValue($pl_id, "dc:title", "A Title");
if($res !== TRUE) {
$this->fail("problems setting playlist metadata.");
return;
}
return;
}
}
function testGBGetPLMetaData() {
$pl = new Playlist();
$name = "Testing";
$pl_id = $pl->create($name);
$res = $this->greenbox->getPLMetadataValue($pl_id, "dc:title");
if($res !== $name) {
$this->fail("problems getting playlist metadata.");
$this->fail("problems getting playlist metadata.");
return;
}
}
}
function testAddAudioClip() {
// 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);
$pl = new Playlist();
$pl_id = $pl->create("Add");
$res = $this->greenbox->addAudioClipToPlaylist($pl_id, '1');
$pl_id = $pl->create("Playlist Unit Test ". uniqid());
$res = $pl->addAudioClip($this->storedFile->getId());
if($res !== TRUE) {
$this->fail("problems adding audioclip to playlist.");
return;
}
return;
}
$res = $pl->addAudioClip($this->storedFile2->getId());
if($res !== TRUE) {
$this->fail("problems adding audioclip 2 to playlist.");
return;
}
}
function testMoveAudioClip() {
$pl = new Playlist();
$pl_id = $pl->create("Move");
$this->greenbox->addAudioClipToPlaylist($pl_id, '1');
$this->greenbox->addAudioClipToPlaylist($pl_id, '2');
$res = $this->greenbox->moveAudioClipInPlaylist($pl_id, 0, 1);
if($res !== TRUE) {
$this->fail("problems moving audioclip in playlist.");
return;
}
}
return;
}
}
function testDeleteAudioClip() {
$pl = new Playlist();
$pl_id = $pl->create("Delete");
$this->greenbox->addAudioClipToPlaylist($pl_id, '1');
$res = $this->greenbox->delAudioClipFromPlaylist($pl_id, 0);
if($res !== TRUE) {
$this->fail("problems deleting audioclip from playlist.");
return;
}
return;
}
}
function testFadeInfo() {
@ -162,7 +172,6 @@ class PlayListTests extends PHPUnit_TestCase {
return;
}
}
}
?>
?>

View file

@ -60,7 +60,7 @@ class SchedulerTests extends PHPUnit_TestCase {
function testAddAndRemovePlaylist() {
// Create a playlist
$playlist = new Playlist();
$playlist->create("Scheduler Unit Test");
$playlist->create("Scheduler Unit Test ".uniqid());
$result = $playlist->addAudioClip($this->storedFile->getId());
$result = $playlist->addAudioClip($this->storedFile2->getId());
$result = $playlist->addAudioClip($this->storedFile2->getId());
@ -76,7 +76,7 @@ class SchedulerTests extends PHPUnit_TestCase {
$this->fail("Wrong number of items added.");
}
$items = $group->getItems();
if ($items[1]["starts"] != "2010-11-11 01:30:34.231") {
if (!is_array($items) || ($items[1]["starts"] != "2010-11-11 01:30:34.231")) {
$this->fail("Wrong start time for 2nd item.");
}

View file

@ -1,7 +1,7 @@
<?php
require_once(dirname(__FILE__).'/../StoredFile.php');
require_once(dirname(__FILE__).'/../BasicStor.php');
require_once(dirname(__FILE__).'/../GreenBox.php');
//require_once(dirname(__FILE__).'/../BasicStor.php');
//require_once(dirname(__FILE__).'/../GreenBox.php');
$dsn = $CC_CONFIG['dsn'];
$CC_DBC = DB::connect($dsn, TRUE);
@ -11,16 +11,13 @@ if (PEAR::isError($CC_DBC)) {
}
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
class BasicStorTest extends PHPUnit_TestCase {
class StoredFileTest extends PHPUnit_TestCase {
private $greenbox;
// function __construct($name) {
// parent::__construct($name);
// }
function __construct($name) {
parent::__construct($name);
}
function setup() {
$this->greenbox = new GreenBox();
}
function testGetAudioMetadata() {
@ -53,11 +50,13 @@ class BasicStorTest extends PHPUnit_TestCase {
}
$values = array("filepath" => $filePath);
$storedFile = $this->greenbox->bsPutFile($values, false);
// Insert and link to file, dont copy it
$storedFile = 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)) {
$this->fail("StoredFile not created correctly. id = ".$id);