Fix for the bug where you could not upload files (the first part of bug #2114). Converted StoredFile into a real class that mapped the database table properly. Renamed some functions to be consistent with each other and with coding standards.

This commit is contained in:
paul 2007-01-11 19:24:45 +00:00
parent c59a73f506
commit 623be37d8a
13 changed files with 392 additions and 322 deletions

View File

@ -33,7 +33,7 @@ class AccessRecur {
return $r; return $r;
} }
$plRes = $r; $plRes = $r;
$r = StoredFile::recallByGunid($plid); $r = StoredFile::RecallByGunid($plid);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }

View File

@ -301,7 +301,7 @@ class Backup
foreach ($this->ids as $i=>$item) { foreach ($this->ids as $i=>$item) {
$gunid = $item['gunid']; $gunid = $item['gunid'];
// get a stored file object of this gunid // get a stored file object of this gunid
$sf = StoredFile::recallByGunid($gunid); $sf = StoredFile::RecallByGunid($gunid);
if (PEAR::isError($sf)) { if (PEAR::isError($sf)) {
return $sf; return $sf;
} }

View File

@ -93,22 +93,22 @@ class BasicStor {
if (PEAR::isError($id)) { if (PEAR::isError($id)) {
return $id; return $id;
} }
$ac = StoredFile::insert($id, $fileName, $storedFile = StoredFile::insert($id, $fileName,
$localFilePath, $metadataFilePath, $mdataLoc, $gunid, $ftype, 'StoredFile', $copyMedia); $localFilePath, $metadataFilePath, $mdataLoc, $gunid, $ftype, 'StoredFile', $copyMedia);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
$res = BasicStor::RemoveObj($id); $res = BasicStor::RemoveObj($id);
// catch constraint violations // catch constraint violations
switch ($ac->getCode()) { switch ($storedFile->getCode()) {
case -3: case -3:
return PEAR::raiseError( return PEAR::raiseError(
"BasicStor::bsPutFile: gunid duplication", "BasicStor::bsPutFile: gunid duplication",
GBERR_GUNID); GBERR_GUNID);
default: default:
return $ac; return $storedFile;
} }
} }
if ($ftype == 'playlist') { if ($ftype == 'playlist') {
$ac->setMime('application/smil'); $storedFile->setMime('application/smil');
} }
return $id; return $id;
} // fn bsPutFile } // fn bsPutFile
@ -129,13 +129,13 @@ class BasicStor {
case "audioclip": case "audioclip":
case "playlist": case "playlist":
case "webstream": case "webstream":
$ac = StoredFile::recall($id); $storedFile = StoredFile::Recall($id);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
// catch nonerror exception: // catch nonerror exception:
//if($ac->getCode() != GBERR_FOBJNEX) //if($storedFile->getCode() != GBERR_FOBJNEX)
return $ac; return $storedFile;
} }
$res = $ac->rename($newName); $res = $storedFile->setName($newName);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
@ -233,19 +233,19 @@ class BasicStor {
*/ */
public function bsReplaceFile($id, $localFilePath, $metadataFilePath, $mdataLoc='file') public function bsReplaceFile($id, $localFilePath, $metadataFilePath, $mdataLoc='file')
{ {
$ac = StoredFile::recall($id); $storedFile = StoredFile::Recall($id);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
if (!empty($metadataFilePath) && if (!empty($metadataFilePath) &&
($mdataLoc!='file' || file_exists($metadataFilePath))) { ($mdataLoc!='file' || file_exists($metadataFilePath))) {
$r = $ac->replaceMetadata($metadataFilePath, $mdataLoc); $r = $storedFile->setMetadata($metadataFilePath, $mdataLoc);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
} }
if (!empty($localFilePath) && file_exists($localFilePath)) { if (!empty($localFilePath) && file_exists($localFilePath)) {
$r = $ac->replaceRawMediaData($localFilePath); $r = $storedFile->setRawMediaData($localFilePath);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -280,15 +280,15 @@ class BasicStor {
case "audioclip": case "audioclip":
case "playlist": case "playlist":
case "webstream": case "webstream":
$ac = StoredFile::recall($id); $storedFile = StoredFile::Recall($id);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
if (is_null($did)) { if (is_null($did)) {
return PEAR::raiseError("BasicStor::bsDeleteFile: ". return PEAR::raiseError("BasicStor::bsDeleteFile: ".
"trash not found", GBERR_NOTF); "trash not found", GBERR_NOTF);
} }
$res = $ac->setState('deleted'); $res = $storedFile->setState('deleted');
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
@ -514,21 +514,21 @@ class BasicStor {
*/ */
public function bsOpenDownload($id, $part='media', $parent='0') public function bsOpenDownload($id, $part='media', $parent='0')
{ {
$ac = StoredFile::recall($id); $storedFile = StoredFile::Recall($id);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
$gunid = $ac->gunid; $gunid = $storedFile->gunid;
switch ($part) { switch ($part) {
case "media": case "media":
$realfile = $ac->getRealFileName(); $realfile = $storedFile->getRealFileName();
$ext = $ac->getFileExtension(); $ext = $storedFile->getFileExtension();
$filename = $ac->getFileName(); $filename = $storedFile->getName();
break; break;
case "metadata": case "metadata":
$realfile = $ac->getRealMetadataFileName(); $realfile = $storedFile->getRealMetadataFileName();
$ext = "xml"; $ext = "xml";
$filename = $ac->getFileName(); $filename = $storedFile->getName();
break; break;
default: default:
return PEAR::raiseError( return PEAR::raiseError(
@ -666,7 +666,7 @@ class BasicStor {
GBERR_PUT); GBERR_PUT);
} else { } else {
// Remember the MD5 sum // Remember the MD5 sum
$storedFile = StoredFile::recallByToken($token); $storedFile = StoredFile::RecallByToken($token);
if (!PEAR::isError($storedFile)) { if (!PEAR::isError($storedFile)) {
$storedFile->setMd5($md5sum); $storedFile->setMd5($md5sum);
} else { } else {
@ -800,11 +800,11 @@ class BasicStor {
*/ */
public function bsReplaceMetadata($id, $mdata, $mdataLoc='file') public function bsReplaceMetadata($id, $mdata, $mdataLoc='file')
{ {
$ac = StoredFile::recall($id); $storedFile = StoredFile::Recall($id);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
return $ac->replaceMetadata($mdata, $mdataLoc); return $storedFile->setMetadata($mdata, $mdataLoc);
} }
@ -817,11 +817,11 @@ class BasicStor {
*/ */
public function bsGetMetadata($id) public function bsGetMetadata($id)
{ {
$ac = StoredFile::recall($id); $storedFile = StoredFile::Recall($id);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
return $ac->getMetadata(); return $storedFile->getMetadata();
} }
@ -842,14 +842,14 @@ class BasicStor {
public function bsGetTitle($id, $gunid=NULL, $lang=NULL, $deflang=NULL) public function bsGetTitle($id, $gunid=NULL, $lang=NULL, $deflang=NULL)
{ {
if (is_null($gunid)) { if (is_null($gunid)) {
$ac = StoredFile::recall($id); $storedFile = StoredFile::Recall($id);
} else { } else {
$ac = StoredFile::recallByGunid($gunid); $storedFile = StoredFile::RecallByGunid($gunid);
} }
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
$r = $ac->md->getMetadataValue('dc:title', $lang, $deflang); $r = $storedFile->md->getMetadataValue('dc:title', $lang, $deflang);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -875,11 +875,11 @@ class BasicStor {
*/ */
// public function bsGetMetadataValue($id, $category, $lang=NULL, $deflang=NULL) // public function bsGetMetadataValue($id, $category, $lang=NULL, $deflang=NULL)
// { // {
// $ac = StoredFile::recall($id); // $storedFile = StoredFile::Recall($id);
// if (PEAR::isError($ac)) { // if (PEAR::isError($storedFile)) {
// return $ac; // return $storedFile;
// } // }
// return $ac->md->getMetadataValue($category, $lang, $deflang); // return $storedFile->md->getMetadataValue($category, $lang, $deflang);
// } // }
@ -899,20 +899,20 @@ class BasicStor {
*/ */
public function bsGetMetadataValue($id, $category = null) public function bsGetMetadataValue($id, $category = null)
{ {
$ac = StoredFile::recall($id); $storedFile = StoredFile::Recall($id);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
if (is_null($category)) { if (is_null($category)) {
return $ac->md->getAllMetadata(); return $storedFile->md->getAllMetadata();
} elseif (is_array($category)) { } elseif (is_array($category)) {
$values = array(); $values = array();
foreach ($category as $tmpCat) { foreach ($category as $tmpCat) {
$values[$tmpCat] = $ac->md->getMetadataValue($tmpCat); $values[$tmpCat] = $storedFile->md->getMetadataValue($tmpCat);
} }
return $values; return $values;
} else { } else {
return $ac->md->getMetadataValue($category); return $storedFile->md->getMetadataValue($category);
} }
} }
@ -939,19 +939,19 @@ class BasicStor {
public function bsSetMetadataValue($id, $category, $value, public function bsSetMetadataValue($id, $category, $value,
$lang=NULL, $mid=NULL, $container='metadata', $regen=TRUE) $lang=NULL, $mid=NULL, $container='metadata', $regen=TRUE)
{ {
$ac = StoredFile::recall($id); $storedFile = StoredFile::Recall($id);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
if ($category == 'dcterms:extent') { if ($category == 'dcterms:extent') {
$value = BasicStor::NormalizeExtent($value); $value = BasicStor::NormalizeExtent($value);
} }
$res = $ac->md->setMetadataValue($category, $value, $lang, $mid, $container); $res = $storedFile->md->setMetadataValue($category, $value, $lang, $mid, $container);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
if ($regen) { if ($regen) {
$r = $ac->md->regenerateXmlFile(); $r = $storedFile->md->regenerateXmlFile();
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -1009,11 +1009,11 @@ class BasicStor {
} }
} }
if ($regen) { if ($regen) {
$ac = StoredFile::recall($id); $storedFile = StoredFile::Recall($id);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
$r = $ac->md->regenerateXmlFile(); $r = $storedFile->md->regenerateXmlFile();
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -1135,7 +1135,7 @@ class BasicStor {
} }
$gunids = array(); $gunids = array();
foreach ($plids as $plid) { foreach ($plids as $plid) {
$pl = Playlist::recallByGunid($plid); $pl = Playlist::RecallByGunid($plid);
if (PEAR::isError($pl)) { if (PEAR::isError($pl)) {
return $pl; return $pl;
} }
@ -1164,11 +1164,11 @@ class BasicStor {
mkdir($tmpdc); mkdir($tmpdc);
} }
foreach ($gunids as $i => $it) { foreach ($gunids as $i => $it) {
$ac = StoredFile::recallByGunid($it['gunid']); $storedFile = StoredFile::RecallByGunid($it['gunid']);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
$MDfname = $ac->md->getFileName(); $MDfname = $storedFile->md->getName();
if (PEAR::isError($MDfname)) { if (PEAR::isError($MDfname)) {
return $MDfname; return $MDfname;
} }
@ -1176,16 +1176,16 @@ class BasicStor {
switch ($it['type']) { switch ($it['type']) {
case "playlist": case "playlist":
require_once("LsPlaylist.php"); require_once("LsPlaylist.php");
$ac = $r = LsPlaylist::recallByGunid($it['gunid']); $storedFile = $r = LsPlaylist::RecallByGunid($it['gunid']);
switch ($type) { switch ($type) {
case "smil": case "smil":
$string = $r = $ac->outputToSmil(); $string = $r = $storedFile->outputToSmil();
break; break;
case "m3u": case "m3u":
$string = $r = $ac->outputToM3u(); $string = $r = $storedFile->outputToM3u();
break; break;
default: default:
$string = $r = $ac->md->genXmlDoc(); $string = $r = $storedFile->md->genXmlDoc();
} }
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
@ -1199,11 +1199,11 @@ class BasicStor {
copy($MDfname, "$tmpdc/{$it['gunid']}.xml"); break; copy($MDfname, "$tmpdc/{$it['gunid']}.xml"); break;
} // switch } // switch
} // if file_exists() } // if file_exists()
$RADfname = $ac->getRealFileName(); $RADfname = $storedFile->getRealFileName();
if (PEAR::isError($RADfname)) { if (PEAR::isError($RADfname)) {
return $RADfname; return $RADfname;
} }
$RADext = $ac->getFileExtension(); $RADext = $storedFile->getFileExtension();
if (PEAR::isError($RADext)) { if (PEAR::isError($RADext)) {
return $RADext; return $RADext;
} }
@ -1475,11 +1475,11 @@ class BasicStor {
*/ */
public function bsAnalyzeFile($id) public function bsAnalyzeFile($id)
{ {
$ac = StoredFile::recall($id); $storedFile = StoredFile::Recall($id);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
$ia = $ac->analyzeFile(); $ia = $storedFile->analyzeFile();
return $ia; return $ia;
} }
@ -1556,22 +1556,22 @@ class BasicStor {
public function bsExistsFile($id, $ftype=NULL, $byGunid=FALSE) public function bsExistsFile($id, $ftype=NULL, $byGunid=FALSE)
{ {
if ($byGunid) { if ($byGunid) {
$ac = StoredFile::recallByGunid($id); $storedFile = StoredFile::RecallByGunid($id);
} else { } else {
$ac = StoredFile::recall($id); $storedFile = StoredFile::Recall($id);
} }
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
// catch some exceptions // catch some exceptions
switch ($ac->getCode()) { switch ($storedFile->getCode()) {
case GBERR_FILENEX: case GBERR_FILENEX:
case GBERR_FOBJNEX: case GBERR_FOBJNEX:
return FALSE; return FALSE;
break; break;
default: default:
return $ac; return $storedFile;
} }
} }
$realFtype = BasicStor::GetType($ac->gunid); $realFtype = BasicStor::GetType($storedFile->gunid);
if (!is_null($ftype) && ( if (!is_null($ftype) && (
($realFtype != $ftype) ($realFtype != $ftype)
// webstreams are subset of audioclips // webstreams are subset of audioclips
@ -1932,15 +1932,15 @@ class BasicStor {
return $p_subjid; return $p_subjid;
} }
} }
$ac = StoredFile::recallByGunid($p_playlistId); $storedFile = StoredFile::RecallByGunid($p_playlistId);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
$state = $ac->getState(); $state = $storedFile->getState();
if ($p_val) { if ($p_val) {
$r = $ac->setState('edited', $p_subjid); $r = $storedFile->setState('edited', $p_subjid);
} else { } else {
$r = $ac->setState('ready', 'NULL'); $r = $storedFile->setState('ready', 'NULL');
} }
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
@ -1959,14 +1959,14 @@ class BasicStor {
*/ */
public function isEdited($p_playlistId) public function isEdited($p_playlistId)
{ {
$ac = StoredFile::recallByGunid($p_playlistId); $storedFile = StoredFile::RecallByGunid($p_playlistId);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
if (!$ac->isEdited($p_playlistId)) { if (!$storedFile->isEdited($p_playlistId)) {
return FALSE; return FALSE;
} }
return $ac->isEditedBy($p_playlistId); return $storedFile->isEditedBy($p_playlistId);
} }
@ -1989,12 +1989,12 @@ class BasicStor {
case "audioclip": case "audioclip":
case "playlist": case "playlist":
case "webstream": case "webstream":
$ac = StoredFile::recall($id); $storedFile = StoredFile::Recall($id);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
$ac2 = StoredFile::CopyOf($ac, $nid); $ac2 = StoredFile::CopyOf($storedFile, $nid);
$ac2->rename(M2tree::GetObjName($nid)); $ac2->setName(M2tree::GetObjName($nid));
break; break;
case "File": case "File":
default: default:
@ -2016,15 +2016,15 @@ class BasicStor {
case "audioclip": case "audioclip":
case "playlist": case "playlist":
case "webstream": case "webstream":
$ac = StoredFile::recall($id); $storedFile = StoredFile::Recall($id);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
if ($ac->isEdited()) { if ($storedFile->isEdited()) {
return PEAR::raiseError( return PEAR::raiseError(
'BasicStor::MoveObj: file is currently being edited, it cannot be moved.'); 'BasicStor::MoveObj: file is currently being edited, it cannot be moved.');
} }
if ($ac->isAccessed()) { if ($storedFile->isAccessed()) {
return PEAR::raiseError( return PEAR::raiseError(
'BasicStor::MoveObj: file is currently in use, it cannot be moved.'); 'BasicStor::MoveObj: file is currently in use, it cannot be moved.');
} }
@ -2082,21 +2082,21 @@ class BasicStor {
case "audioclip": case "audioclip":
case "playlist": case "playlist":
case "webstream": case "webstream":
$ac = StoredFile::recall($id); $storedFile = StoredFile::Recall($id);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
if ($ac->isEdited() && !$forced) { if ($storedFile->isEdited() && !$forced) {
return PEAR::raiseError( return PEAR::raiseError(
'BasicStor::RemoveObj(): is edited' 'BasicStor::RemoveObj(): is edited'
); );
} }
if ($ac->isAccessed() && !$forced) { if ($storedFile->isAccessed() && !$forced) {
return PEAR::raiseError( return PEAR::raiseError(
'BasicStor::RemoveObj(): is accessed' 'BasicStor::RemoveObj(): is accessed'
); );
} }
$ac->delete(); $storedFile->delete();
break; break;
case "File": case "File":
case "Folder": case "Folder":

View File

@ -294,13 +294,13 @@ class GreenBox extends BasicStor {
* session id * session id
* @return boolean|PEAR_Error * @return boolean|PEAR_Error
*/ */
public function replaceMetadata($id, $mdata, $mdataLoc='file', $sessid='') // public function replaceMetadata($id, $mdata, $mdataLoc='file', $sessid='')
{ // {
if (($res = BasicStor::Authorize('write', $id, $sessid)) !== TRUE) { // if (($res = BasicStor::Authorize('write', $id, $sessid)) !== TRUE) {
return $res; // return $res;
} // }
return $this->bsReplaceMetadata($id, $mdata, $mdataLoc); // return $this->bsReplaceMetadata($id, $mdata, $mdataLoc);
} // fn replaceMetadata // } // fn replaceMetadata
/** /**
@ -341,11 +341,11 @@ class GreenBox extends BasicStor {
if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) { if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) {
return $res; return $res;
} }
$ac = StoredFile::recall($id); $storedFile = StoredFile::Recall($id);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
$arr = $ac->md->genPhpArray(); $arr = $storedFile->md->genPhpArray();
$md = FALSE; $md = FALSE;
foreach ($arr['children'] as $i=>$a) { foreach ($arr['children'] as $i=>$a) {
if ($a['elementname'] == 'metadata'){ if ($a['elementname'] == 'metadata'){
@ -588,7 +588,7 @@ class GreenBox extends BasicStor {
public function getPlaylistArray($id, $sessid) public function getPlaylistArray($id, $sessid)
{ {
$gunid = BasicStor::GunidFromId($id); $gunid = BasicStor::GunidFromId($id);
$pl = StoredFile::recall($id); $pl = StoredFile::Recall($id);
if (PEAR::isError($pl)) { if (PEAR::isError($pl)) {
return $pl; return $pl;
} }
@ -635,11 +635,11 @@ class GreenBox extends BasicStor {
if (PEAR::isError($gunid)) { if (PEAR::isError($gunid)) {
return $gunid; return $gunid;
} }
$ac = StoredFile::recallByGunid($gunid); $storedFile = StoredFile::RecallByGunid($gunid);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
$r = $ac->md->regenerateXmlFile(); $r = $storedFile->md->regenerateXmlFile();
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -672,7 +672,7 @@ class GreenBox extends BasicStor {
$fadeIn=NULL, $fadeOut=NULL, $length=NULL, $pause=NULL) $fadeIn=NULL, $fadeOut=NULL, $length=NULL, $pause=NULL)
{ {
require_once"Playlist.php"; require_once"Playlist.php";
$pl = Playlist::recallByToken($token); $pl = Playlist::RecallByToken($token);
if (PEAR::isError($pl)) { if (PEAR::isError($pl)) {
return $pl; return $pl;
} }
@ -713,7 +713,7 @@ class GreenBox extends BasicStor {
public function delAudioClipFromPlaylist($token, $plElGunid, $sessid) public function delAudioClipFromPlaylist($token, $plElGunid, $sessid)
{ {
require_once("Playlist.php"); require_once("Playlist.php");
$pl = Playlist::recallByToken($token); $pl = Playlist::RecallByToken($token);
if (PEAR::isError($pl)) { if (PEAR::isError($pl)) {
return $pl; return $pl;
} }
@ -748,7 +748,7 @@ class GreenBox extends BasicStor {
public function changeFadeInfo($token, $plElGunid, $fadeIn, $fadeOut, $sessid) public function changeFadeInfo($token, $plElGunid, $fadeIn, $fadeOut, $sessid)
{ {
require_once("Playlist.php"); require_once("Playlist.php");
$pl = Playlist::recallByToken($token); $pl = Playlist::RecallByToken($token);
if (PEAR::isError($pl)) { if (PEAR::isError($pl)) {
return $pl; return $pl;
} }
@ -784,7 +784,7 @@ class GreenBox extends BasicStor {
public function moveAudioClipInPlaylist($token, $plElGunid, $newPos, $sessid) public function moveAudioClipInPlaylist($token, $plElGunid, $newPos, $sessid)
{ {
require_once("Playlist.php"); require_once("Playlist.php");
$pl = Playlist::recallByToken($token); $pl = Playlist::RecallByToken($token);
if (PEAR::isError($pl)) { if (PEAR::isError($pl)) {
return $pl; return $pl;
} }
@ -864,7 +864,7 @@ class GreenBox extends BasicStor {
$lang=NULL, $deflang=NULL) $lang=NULL, $deflang=NULL)
{ {
require_once("Playlist.php"); require_once("Playlist.php");
$pl = Playlist::recallByGunid($plid); $pl = Playlist::RecallByGunid($plid);
if (PEAR::isError($pl)) { if (PEAR::isError($pl)) {
return $pl; return $pl;
} }

View File

@ -20,7 +20,12 @@ class LocStor extends BasicStor {
/* ---------------------------------------------------------------- store */ /* ---------------------------------------------------------------- store */
/** /**
* Store or replace existing audio clip * Store or replace existing audio clip.
*
* Sending a file to the storage server is a 3 step process:
* 1) Call storeAudioClipOpen
* 2) Upload the file to the URL specified
* 3) Call storeAudioClipClose
* *
* @param string $sessid * @param string $sessid
* session id * session id
@ -49,27 +54,28 @@ class LocStor extends BasicStor {
} }
// Check if we already have this file. // Check if we already have this file.
if ($duplicate = StoredFile::RecallByMd5($chsum)) { $duplicate = StoredFile::RecallByMd5($chsum);
if (!empty($chsum) && $duplicate) {
return PEAR::raiseError( return PEAR::raiseError(
"LocStor::storeAudioClipOpen: Duplicate file" "LocStor::storeAudioClipOpen: Duplicate file"
." - Matched MD5 against '".$duplicate->getFileName()."'", ." - Matched MD5 ($chsum) against '".$duplicate->getName()."'",
888); 888);
} }
// Check if specified gunid exists. // Check if specified gunid exists.
$ac =& StoredFile::recallByGunid($gunid); $storedFile =& StoredFile::RecallByGunid($gunid);
if (!PEAR::isError($ac)) { if (!PEAR::isError($storedFile)) {
// gunid exists - do replace // gunid exists - do replace
$oid = $ac->getId(); $oid = $storedFile->getId();
if (($res = BasicStor::Authorize('write', $oid, $sessid)) !== TRUE) { if (($res = BasicStor::Authorize('write', $oid, $sessid)) !== TRUE) {
return $res; return $res;
} }
if ($ac->isAccessed()) { if ($storedFile->isAccessed()) {
return PEAR::raiseError( return PEAR::raiseError(
'LocStor::storeAudioClipOpen: is accessed' 'LocStor::storeAudioClipOpen: is accessed'
); );
} }
$res = $ac->replace($oid, $ac->name, '', $metadata, 'string'); $res = $storedFile->replace($oid, $storedFile->name, '', $metadata, 'string');
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
@ -87,17 +93,17 @@ class LocStor extends BasicStor {
if (PEAR::isError($oid)) { if (PEAR::isError($oid)) {
return $oid; return $oid;
} }
$ac =& StoredFile::insert($oid, '', '', $metadata, $storedFile =& StoredFile::insert($oid, '', '', $metadata,
'string', $gunid, $ftype); 'string', $gunid, $ftype);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
$res = BasicStor::RemoveObj($oid); $res = BasicStor::RemoveObj($oid);
return $ac; return $storedFile;
} }
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
} }
$res = $ac->setState('incomplete'); $res = $storedFile->setState('incomplete');
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
@ -108,7 +114,7 @@ class LocStor extends BasicStor {
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
return $this->bsOpenPut($chsum, $ac->gunid); return $this->bsOpenPut($chsum, $storedFile->gunid);
} }
@ -121,29 +127,28 @@ class LocStor extends BasicStor {
*/ */
protected function storeAudioClipClose($sessid, $token) protected function storeAudioClipClose($sessid, $token)
{ {
$ac =& StoredFile::recallByToken($token); $storedFile =& StoredFile::RecallByToken($token);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
$arr = $this->bsClosePut($token); $arr = $this->bsClosePut($token);
if (PEAR::isError($arr)) { if (PEAR::isError($arr)) {
$ac->delete(); $storedFile->delete();
return $arr; return $arr;
} }
$fname = $arr['fname']; $fname = $arr['fname'];
//$owner = $arr['owner']; $res = $storedFile->setRawMediaData($fname);
$res = $ac->replaceRawMediaData($fname);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
if (file_exists($fname)) { if (file_exists($fname)) {
@unlink($fname); @unlink($fname);
} }
$res = $ac->setState('ready'); $res = $storedFile->setState('ready');
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
return $ac->gunid; return $storedFile->gunid;
} }
@ -188,11 +193,11 @@ class LocStor extends BasicStor {
if (PEAR::isError($gunid)) { if (PEAR::isError($gunid)) {
return $gunid; return $gunid;
} }
$ac =& StoredFile::recallByGunid($gunid); $storedFile =& StoredFile::RecallByGunid($gunid);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
$oid = $ac->getId(); $oid = $storedFile->getId();
$r = $this-> bsSetMetadataValue( $r = $this-> bsSetMetadataValue(
$oid, 'ls:url', $url, NULL, NULL, 'metadata'); $oid, 'ls:url', $url, NULL, NULL, 'metadata');
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
@ -215,14 +220,14 @@ class LocStor extends BasicStor {
*/ */
public function accessRawAudioData($sessid, $gunid, $parent='0') public function accessRawAudioData($sessid, $gunid, $parent='0')
{ {
$ac =& StoredFile::recallByGunid($gunid); $storedFile =& StoredFile::RecallByGunid($gunid);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
if (($res = BasicStor::Authorize('read', $ac->getId(), $sessid)) !== TRUE) { if (($res = BasicStor::Authorize('read', $storedFile->getId(), $sessid)) !== TRUE) {
return $res; return $res;
} }
return $ac->accessRawMediaData($parent); return $storedFile->accessRawMediaData($parent);
} }
@ -236,11 +241,11 @@ class LocStor extends BasicStor {
*/ */
public function releaseRawAudioData($sessid, $token) public function releaseRawAudioData($sessid, $token)
{ {
$ac =& StoredFile::recallByToken($token); $storedFile =& StoredFile::RecallByToken($token);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
return $ac->releaseRawMediaData($token); return $storedFile->releaseRawMediaData($token);
} }
@ -343,14 +348,14 @@ class LocStor extends BasicStor {
*/ */
protected function getAudioClip($sessid, $gunid) protected function getAudioClip($sessid, $gunid)
{ {
$ac =& StoredFile::recallByGunid($gunid); $storedFile =& StoredFile::RecallByGunid($gunid);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
if (($res = BasicStor::Authorize('read', $ac->getId(), $sessid)) !== TRUE) { if (($res = BasicStor::Authorize('read', $storedFile->getId(), $sessid)) !== TRUE) {
return $res; return $res;
} }
$md = $this->bsGetMetadata($ac->getId()); $md = $this->bsGetMetadata($storedFile->getId());
if (PEAR::isError($md)) { if (PEAR::isError($md)) {
return $md; return $md;
} }
@ -483,11 +488,11 @@ class LocStor extends BasicStor {
if (PEAR::isError($ex)) { if (PEAR::isError($ex)) {
return $ex; return $ex;
} }
$ac =& StoredFile::recallByGunid($gunid); $storedFile =& StoredFile::RecallByGunid($gunid);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
return $ac->exists(); return $storedFile->exists();
} }
@ -525,17 +530,17 @@ class LocStor extends BasicStor {
*/ */
protected function deleteAudioClip($sessid, $gunid, $forced=FALSE) protected function deleteAudioClip($sessid, $gunid, $forced=FALSE)
{ {
$ac =& StoredFile::recallByGunid($gunid); $storedFile =& StoredFile::RecallByGunid($gunid);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
if ($ac->getCode()==GBERR_FOBJNEX && $forced) { if ($storedFile->getCode()==GBERR_FOBJNEX && $forced) {
return TRUE; return TRUE;
} }
return $ac; return $storedFile;
} }
if (($res = BasicStor::Authorize('write', $ac->getId(), $sessid)) !== TRUE) { if (($res = BasicStor::Authorize('write', $storedFile->getId(), $sessid)) !== TRUE) {
return $res; return $res;
} }
$res = $this->bsDeleteFile($ac->getId(), $forced); $res = $this->bsDeleteFile($storedFile->getId(), $forced);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
@ -554,14 +559,14 @@ class LocStor extends BasicStor {
*/ */
protected function updateAudioClipMetadata($sessid, $gunid, $metadata) protected function updateAudioClipMetadata($sessid, $gunid, $metadata)
{ {
$ac =& StoredFile::recallByGunid($gunid); $storedFile =& StoredFile::RecallByGunid($gunid);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
if (($res = BasicStor::Authorize('write', $ac->getId(), $sessid)) !== TRUE) { if (($res = BasicStor::Authorize('write', $storedFile->getId(), $sessid)) !== TRUE) {
return $res; return $res;
} }
return $ac->replaceMetadata($metadata, 'string'); return $storedFile->setMetadata($metadata, 'string');
} }
@ -601,13 +606,13 @@ class LocStor extends BasicStor {
if (PEAR::isError($oid)) { if (PEAR::isError($oid)) {
return $oid; return $oid;
} }
$ac =& StoredFile::insert($oid, '', '', $storedFile =& StoredFile::insert($oid, '', '',
dirname(__FILE__).'/emptyPlaylist.xml', dirname(__FILE__).'/emptyPlaylist.xml',
'file', $playlistId, 'playlist' 'file', $playlistId, 'playlist'
); );
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
$res = BasicStor::RemoveObj($oid); $res = BasicStor::RemoveObj($oid);
return $ac; return $storedFile;
} }
if ($fname == '') { if ($fname == '') {
$fname = "newFile.xml"; $fname = "newFile.xml";
@ -616,15 +621,15 @@ class LocStor extends BasicStor {
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
$res = $ac->setState('ready'); $res = $storedFile->setState('ready');
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
$res = $ac->setMime('application/smil'); $res = $storedFile->setMime('application/smil');
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
return $ac->gunid; return $storedFile->gunid;
} }
@ -655,11 +660,11 @@ class LocStor extends BasicStor {
'LocStor::editPlaylist: playlist already edited' 'LocStor::editPlaylist: playlist already edited'
); );
} }
$ac =& StoredFile::recallByGunid($playlistId); $storedFile =& StoredFile::RecallByGunid($playlistId);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
$id = $ac->getId(); $id = $storedFile->getId();
if (($res = BasicStor::Authorize('write', $id, $sessid)) !== TRUE) { if (($res = BasicStor::Authorize('write', $id, $sessid)) !== TRUE) {
return $res; return $res;
} }
@ -694,11 +699,11 @@ class LocStor extends BasicStor {
if (PEAR::isError($playlistId)) { if (PEAR::isError($playlistId)) {
return $playlistId; return $playlistId;
} }
$ac =& StoredFile::recallByGunid($playlistId); $storedFile =& StoredFile::RecallByGunid($playlistId);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
$res = $ac->replaceMetadata($newPlaylist, 'string', 'playlist'); $res = $storedFile->setMetadata($newPlaylist, 'string', 'playlist');
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
@ -726,16 +731,16 @@ class LocStor extends BasicStor {
if (PEAR::isError($gunid)) { if (PEAR::isError($gunid)) {
return $gunid; return $gunid;
} }
$ac =& StoredFile::recallByGunid($gunid); $storedFile =& StoredFile::RecallByGunid($gunid);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
$id = $ac->getId(); $id = $storedFile->getId();
$mdata = $ac->getMetadata(); $mdata = $storedFile->getMetadata();
if (PEAR::isError($mdata)) { if (PEAR::isError($mdata)) {
return $mdata; return $mdata;
} }
$res = $ac->replaceMetadata($mdata, 'string'); $res = $storedFile->setMetadata($mdata, 'string');
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
@ -770,14 +775,14 @@ class LocStor extends BasicStor {
GBERR_FILENEX GBERR_FILENEX
); );
} }
$ac =& StoredFile::recallByGunid($playlistId); $storedFile =& StoredFile::RecallByGunid($playlistId);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
if (($res = BasicStor::Authorize('write', $ac->getId(), $sessid)) !== TRUE) { if (($res = BasicStor::Authorize('write', $storedFile->getId(), $sessid)) !== TRUE) {
return $res; return $res;
} }
$res = $this->bsDeleteFile($ac->getId(), $forced); $res = $this->bsDeleteFile($storedFile->getId(), $forced);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }

View File

@ -30,9 +30,9 @@ class LsPlaylist extends Playlist
* optional classname to recall * optional classname to recall
* @return LsPlaylist * @return LsPlaylist
*/ */
public static function &recallByGunid($gunid, $className='LsPlaylist') public static function RecallByGunid($gunid, $className='LsPlaylist')
{ {
return parent::recallByGunid($gunid, $className); return parent::RecallByGunid($gunid, $className);
} }
@ -46,9 +46,9 @@ class LsPlaylist extends Playlist
* optional classname to recall * optional classname to recall
* @return LsPlaylist * @return LsPlaylist
*/ */
public static function &recallByToken($token, $className='LsPlaylist') public static function RecallByToken($token, $className='LsPlaylist')
{ {
return parent::recallByToken($token, $className); return parent::RecallByToken($token, $className);
} }
@ -301,7 +301,7 @@ class LsPlaylistElement {
break; break;
case "playlist": case "playlist":
$gunid = $ac['attrs']['id']; $gunid = $ac['attrs']['id'];
$pl2 = LsPlaylist::recallByGunid($gunid); $pl2 = LsPlaylist::RecallByGunid($gunid);
if (PEAR::isError($pl2)) { if (PEAR::isError($pl2)) {
return $pl2; return $pl2;
} }
@ -374,7 +374,7 @@ class LsPlaylistElement {
break; break;
case "playlist": case "playlist":
$gunid = $ac['attrs']['id']; $gunid = $ac['attrs']['id'];
$pl2 = LsPlaylist::recallByGunid($gunid); $pl2 = LsPlaylist::RecallByGunid($gunid);
if (PEAR::isError($pl2)) { if (PEAR::isError($pl2)) {
return $pl2; return $pl2;
} }
@ -418,7 +418,7 @@ class LsPlaylistElement {
break; break;
case "playlist": case "playlist":
$gunid = $ac['attrs']['id']; $gunid = $ac['attrs']['id'];
$pl2 = LsPlaylist::recallByGunid($gunid); $pl2 = LsPlaylist::RecallByGunid($gunid);
if (PEAR::isError($pl2)) { if (PEAR::isError($pl2)) {
return $pl2; return $pl2;
} }
@ -469,7 +469,7 @@ class LsPlaylistAudioClip
public function outputToSmil(&$pl, $plac, $ind='') public function outputToSmil(&$pl, $plac, $ind='')
{ {
$gunid = $plac['attrs']['id']; $gunid = $plac['attrs']['id'];
$ac = StoredFile::recallByGunid($gunid); $ac = StoredFile::RecallByGunid($gunid);
if (PEAR::isError($ac)) { if (PEAR::isError($ac)) {
return $ac; return $ac;
} }
@ -489,7 +489,7 @@ class LsPlaylistAudioClip
public function outputToM3u(&$pl, $plac, $ind='') public function outputToM3u(&$pl, $plac, $ind='')
{ {
$gunid = $plac['attrs']['id']; $gunid = $plac['attrs']['id'];
$ac = StoredFile::recallByGunid($gunid); $ac = StoredFile::RecallByGunid($gunid);
if (PEAR::isError($ac)) { if (PEAR::isError($ac)) {
return $ac; return $ac;
} }
@ -508,7 +508,7 @@ class LsPlaylistAudioClip
public function outputToRss(&$pl, $plac, $ind='') public function outputToRss(&$pl, $plac, $ind='')
{ {
$gunid = $plac['attrs']['id']; $gunid = $plac['attrs']['id'];
$ac = StoredFile::recallByGunid($gunid); $ac = StoredFile::RecallByGunid($gunid);
if (PEAR::isError($ac)) { if (PEAR::isError($ac)) {
return $ac; return $ac;
} }

View File

@ -28,9 +28,9 @@ class Playlist extends StoredFile {
* @return Playlist * @return Playlist
* instance of Playlist object * instance of Playlist object
*/ */
public static function &recallByGunid($gunid, $className='Playlist') public static function RecallByGunid($gunid, $className='Playlist')
{ {
return parent::recallByGunid($gunid, $className); return parent::RecallByGunid($gunid, $className);
} }
@ -45,9 +45,9 @@ class Playlist extends StoredFile {
* @return Playlist * @return Playlist
* instance of Playlist object * instance of Playlist object
*/ */
public static function &recallByToken($token, $className='Playlist') public static function RecallByToken($token, $className='Playlist')
{ {
return parent::recallByToken($token, $className); return parent::RecallByToken($token, $className);
} }
@ -221,7 +221,7 @@ class Playlist extends StoredFile {
*/ */
private function getAudioClipInfo($acId) private function getAudioClipInfo($acId)
{ {
$ac = StoredFile::recall($acId); $ac = StoredFile::Recall($acId);
if (PEAR::isError($ac)) { if (PEAR::isError($ac)) {
return $ac; return $ac;
} }
@ -956,7 +956,7 @@ class Playlist extends StoredFile {
if ($found) { // we've found offset if ($found) { // we've found offset
switch ($el['type']) { switch ($el['type']) {
case "playlist": case "playlist":
$pl = Playlist::recallByGunid($acGunid); $pl = Playlist::RecallByGunid($acGunid);
if (PEAR::isError($pl)) { if (PEAR::isError($pl)) {
return $pl; return $pl;
} }
@ -1033,7 +1033,7 @@ class Playlist extends StoredFile {
extract($el); // acLen, elOffset, acGunid, fadeIn, fadeOut, playlist extract($el); // acLen, elOffset, acGunid, fadeIn, fadeOut, playlist
switch ($el['type']) { switch ($el['type']) {
case "playlist": case "playlist":
$pl = Playlist::recallByGunid($acGunid); $pl = Playlist::RecallByGunid($acGunid);
if (PEAR::isError($pl)) { if (PEAR::isError($pl)) {
return $pl; return $pl;
} }
@ -1105,7 +1105,7 @@ class Playlist extends StoredFile {
if ($this->gunid == $insGunid) { if ($this->gunid == $insGunid) {
return TRUE; return TRUE;
} }
$pl = Playlist::recallByGunid($insGunid); $pl = Playlist::RecallByGunid($insGunid);
if (PEAR::isError($pl)) { if (PEAR::isError($pl)) {
return $pl; return $pl;
} }

View File

@ -37,7 +37,7 @@ class Renderer
{ {
global $CC_CONFIG; global $CC_CONFIG;
// recall playlist: // recall playlist:
$pl = LsPlaylist::recallByGunid($plid); $pl = LsPlaylist::RecallByGunid($plid);
if (PEAR::isError($pl)) { if (PEAR::isError($pl)) {
return $pl; return $pl;
} }
@ -237,7 +237,7 @@ class Renderer
if (PEAR::isError($id)) { if (PEAR::isError($id)) {
return $id; return $id;
} }
$ac = StoredFile::recall($id); $ac = StoredFile::Recall($id);
if (PEAR::isError($ac)) { if (PEAR::isError($ac)) {
return $ac; return $ac;
} }

View File

@ -333,7 +333,7 @@ class Restore {
return $put; return $put;
} }
} }
$ac = StoredFile::recallByGunid($gunid); $ac = StoredFile::RecallByGunid($gunid);
if (PEAR::isError($ac)) { if (PEAR::isError($ac)) {
return $ac; return $ac;
} }

View File

@ -75,7 +75,7 @@ class SmilPlaylist {
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
$r = $pl->replaceMetadata($lspl, 'string', 'playlist'); $r = $pl->setMetadata($lspl, 'string', 'playlist');
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -262,7 +262,7 @@ class SmilPlaylistAudioElement {
} }
//break; //break;
default: default:
$ac = StoredFile::recallByGunid($gunid); $ac = StoredFile::RecallByGunid($gunid);
if (PEAR::isError($ac)) { if (PEAR::isError($ac)) {
return $ac; return $ac;
} }

View File

@ -232,6 +232,14 @@ function camp_get_audio_metadata($p_filename, $p_testonly = false)
* @see MetaData * @see MetaData
*/ */
class StoredFile { class StoredFile {
// *** Variable stored in the database ***
/**
* @var int
*/
private $id;
/** /**
* Unique ID for the file. This is stored in HEX format. It is * Unique ID for the file. This is stored in HEX format. It is
* converted to a bigint whenever it is used in a database call. * converted to a bigint whenever it is used in a database call.
@ -240,6 +248,58 @@ class StoredFile {
*/ */
public $gunid; public $gunid;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $mime;
/**
* Can be 'playlist' or 'audioclip'.
*
* @var string
*/
private $ftype;
/**
* Can be 'ready', 'edited', 'incomplete'.
*
* @var string
*/
private $state;
/**
* @var int
*/
private $currentlyaccessing;
/**
* @var int
*/
private $editedby;
/**
* @var timestamp
*/
private $mtime;
/**
* @var string
*/
private $md5;
// *** Variables NOT stored in the database ***
/**
* @var string
*/
private $filepath;
/** /**
* Directory where the file is located. * Directory where the file is located.
* *
@ -247,11 +307,6 @@ class StoredFile {
*/ */
private $resDir; private $resDir;
/**
* @var string
*/
private $fname;
/** /**
* @var boolean * @var boolean
*/ */
@ -278,8 +333,8 @@ class StoredFile {
$this->gunid = StoredFile::CreateGunid(); $this->gunid = StoredFile::CreateGunid();
} }
$this->resDir = $this->_getResDir($this->gunid); $this->resDir = $this->_getResDir($this->gunid);
$this->fname = $this->makeFileName(); $this->filepath = $this->makeFileName();
$this->exists = is_file($this->fname) && is_readable($this->fname); $this->exists = is_file($this->filepath) && is_readable($this->filepath);
$this->md = new MetaData($this->gunid, $this->resDir); $this->md = new MetaData($this->gunid, $this->resDir);
} }
@ -314,12 +369,12 @@ class StoredFile {
if (PEAR::isError($storedFile)) { if (PEAR::isError($storedFile)) {
return $storedFile; return $storedFile;
} }
$storedFile->fname = $filename; $storedFile->name = $filename;
$storedFile->id = $oid; $storedFile->id = $oid;
$storedFile->mime = "unknown"; $storedFile->mime = "unknown";
$emptyState = TRUE; $emptyState = TRUE;
if ($storedFile->fname == '') { if ($storedFile->name == '') {
$storedFile->fname = $storedFile->gunid; $storedFile->name = $storedFile->gunid;
} }
$storedFile->exists = FALSE; $storedFile->exists = FALSE;
if (file_exists($localFilePath)) { if (file_exists($localFilePath)) {
@ -401,7 +456,7 @@ class StoredFile {
* global unique id of file * global unique id of file
* @return StoredFile * @return StoredFile
*/ */
public static function recall($oid='', $gunid='') public static function Recall($oid='', $gunid='')
{ {
global $CC_DBC; global $CC_DBC;
global $CC_CONFIG; global $CC_CONFIG;
@ -410,9 +465,8 @@ class StoredFile {
: "gunid=x'$gunid'::bigint" : "gunid=x'$gunid'::bigint"
); );
$row = $CC_DBC->getRow(" $row = $CC_DBC->getRow("
SELECT id, to_hex(gunid)as gunid, mime, name, ftype SELECT id, to_hex(gunid)as gunid, name, mime, ftype, state, currentlyaccessing, editedby, mtime, md5
FROM ".$CC_CONFIG['filesTable']." WHERE $cond FROM ".$CC_CONFIG['filesTable']." WHERE $cond");
");
if (PEAR::isError($row)) { if (PEAR::isError($row)) {
return $row; return $row;
} }
@ -425,10 +479,16 @@ class StoredFile {
} }
$gunid = StoredFile::NormalizeGunid($row['gunid']); $gunid = StoredFile::NormalizeGunid($row['gunid']);
$storedFile = new StoredFile($gunid); $storedFile = new StoredFile($gunid);
$storedFile->mime = $row['mime'];
$storedFile->fname = $row['name'];
$storedFile->exists = TRUE;
$storedFile->id = $row['id']; $storedFile->id = $row['id'];
$storedFile->name = $row['name'];
$storedFile->mime = $row['mime'];
$storedFile->ftype = $row['ftype'];
$storedFile->state = $row['state'];
$storedFile->currentlyaccessing = $row['currentlyaccessing'];
$storedFile->editedby = $row['editedby'];
$storedFile->mtime = $row['mtime'];
$storedFile->md5 = $row['md5'];
$storedFile->exists = TRUE;
$storedFile->md->setFormat($row['ftype']); $storedFile->md->setFormat($row['ftype']);
return $storedFile; return $storedFile;
} }
@ -442,9 +502,9 @@ class StoredFile {
* global unique id of file * global unique id of file
* @return StoredFile * @return StoredFile
*/ */
public static function recallByGunid($gunid='') public static function RecallByGunid($gunid='')
{ {
return StoredFile::recall('', $gunid); return StoredFile::Recall('', $gunid);
} }
@ -456,7 +516,7 @@ class StoredFile {
* access token * access token
* @return StoredFile * @return StoredFile
*/ */
public static function recallByToken($token) public static function RecallByToken($token)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$gunid = $CC_DBC->getOne(" $gunid = $CC_DBC->getOne("
@ -468,10 +528,10 @@ class StoredFile {
} }
if (is_null($gunid)) { if (is_null($gunid)) {
return PEAR::raiseError( return PEAR::raiseError(
"StoredFile::recallByToken: invalid token ($token)", GBERR_AOBJNEX); "StoredFile::RecallByToken: invalid token ($token)", GBERR_AOBJNEX);
} }
$gunid = StoredFile::NormalizeGunid($gunid); $gunid = StoredFile::NormalizeGunid($gunid);
return StoredFile::recall('', $gunid); return StoredFile::Recall('', $gunid);
} }
@ -493,7 +553,7 @@ class StoredFile {
} }
if ($gunid) { if ($gunid) {
$gunid = StoredFile::NormalizeGunid($gunid); $gunid = StoredFile::NormalizeGunid($gunid);
return StoredFile::recall('', $gunid); return StoredFile::Recall('', $gunid);
} else { } else {
return FALSE; return FALSE;
} }
@ -509,21 +569,21 @@ class StoredFile {
* copy the media file if true, make symlink if false * copy the media file if true, make symlink if false
* @return TRUE|PEAR_Error * @return TRUE|PEAR_Error
*/ */
function addFile($localFilePath, $copyMedia=TRUE) public function addFile($localFilePath, $copyMedia=TRUE)
{ {
if ($this->exists) { if ($this->exists) {
return FALSE; return FALSE;
} }
// for files downloaded from archive: // for files downloaded from archive:
if ($localFilePath == $this->fname) { if ($localFilePath == $this->filepath) {
$this->exists = TRUE; $this->exists = TRUE;
return TRUE; return TRUE;
} }
umask(0002); umask(0002);
if ($copyMedia) { if ($copyMedia) {
$r = @copy($localFilePath, $this->fname); $r = @copy($localFilePath, $this->filepath);
} else { } else {
$r = @symlink($localFilePath, $this->fname); $r = @symlink($localFilePath, $this->filepath);
} }
if ( $r ) { if ( $r ) {
$this->exists = TRUE; $this->exists = TRUE;
@ -533,7 +593,7 @@ class StoredFile {
$this->exists = FALSE; $this->exists = FALSE;
return PEAR::raiseError( return PEAR::raiseError(
"StoredFile::addFile: file save failed". "StoredFile::addFile: file save failed".
" ($localFilePath, {$this->fname})",GBERR_FILEIO " ($localFilePath, {$this->filepath})",GBERR_FILEIO
); );
} }
} }
@ -546,15 +606,19 @@ class StoredFile {
* local path * local path
* @return TRUE|PEAR_Error * @return TRUE|PEAR_Error
*/ */
function replaceFile($localFilePath) public function replaceFile($localFilePath)
{ {
if ($this->exists) { // Dont do anything if the source and destination files are
$r = $this->delete(); // the same.
} else { if ($this->name == $localFilePath) {
$r = NULL; return TRUE;
} }
if (PEAR::isError($r)) {
return $r; if ($this->exists) {
$r = $this->deleteFile();
if (PEAR::isError($r)) {
return $r;
}
} }
return $this->addFile($localFilePath); return $this->addFile($localFilePath);
} }
@ -565,7 +629,7 @@ class StoredFile {
* *
* @return boolean * @return boolean
*/ */
function existsFile() public function existsFile()
{ {
return $this->exists; return $this->exists;
} }
@ -576,17 +640,17 @@ class StoredFile {
* *
* @return boolean|PEAR_Error * @return boolean|PEAR_Error
*/ */
function deleteFile() public function deleteFile()
{ {
if (!$this->exists) { if (!$this->exists) {
return FALSE; return FALSE;
} }
if (@unlink($this->fname)) { if (!file_exists($this->filepath) || @unlink($this->filepath)) {
$this->exists = FALSE; $this->exists = FALSE;
return TRUE; return TRUE;
} else { } else {
return PEAR::raiseError( return PEAR::raiseError(
"StoredFile::deleteFile: unlink failed ({$this->fname})", "StoredFile::deleteFile: unlink failed ({$this->filepath})",
GBERR_FILEIO GBERR_FILEIO
); );
} }
@ -602,16 +666,12 @@ class StoredFile {
* @return array * @return array
* hierarchical hasharray with information about media file * hierarchical hasharray with information about media file
*/ */
function analyzeFile() public function analyzeFile()
{ {
if (!$this->exists) { if (!$this->exists) {
return FALSE; return FALSE;
} }
$ia = camp_get_audio_metadata($this->fname); $ia = camp_get_audio_metadata($this->filepath);
// echo "<pre>";
// $ia = camp_get_audio_metadata($this->fname, true);
// print_r($ia);
// exit;
return $ia; return $ia;
} }
@ -621,7 +681,7 @@ class StoredFile {
* *
* @return string * @return string
*/ */
function makeFileName() public function makeFileName()
{ {
return "{$this->resDir}/{$this->gunid}"; return "{$this->resDir}/{$this->gunid}";
} }
@ -638,7 +698,7 @@ class StoredFile {
*/ */
public static function CopyOf(&$src, $nid) public static function CopyOf(&$src, $nid)
{ {
$storedFile = StoredFile::insert($nid, $src->fname, $src->getRealFileName(), $storedFile = StoredFile::insert($nid, $src->name, $src->getRealFileName(),
'', '', NULL, BasicStor::GetType($src->gunid)); '', '', NULL, BasicStor::GetType($src->gunid));
if (PEAR::isError($storedFile)) { if (PEAR::isError($storedFile)) {
return $storedFile; return $storedFile;
@ -668,13 +728,13 @@ class StoredFile {
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$CC_DBC->query("BEGIN"); $CC_DBC->query("BEGIN");
$res = $this->rename($name); $res = $this->setName($name);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
$CC_DBC->query("ROLLBACK"); $CC_DBC->query("ROLLBACK");
return $res; return $res;
} }
if ($localFilePath != '') { if ($localFilePath != '') {
$res = $this->replaceRawMediaData($localFilePath); $res = $this->setRawMediaData($localFilePath);
} else { } else {
$res = $this->deleteFile(); $res = $this->deleteFile();
} }
@ -683,7 +743,7 @@ class StoredFile {
return $res; return $res;
} }
if ($metadata != '') { if ($metadata != '') {
$res = $this->replaceMetadata($metadata, $mdataLoc); $res = $this->setMetadata($metadata, $mdataLoc);
} else { } else {
$res = $this->md->delete(); $res = $this->md->delete();
} }
@ -744,9 +804,9 @@ class StoredFile {
* *
* @param string $localFilePath * @param string $localFilePath
* local path to media file * local path to media file
* @return void|PEAR_Error * @return TRUE|PEAR_Error
*/ */
public function replaceRawMediaData($localFilePath) public function setRawMediaData($localFilePath)
{ {
$res = $this->replaceFile($localFilePath); $res = $this->replaceFile($localFilePath);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
@ -763,6 +823,7 @@ class StoredFile {
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
return TRUE;
} }
@ -779,7 +840,7 @@ class StoredFile {
* (NULL = no validation) * (NULL = no validation)
* @return boolean * @return boolean
*/ */
public function replaceMetadata($metadata, $mdataLoc='file', $format=NULL) public function setMetadata($metadata, $mdataLoc='file', $format=NULL)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$CC_DBC->query("BEGIN"); $CC_DBC->query("BEGIN");
@ -819,17 +880,17 @@ class StoredFile {
* @param string $newname * @param string $newname
* @return TRUE|PEAR_Error * @return TRUE|PEAR_Error
*/ */
public function rename($newname) public function setName($p_newname)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$escapedName = pg_escape_string($newname); $escapedName = pg_escape_string($p_newname);
$res = $CC_DBC->query(" $res = $CC_DBC->query("
UPDATE ".$CC_CONFIG['filesTable']." SET name='$escapedName', mtime=now() UPDATE ".$CC_CONFIG['filesTable']." SET name='$escapedName', mtime=now()
WHERE gunid=x'{$this->gunid}'::bigint WHERE gunid=x'{$this->gunid}'::bigint");
");
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
$this->name = $p_newname;
return TRUE; return TRUE;
} }
@ -843,19 +904,20 @@ class StoredFile {
* user id | 'NULL' for clear editedBy field * user id | 'NULL' for clear editedBy field
* @return TRUE|PEAR_Error * @return TRUE|PEAR_Error
*/ */
public function setState($state, $editedby=NULL) public function setState($p_state, $p_editedby=NULL)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$escapedState = pg_escape_string($state); $escapedState = pg_escape_string($p_state);
$eb = (!is_null($editedby) ? ", editedBy=$editedby" : ''); $eb = (!is_null($p_editedby) ? ", editedBy=$p_editedby" : '');
$res = $CC_DBC->query(" $res = $CC_DBC->query("
UPDATE ".$CC_CONFIG['filesTable']." UPDATE ".$CC_CONFIG['filesTable']."
SET state='$escapedState'$eb, mtime=now() SET state='$escapedState'$eb, mtime=now()
WHERE gunid=x'{$this->gunid}'::bigint WHERE gunid=x'{$this->gunid}'::bigint");
");
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
$this->state = $p_state;
$this->editedby = $p_editedby;
return TRUE; return TRUE;
} }
@ -867,19 +929,20 @@ class StoredFile {
* mime-type * mime-type
* @return boolean|PEAR_Error * @return boolean|PEAR_Error
*/ */
public function setMime($mime) public function setMime($p_mime)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
if (!is_string($mime)) { if (!is_string($p_mime)) {
$mime = 'application/octet-stream'; $p_mime = 'application/octet-stream';
} }
$escapedMime = pg_escape_string($mime); $escapedMime = pg_escape_string($p_mime);
$res = $CC_DBC->query( $res = $CC_DBC->query(
"UPDATE ".$CC_CONFIG['filesTable']." SET mime='$escapedMime', mtime=now() "UPDATE ".$CC_CONFIG['filesTable']." SET mime='$escapedMime', mtime=now()
WHERE gunid=x'{$this->gunid}'::bigint"); WHERE gunid=x'{$this->gunid}'::bigint");
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
$this->mime = $p_mime;
return TRUE; return TRUE;
} }
@ -900,6 +963,7 @@ class StoredFile {
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
$this->md5 = $p_md5sum;
return TRUE; return TRUE;
} }
@ -910,12 +974,14 @@ class StoredFile {
* @see MetaData * @see MetaData
* @return TRUE|PEAR_Error * @return TRUE|PEAR_Error
*/ */
public function delete() public function delete($p_deleteFile = true)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$res = $this->deleteFile(); if ($p_deleteFile) {
if (PEAR::isError($res)) { $res = $this->deleteFile();
return $res; if (PEAR::isError($res)) {
return $res;
}
} }
$res = $this->md->delete(); $res = $this->md->delete();
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
@ -960,12 +1026,11 @@ class StoredFile {
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
if (is_null($gunid)) { if (is_null($gunid)) {
$gunid = $this->gunid; return ($this->currentlyaccessing > 0);
} }
$ca = $CC_DBC->getOne(" $ca = $CC_DBC->getOne("
SELECT currentlyAccessing FROM ".$CC_CONFIG['filesTable']." SELECT currentlyAccessing FROM ".$CC_CONFIG['filesTable']."
WHERE gunid=x'$gunid'::bigint WHERE gunid=x'$gunid'::bigint");
");
if (is_null($ca)) { if (is_null($ca)) {
return PEAR::raiseError( return PEAR::raiseError(
"StoredFile::isAccessed: invalid gunid ($gunid)", "StoredFile::isAccessed: invalid gunid ($gunid)",
@ -986,7 +1051,7 @@ class StoredFile {
public function isEdited($playlistId=NULL) public function isEdited($playlistId=NULL)
{ {
if (is_null($playlistId)) { if (is_null($playlistId)) {
$playlistId = $this->gunid; return ($this->state == 'edited');
} }
$state = $this->getState($playlistId); $state = $this->getState($playlistId);
if ($state != 'edited') { if ($state != 'edited') {
@ -1094,7 +1159,7 @@ class StoredFile {
*/ */
public function getFileExtension() public function getFileExtension()
{ {
$fname = $this->getFileName(); $fname = $this->getName();
$pos = strrpos($fname, '.'); $pos = strrpos($fname, '.');
if ($pos !== FALSE) { if ($pos !== FALSE) {
$ext = substr($fname, $pos+1); $ext = substr($fname, $pos+1);
@ -1153,7 +1218,7 @@ class StoredFile {
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
if (is_null($gunid)) { if (is_null($gunid)) {
$gunid = $this->gunid; return $this->state;
} }
return $CC_DBC->getOne(" return $CC_DBC->getOne("
SELECT state FROM ".$CC_CONFIG['filesTable']." SELECT state FROM ".$CC_CONFIG['filesTable']."
@ -1169,11 +1234,11 @@ class StoredFile {
* global unique id of file * global unique id of file
* @return string * @return string
*/ */
public function getFileName($gunid=NULL) public function getName($gunid=NULL)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
if (is_null($gunid)) { if (is_null($gunid)) {
$gunid = $this->gunid; return $this->name;
} }
return $CC_DBC->getOne(" return $CC_DBC->getOne("
SELECT name FROM ".$CC_CONFIG['filesTable']." SELECT name FROM ".$CC_CONFIG['filesTable']."
@ -1209,7 +1274,7 @@ class StoredFile {
*/ */
public function getRealFileName() public function getRealFileName()
{ {
return $this->fname; return $this->filepath;
} }

View File

@ -287,12 +287,12 @@ class Transport
switch ($ftype = BasicStor::GetType($gunid)) { switch ($ftype = BasicStor::GetType($gunid)) {
case "audioclip": case "audioclip":
case "webstream": case "webstream":
$ac = StoredFile::recallByGunid($gunid); $storedFile = StoredFile::RecallByGunid($gunid);
if (PEAR::isError($ac)) { if (PEAR::isError($storedFile)) {
return $ac; return $storedFile;
} }
// handle metadata: // handle metadata:
$mdfpath = $ac->getRealMetadataFileName(); $mdfpath = $storedFile->getRealMetadataFileName();
if (PEAR::isError($mdfpath)) { if (PEAR::isError($mdfpath)) {
return $mdfpath; return $mdfpath;
} }
@ -303,11 +303,11 @@ class Transport
return $mdtrec; return $mdtrec;
} }
// handle raw media file: // handle raw media file:
$fpath = $ac->getRealFileName(); $fpath = $storedFile->getRealFileName();
if (PEAR::isError($fpath)) { if (PEAR::isError($fpath)) {
return $fpath; return $fpath;
} }
$fname = $ac->getFileName(); $fname = $storedFile->getName();
if (PEAR::isError($fname)) { if (PEAR::isError($fname)) {
return $fname; return $fname;
} }
@ -325,11 +325,11 @@ class Transport
case "playlist": case "playlist":
$plid = $gunid; $plid = $gunid;
require_once("Playlist.php"); require_once("Playlist.php");
$pl = Playlist::recallByGunid($plid); $pl = Playlist::RecallByGunid($plid);
if (PEAR::isError($pl)) { if (PEAR::isError($pl)) {
return $pl; return $pl;
} }
$fname = $pl->getFileName(); $fname = $pl->getName();
if (PEAR::isError($fname)) { if (PEAR::isError($fname)) {
return $fname; return $fname;
} }

View File

@ -58,7 +58,7 @@ if (preg_match("|^[0-9a-fA-F]{16}$|", $_REQUEST['id'])) {
} }
// stored file recall: // stored file recall:
$ac = StoredFile::recallByGunid($gunid); $ac = StoredFile::RecallByGunid($gunid);
if (PEAR::isError($ac)) { if (PEAR::isError($ac)) {
switch ($ac->getCode()) { switch ($ac->getCode()) {
case GBERR_DENY: case GBERR_DENY: