Major changes - some code tranfers between layers:
StoredFile, BasicStor, GreenBox and LocStor +Resolved: http://bugs.campware.org/view.php?id=545
This commit is contained in:
parent
958c1b4952
commit
8e783bea66
|
@ -23,7 +23,7 @@
|
|||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.18 $
|
||||
Version : $Revision: 1.19 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/BasicStor.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -50,7 +50,7 @@ require_once "StoredFile.php";
|
|||
* Core of LiveSupport file storage module
|
||||
*
|
||||
* @author $Author: tomas $
|
||||
* @version $Revision: 1.18 $
|
||||
* @version $Revision: 1.19 $
|
||||
* @see Alib
|
||||
*/
|
||||
class BasicStor extends Alib{
|
||||
|
@ -127,23 +127,10 @@ class BasicStor extends Alib{
|
|||
$res = $this->removeObj($id);
|
||||
return $ac;
|
||||
}
|
||||
if($ftype == 'playlist') $ac->setMime('application/smil');
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze media file for internal metadata information
|
||||
*
|
||||
* @param id int, virt.file's local id
|
||||
* @return array
|
||||
*/
|
||||
function bsAnalyzeFile($id)
|
||||
{
|
||||
$ac =& StoredFile::recall(&$this, $id);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
$ia = $ac->analyzeMediaFile();
|
||||
return $ia;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename file
|
||||
*
|
||||
|
@ -157,15 +144,16 @@ class BasicStor extends Alib{
|
|||
switch($this->getObjType($id)){
|
||||
case"audioclip":
|
||||
case"playlist":
|
||||
case"File":
|
||||
$ac =& StoredFile::recall(&$this, $id);
|
||||
if(PEAR::isError($ac)){
|
||||
#// catch nonerror exception:
|
||||
#if($ac->getCode() != GBERR_FOBJNEX)
|
||||
// catch nonerror exception:
|
||||
//if($ac->getCode() != GBERR_FOBJNEX)
|
||||
return $ac;
|
||||
}
|
||||
$res = $ac->rename($newName);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
break;
|
||||
case"File":
|
||||
default:
|
||||
}
|
||||
return $this->renameObj($id, $newName);
|
||||
|
@ -198,7 +186,7 @@ class BasicStor extends Alib{
|
|||
case"playlist":
|
||||
case"File":
|
||||
return $this->_relocateSubtree($id, $did);
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
return PEAR::raiseError(
|
||||
"BasicStor::moveFile: only file move supported now, sorry.",
|
||||
|
@ -235,7 +223,7 @@ class BasicStor extends Alib{
|
|||
case"playlist":
|
||||
case"File":
|
||||
return $this->_copySubtree($id, $did);
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
return PEAR::raiseError(
|
||||
"BasicStor::moveFile: only file sopy supported now, sorry.",
|
||||
|
@ -253,8 +241,7 @@ class BasicStor extends Alib{
|
|||
function bsDeleteFile($id)
|
||||
{
|
||||
$res = $this->removeObj($id);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
return TRUE;
|
||||
return $res;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------- put, access etc. */
|
||||
|
@ -281,27 +268,16 @@ class BasicStor extends Alib{
|
|||
* @param realFname string, local filepath to accessed file
|
||||
* @param ext string, useful filename extension for accessed file
|
||||
* @param gunid int, global unique id
|
||||
* @param sessid string, session id
|
||||
* @param type string 'access'|'download'
|
||||
* @return array with: seekable filehandle, access token
|
||||
*/
|
||||
function bsAccess($realFname, $ext, $gunid, $sessid='', $type='access')
|
||||
function bsAccess($realFname, $ext, $gunid, $type='access')
|
||||
{
|
||||
$token = StoredFile::_createGunid();
|
||||
$res = $this->dbc->query("
|
||||
INSERT INTO {$this->accessTable}
|
||||
(gunid, sessid, token,
|
||||
ext, type, ts)
|
||||
VALUES
|
||||
(x'{$gunid}'::bigint, '$sessid', x'$token'::bigint,
|
||||
'$ext', '$type', now())
|
||||
");
|
||||
if(PEAR::isError($res)){ return $res; }
|
||||
$linkFname = "{$this->accessDir}/$token.$ext";
|
||||
|
||||
if(!file_exists($realFname)){
|
||||
return PEAR::raiseError(
|
||||
"BasicStor::bsAccess: symlink create failed ($accLinkName)",
|
||||
"BasicStor::bsAccess: real file not found ($realFname)",
|
||||
GBERR_FILEIO);
|
||||
}
|
||||
if(! @symlink($realFname, $linkFname)){
|
||||
|
@ -309,6 +285,23 @@ class BasicStor extends Alib{
|
|||
"BasicStor::bsAccess: symlink create failed ($linkFname)",
|
||||
GBERR_FILEIO);
|
||||
}
|
||||
$this->dbc->query("BEGIN");
|
||||
$res = $this->dbc->query("
|
||||
INSERT INTO {$this->accessTable}
|
||||
(gunid, token, ext, type, ts)
|
||||
VALUES
|
||||
(x'{$gunid}'::bigint, x'$token'::bigint,
|
||||
'$ext', '$type', now())
|
||||
");
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
$res = $this->dbc->query("
|
||||
UPDATE {$this->filesTable}
|
||||
SET currentlyAccessing=currentlyAccessing+1
|
||||
WHERE gunid=x'{$gunid}'::bigint
|
||||
");
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
$res = $this->dbc->query("COMMIT");
|
||||
if(PEAR::isError($res)){ return $res; }
|
||||
return array('fname'=>$linkFname, 'token'=>$token);
|
||||
}
|
||||
|
||||
|
@ -330,19 +323,28 @@ class BasicStor extends Alib{
|
|||
SELECT to_hex(gunid)as gunid, ext FROM {$this->accessTable}
|
||||
WHERE token=x'{$token}'::bigint AND type='$type'
|
||||
");
|
||||
if(PEAR::isError($acc)){ return $acc; }
|
||||
$ext = $acc['ext'];
|
||||
$gunid = StoredFile::_normalizeGunid($acc['gunid']);
|
||||
if(PEAR::isError($acc)){ return $acc; }
|
||||
$linkFname = "{$this->accessDir}/$token.$ext";
|
||||
$res = $this->dbc->query("
|
||||
DELETE FROM {$this->accessTable} WHERE token=x'$token'::bigint
|
||||
");
|
||||
if(PEAR::isError($res)){ return $res; }
|
||||
if(! @unlink($linkFname)){
|
||||
return PEAR::raiseError(
|
||||
"BasicStor::bsRelease: unlink failed ($linkFname)",
|
||||
GBERR_FILEIO);
|
||||
}
|
||||
$this->dbc->query("BEGIN");
|
||||
$res = $this->dbc->query("
|
||||
UPDATE {$this->filesTable}
|
||||
SET currentlyAccessing=currentlyAccessing-1
|
||||
WHERE gunid=x'{$gunid}'::bigint AND currentlyAccessing>0
|
||||
");
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
$res = $this->dbc->query("
|
||||
DELETE FROM {$this->accessTable} WHERE token=x'$token'::bigint
|
||||
");
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
$res = $this->dbc->query("COMMIT");
|
||||
if(PEAR::isError($res)){ return $res; }
|
||||
return $gunid;
|
||||
}
|
||||
|
||||
|
@ -368,8 +370,7 @@ class BasicStor extends Alib{
|
|||
$ext = "xml";
|
||||
break;
|
||||
}
|
||||
$sessid = '';
|
||||
$acc = $this->bsAccess($fname, $ext, $gunid, $sessid, 'download');
|
||||
$acc = $this->bsAccess($fname, $ext, $gunid, 'download');
|
||||
$url = $this->getUrlPart()."access/".basename($acc['fname']);
|
||||
return array('url'=>$url, 'token'=>$acc['token']);
|
||||
}
|
||||
|
@ -400,14 +401,13 @@ class BasicStor extends Alib{
|
|||
*/
|
||||
function bsOpenPut($chsum, $gunid)
|
||||
{
|
||||
$sessid = '';
|
||||
$ext = '';
|
||||
$token = StoredFile::_createGunid();
|
||||
$res = $this->dbc->query("
|
||||
INSERT INTO {$this->accessTable}
|
||||
(gunid, sessid, token, ext, chsum, type, ts)
|
||||
(gunid, token, ext, chsum, type, ts)
|
||||
VALUES
|
||||
(x'{$gunid}'::bigint, '$sessid', x'$token'::bigint,
|
||||
(x'{$gunid}'::bigint, x'$token'::bigint,
|
||||
'$ext', '$chsum', 'put', now())
|
||||
");
|
||||
if(PEAR::isError($res)){ return $res; }
|
||||
|
@ -488,7 +488,7 @@ class BasicStor extends Alib{
|
|||
{ $replicaName.='_R'; }
|
||||
$rid = $this->addObj($replicaName , 'Replica', $did, 0, $id);
|
||||
if(PEAR::isError($rid)) return $rid;
|
||||
# $this->addMdata($this->_pathFromId($rid), 'isReplOf', $id, $sessid);
|
||||
# $this->addMdata($this->_pathFromId($rid), 'isReplOf', $id);
|
||||
return $rid;
|
||||
}
|
||||
|
||||
|
@ -637,10 +637,34 @@ class BasicStor extends Alib{
|
|||
return PEAR::raiseError(
|
||||
'BasicStor::bsListFolder: not a folder', GBERR_NOTF
|
||||
);
|
||||
$a = $this->getDir($id, 'id, name, type, param as target', 'name');
|
||||
return $a;
|
||||
$listArr = $this->getDir($id, 'id, name, type, param as target', 'name');
|
||||
foreach($listArr as $i=>$v){
|
||||
if($v['type'] == 'File'){
|
||||
$gunid = $this->_gunidFromId($v['id']);
|
||||
$listArr[$i]['type'] =
|
||||
StoredFile::_getType($gunid);
|
||||
$listArr[$i]['gunid'] = $gunid;
|
||||
if(StoredFIle::_getState($gunid) == 'incomplete')
|
||||
unset($listArr[$i]);
|
||||
}
|
||||
}
|
||||
return $listArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze media file for internal metadata information
|
||||
*
|
||||
* @param id int, virt.file's local id
|
||||
* @return array
|
||||
*/
|
||||
function bsAnalyzeFile($id)
|
||||
{
|
||||
$ac =& StoredFile::recall(&$this, $id);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
$ia = $ac->analyzeMediaFile();
|
||||
return $ia;
|
||||
}
|
||||
|
||||
/**
|
||||
* List files in folder
|
||||
*
|
||||
|
@ -651,11 +675,11 @@ class BasicStor extends Alib{
|
|||
function getObjIdFromRelPath($id, $relPath='.')
|
||||
{
|
||||
$relPath = trim($relPath);
|
||||
#if($this->getObjType($id) !== 'Folder')
|
||||
//if($this->getObjType($id) !== 'Folder')
|
||||
$nid = $this->getParent($id);
|
||||
if(PEAR::isError($nid)) return $nid;
|
||||
if(is_null($nid)){ return PEAR::raiseError("null parent for $nid"); }
|
||||
#else $nid = $id;
|
||||
//else $nid = $id;
|
||||
if(substr($relPath, 0, 1)=='/'){ $nid=$this->storId; }
|
||||
$a = split('/', $relPath);
|
||||
foreach($a as $i=>$pathItem){
|
||||
|
@ -686,6 +710,174 @@ class BasicStor extends Alib{
|
|||
return $nid;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------- redefined methods */
|
||||
/**
|
||||
* Get object type by id.
|
||||
* (RootNode, Folder, File, )
|
||||
*
|
||||
* @param oid int, local object id
|
||||
* @return string/err
|
||||
*/
|
||||
function getObjType($oid)
|
||||
{
|
||||
$type = $this->getObjName($oid, 'type');
|
||||
if($type == 'File'){
|
||||
$ftype =
|
||||
StoredFile::_getType($this->_gunidFromId($oid));
|
||||
if(!is_null($ftype)) $type=$ftype;
|
||||
}
|
||||
return $type;
|
||||
}
|
||||
|
||||
/* ==================================================== "private" methods */
|
||||
/**
|
||||
* Check authorization - auxiliary method
|
||||
*
|
||||
* @param acts array of actions
|
||||
* @param pars array of parameters - e.g. ids
|
||||
* @param sessid string, session id
|
||||
* @return true or PEAR::error
|
||||
*/
|
||||
function _authorize($acts, $pars, $sessid='')
|
||||
{
|
||||
$userid = $this->getSessUserId($sessid);
|
||||
if(!is_array($pars)) $pars = array($pars);
|
||||
if(!is_array($acts)) $acts = array($acts);
|
||||
$perm = true;
|
||||
foreach($acts as $i=>$action){
|
||||
$res = $this->checkPerm($userid, $action, $pars[$i]);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
$perm = $perm && $res;
|
||||
}
|
||||
if($perm) return TRUE;
|
||||
$adesc = "[".join(',',$acts)."]";
|
||||
return PEAR::raiseError("GreenBox::$adesc: access denied", GBERR_DENY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return users's home folder local ID
|
||||
*
|
||||
* @param sessid string, session ID
|
||||
* @return local folder id
|
||||
*/
|
||||
function _getHomeDirId($sessid)
|
||||
{
|
||||
$parid = $this->getObjId(
|
||||
$this->getSessLogin($sessid), $this->storId
|
||||
);
|
||||
return $parid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get local id from global id
|
||||
*
|
||||
* @param gunid string global id
|
||||
* @return int local id
|
||||
*/
|
||||
function _idFromGunid($gunid)
|
||||
{
|
||||
return $this->dbc->getOne(
|
||||
"SELECT id FROM {$this->filesTable} WHERE gunid=x'$gunid'::bigint"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global id from local id
|
||||
*
|
||||
* @param id int local id
|
||||
* @return string global id
|
||||
*/
|
||||
function _gunidFromId($id)
|
||||
{
|
||||
if(!is_numeric($id)) return NULL;
|
||||
$gunid = $this->dbc->getOne("
|
||||
SELECT to_hex(gunid)as gunid FROM {$this->filesTable}
|
||||
WHERE id='$id'
|
||||
");
|
||||
if(PEAR::isError($gunid)) return $gunid;
|
||||
if(is_null($gunid)) return NULL;
|
||||
return StoredFile::_normalizeGunid($gunid);
|
||||
}
|
||||
|
||||
/* ------------------------------------------ redefined "private" methods */
|
||||
/**
|
||||
* Copy virtual file.<br>
|
||||
* Redefined from parent class.
|
||||
*
|
||||
* @return id
|
||||
*/
|
||||
function copyObj($id, $newParid, $after=NULL)
|
||||
{
|
||||
$parid = $this->getParent($id);
|
||||
$nid = parent::copyObj($id, $newParid, $after);
|
||||
if(PEAR::isError($nid)) return $nid;
|
||||
switch($this->getObjType($id)){
|
||||
case"audioclip":
|
||||
case"playlist":
|
||||
$ac =& StoredFile::recall(&$this, $id);
|
||||
if(PEAR::isError($ac)){ return $ac; }
|
||||
$ac2 =& StoredFile::copyOf(&$ac, $nid);
|
||||
$ac2->rename($this->getObjName($nid));
|
||||
break;
|
||||
case"File":
|
||||
default:
|
||||
}
|
||||
return $nid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionaly remove virtual file with the same name and add new one.<br>
|
||||
* Redefined from parent class.
|
||||
*
|
||||
* @return id
|
||||
*/
|
||||
function addObj($name, $type, $parid=1, $aftid=NULL, $param='')
|
||||
{
|
||||
if(!is_null($exid = $this->getObjId($name, $parid)))
|
||||
{ $this->removeObj($exid); }
|
||||
return parent::addObj($name, $type, $parid, $aftid, $param);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove virtual file.<br>
|
||||
* Redefined from parent class.
|
||||
*
|
||||
* @param id int, local id of removed object
|
||||
* @return true or PEAR::error
|
||||
*/
|
||||
function removeObj($id)
|
||||
{
|
||||
switch($ot = $this->getObjType($id)){
|
||||
case"audioclip":
|
||||
case"playlist":
|
||||
$ac =& StoredFile::recall(&$this, $id);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
if($ac->isEdited()){
|
||||
return PEAR::raiseError(
|
||||
'BasicStor.php: removeObj: is edited'
|
||||
);
|
||||
}
|
||||
if($ac->isAccessed()){
|
||||
return PEAR::raiseError(
|
||||
'BasicStor.php: removeObj: is accessed'
|
||||
);
|
||||
}
|
||||
$ac->delete();
|
||||
break;
|
||||
case"File":
|
||||
case"Folder":
|
||||
case"Replica":
|
||||
break;
|
||||
default:
|
||||
return PEAR::raiseError(
|
||||
"GreenBox::bsDeleteFile: unknown obj type ($ot)"
|
||||
);
|
||||
}
|
||||
$res = parent::removeObj($id);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* =============================================== test and debug methods */
|
||||
/**
|
||||
* dump
|
||||
|
@ -729,7 +921,7 @@ class BasicStor extends Alib{
|
|||
// $this->dbc->query("DELETE FROM {$this->filesTable}");
|
||||
$ids = $this->dbc->getAll("SELECT id FROM {$this->filesTable}");
|
||||
if(is_array($ids)) foreach($ids as $i=>$item){
|
||||
$this->removeObj($item['id']);
|
||||
$this->bsDeleteFile($item['id']);
|
||||
}
|
||||
parent::deleteData();
|
||||
$this->initData();
|
||||
|
@ -871,7 +1063,6 @@ class BasicStor extends Alib{
|
|||
#echo "{$this->accessTable}\n";
|
||||
$r = $this->dbc->query("CREATE TABLE {$this->accessTable} (
|
||||
gunid bigint,
|
||||
sessid char(32) not null default'',
|
||||
token bigint,
|
||||
chsum char(32) not null default'',
|
||||
ext varchar(128) not null default'',
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.22 $
|
||||
Version : $Revision: 1.23 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/GreenBox.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -35,7 +35,7 @@ require_once "BasicStor.php";
|
|||
* LiveSupport file storage module
|
||||
*
|
||||
* @author $Author: tomas $
|
||||
* @version $Revision: 1.22 $
|
||||
* @version $Revision: 1.23 $
|
||||
* @see BasicStor
|
||||
*/
|
||||
class GreenBox extends BasicStor{
|
||||
|
@ -55,7 +55,7 @@ class GreenBox extends BasicStor{
|
|||
{
|
||||
if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE)
|
||||
return $res;
|
||||
return $this->bsCreateFolder($parid, $folderName , 'Folder', $parid);
|
||||
return $this->bsCreateFolder($parid, $folderName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -159,37 +159,6 @@ class GreenBox extends BasicStor{
|
|||
return $this->bsDeleteFile($id);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------- put, access etc. */
|
||||
/**
|
||||
* Create and return access link to media file
|
||||
*
|
||||
* @param id int, virt.file's local id
|
||||
* @param sessid string, session id
|
||||
* @return array with: seekable filehandle, access token
|
||||
*/
|
||||
function access($id, $sessid='')
|
||||
{
|
||||
$ac =& StoredFile::recall(&$this, $id);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE)
|
||||
return $res;
|
||||
return $ac->accessRawMediaData($sessid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Release access link to media file
|
||||
*
|
||||
* @param sessid string, session id
|
||||
* @param token string, access token
|
||||
* @return boolean or PEAR::error
|
||||
*/
|
||||
function release($token, $sessid='')
|
||||
{
|
||||
$ac =& StoredFile::recallByToken(&$this, $token);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
return $ac->releaseRawMediaData($sessid, $token);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------- replicas, versions etc. */
|
||||
/**
|
||||
* Create replica.<br>
|
||||
|
@ -304,39 +273,11 @@ class GreenBox extends BasicStor{
|
|||
if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE)
|
||||
return $res;
|
||||
$listArr = $this->bsListFolder($id);
|
||||
foreach($listArr as $i=>$v){
|
||||
if($v['type'] == 'File'){
|
||||
$gunid = $this->_gunidFromId($v['id']);
|
||||
$listArr[$i]['type'] =
|
||||
StoredFile::_getType($gunid);
|
||||
$listArr[$i]['gunid'] = $gunid;
|
||||
}
|
||||
}
|
||||
return $listArr;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------- redefined methods */
|
||||
|
||||
/**
|
||||
* Logout and destroy session
|
||||
*
|
||||
* @param sessid string
|
||||
* @return true/err
|
||||
*/
|
||||
function logout($sessid)
|
||||
{
|
||||
/* release all accessed files on logout - probably not useful
|
||||
$acfa = $this->dbc->getAll("SELECT * FROM {$this->accessTable}
|
||||
WHERE sessid='$sessid'");
|
||||
if(PEAR::isError($acfa)) return $acfa;
|
||||
foreach($acfa as $i=>$acf){
|
||||
$ac =& StoredFile::recallByToken(&$this, $acf['token']);
|
||||
$ac->releaseRawMediaData($sessid, $acf['token']);
|
||||
}
|
||||
*/
|
||||
return parent::logout($sessid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new user with home folder
|
||||
*
|
||||
|
@ -348,7 +289,7 @@ class GreenBox extends BasicStor{
|
|||
{
|
||||
$uid = parent::addSubj($login, $pass);
|
||||
if(PEAR::isError($uid)) return $uid;
|
||||
$fid = $this->addObj($login , 'Folder', $this->storId);
|
||||
$fid = $this->bsCreateFolder($this->storId, $login);
|
||||
if(PEAR::isError($fid)) return $fid;
|
||||
$res = $this->addPerm($uid, '_all', $fid, 'A');
|
||||
if(PEAR::isError($res)) return $res;
|
||||
|
@ -367,7 +308,7 @@ class GreenBox extends BasicStor{
|
|||
if(PEAR::isError($res)) return $res;
|
||||
$id = $this->getObjId($login, $this->storId);
|
||||
if(PEAR::isError($id)) return $id;
|
||||
$res = $this->removeObj($id);
|
||||
$res = $this->bsDeleteFile($id);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -380,191 +321,11 @@ class GreenBox extends BasicStor{
|
|||
*/
|
||||
function getPath($id)
|
||||
{
|
||||
$pa = parent::getPath($id, 'id, name, type'); array_shift($pa);
|
||||
$pa = parent::getPath($id, 'id, name, type');
|
||||
array_shift($pa);
|
||||
return $pa;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get object type by id.
|
||||
* (RootNode, Folder, File, )
|
||||
*
|
||||
* @param oid int, local object id
|
||||
* @return string/err
|
||||
*/
|
||||
function getObjType($oid)
|
||||
{
|
||||
$type = $this->getObjName($oid, 'type');
|
||||
if($type == 'File'){
|
||||
$ftype =
|
||||
StoredFile::_getType($this->_gunidFromId($oid));
|
||||
if(!is_null($ftype)) $type=$ftype;
|
||||
}
|
||||
return $type;
|
||||
}
|
||||
|
||||
|
||||
/* ========================================== redefined "private" methods */
|
||||
/**
|
||||
* Copy virtual file.<br>
|
||||
* Redefined from parent class.
|
||||
*
|
||||
* @return id
|
||||
*/
|
||||
function copyObj($id, $newParid, $after=NULL)
|
||||
{
|
||||
$parid = $this->getParent($id);
|
||||
$nid = parent::copyObj($id, $newParid, $after);
|
||||
if(PEAR::isError($nid)) return $nid;
|
||||
switch($this->getObjType($id)){
|
||||
case"audioclip":
|
||||
case"playlist":
|
||||
case"File":
|
||||
$ac =& StoredFile::recall(&$this, $id);
|
||||
if(PEAR::isError($ac)){ return $ac; }
|
||||
$ac2 =& StoredFile::copyOf(&$ac, $nid);
|
||||
$ac2->rename($this->getObjName($nid));
|
||||
break;
|
||||
default:
|
||||
}
|
||||
return $nid;
|
||||
}
|
||||
/**
|
||||
* Optionaly remove virtual file with the same name and add new one.<br>
|
||||
* Redefined from parent class.
|
||||
*
|
||||
* @return id
|
||||
*/
|
||||
function addObj($name, $type, $parid=1, $aftid=NULL, $param='')
|
||||
{
|
||||
if(!is_null($exid = $this->getObjId($name, $parid)))
|
||||
{ $this->removeObj($exid); }
|
||||
return parent::addObj($name, $type, $parid, $aftid, $param);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove virtual file.<br>
|
||||
* Redefined from parent class.
|
||||
*
|
||||
* @param id int, local id of removed object
|
||||
* @return true or PEAR::error
|
||||
*/
|
||||
function removeObj($id)
|
||||
{
|
||||
switch($ot = $this->getObjType($id)){
|
||||
case"audioclip":
|
||||
case"playlist":
|
||||
case"File":
|
||||
$ac =& StoredFile::recall(&$this, $id);
|
||||
if(!PEAR::isError($ac)){
|
||||
$ac->delete();
|
||||
}
|
||||
$r = parent::removeObj($id);
|
||||
if(PEAR::isError($r)) return $r;
|
||||
break;
|
||||
case"Folder":
|
||||
$r = parent::removeObj($id);
|
||||
if(PEAR::isError($r)) return $r;
|
||||
break;
|
||||
case"Replica":
|
||||
$r = parent::removeObj($id);
|
||||
if(PEAR::isError($r)) return $r;
|
||||
break;
|
||||
default:
|
||||
return PEAR::raiseError(
|
||||
"GreenBox::removeObj: unknown obj type ($ot)"
|
||||
);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* ==================================================== "private" methods */
|
||||
/**
|
||||
* Return users's home folder local ID
|
||||
*
|
||||
* @param sessid string, session ID
|
||||
* @return local folder id
|
||||
*/
|
||||
function _getHomeDirId($sessid)
|
||||
{
|
||||
$parid = $this->getObjId(
|
||||
$this->getSessLogin($sessid), $this->storId
|
||||
);
|
||||
return $parid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check authorization - auxiliary method
|
||||
*
|
||||
* @param acts array of actions
|
||||
* @param pars array of parameters - e.g. ids
|
||||
* @param sessid string, session id
|
||||
* @return true or PEAR::error
|
||||
*/
|
||||
function _authorize($acts, $pars, $sessid='')
|
||||
{
|
||||
$userid = $this->getSessUserId($sessid);
|
||||
if(!is_array($pars)) $pars = array($pars);
|
||||
if(!is_array($acts)) $acts = array($acts);
|
||||
$perm = true;
|
||||
foreach($acts as $i=>$action){
|
||||
$res = $this->checkPerm($userid, $action, $pars[$i]);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
$perm = $perm && $res;
|
||||
}
|
||||
if($perm) return TRUE;
|
||||
$adesc = "[".join(',',$acts)."]";
|
||||
return PEAR::raiseError("GreenBox::$adesc: access denied", GBERR_DENY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create fake session for downloaded files
|
||||
*
|
||||
* @param userid user id
|
||||
* @return string sessid
|
||||
*/
|
||||
function _fakeSession($userid)
|
||||
{
|
||||
$sessid = $this->_createSessid();
|
||||
if(PEAR::isError($sessid)) return $sessid;
|
||||
$login = $this->getSubjName($userid);
|
||||
$r = $this->dbc->query("INSERT INTO {$this->sessTable}
|
||||
(sessid, userid, login, ts)
|
||||
VALUES
|
||||
('$sessid', '$userid', '$login', now())");
|
||||
if(PEAR::isError($r)) return $r;
|
||||
return $sessid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get local id from global id
|
||||
*
|
||||
* @param gunid string global id
|
||||
* @return int local id
|
||||
*/
|
||||
function _idFromGunid($gunid)
|
||||
{
|
||||
return $this->dbc->getOne(
|
||||
"SELECT id FROM {$this->filesTable} WHERE gunid=x'$gunid'::bigint"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global id from local id
|
||||
*
|
||||
* @param id int local id
|
||||
* @return string global id
|
||||
*/
|
||||
function _gunidFromId($id)
|
||||
{
|
||||
if(!is_numeric($id)) return NULL;
|
||||
$gunid = $this->dbc->getOne("
|
||||
SELECT to_hex(gunid)as gunid FROM {$this->filesTable}
|
||||
WHERE id='$id'
|
||||
");
|
||||
if(PEAR::isError($gunid)) return $gunid;
|
||||
if(is_null($gunid)) return NULL;
|
||||
return StoredFile::_normalizeGunid($gunid);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -23,19 +23,19 @@
|
|||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.18 $
|
||||
Version : $Revision: 1.19 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/LocStor.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
require_once "GreenBox.php";
|
||||
require_once "BasicStor.php";
|
||||
|
||||
/**
|
||||
* LocStor class
|
||||
*
|
||||
* Livesupport local storage interface
|
||||
*/
|
||||
class LocStor extends GreenBox{
|
||||
class LocStor extends BasicStor{
|
||||
/* ---------------------------------------------------------------- store */
|
||||
/**
|
||||
* Store or replace existing audio clip
|
||||
|
@ -95,7 +95,7 @@ class LocStor extends GreenBox{
|
|||
if($fname == ''){
|
||||
$fname = "newFile";
|
||||
}
|
||||
$res = $this->renameFile($oid, $fname, $sessid);
|
||||
$res = $this->bsRenameFile($oid, $fname);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
return $this->bsOpenPut($chsum, $ac->gunid);
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ class LocStor extends GreenBox{
|
|||
if(PEAR::isError($ac)) return $ac;
|
||||
if(($res = $this->_authorize('read', $ac->getId(), $sessid)) !== TRUE)
|
||||
return $res;
|
||||
return $ac->accessRawMediaData($sessid);
|
||||
return $ac->accessRawMediaData();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -232,7 +232,7 @@ class LocStor extends GreenBox{
|
|||
if(PEAR::isError($ac)) return $ac;
|
||||
if(($res = $this->_authorize('read', $ac->getId(), $sessid)) !== TRUE)
|
||||
return $res;
|
||||
$md = $this->getMdata($ac->getId(), $sessid);
|
||||
$md = $this->bsGetMetadata($ac->getId());
|
||||
if(PEAR::isError($md)) return $md;
|
||||
return $md;
|
||||
}
|
||||
|
@ -284,7 +284,7 @@ class LocStor extends GreenBox{
|
|||
'playlistResults' => $resPL['results']
|
||||
);
|
||||
}
|
||||
$srchRes = $this->localSearch($criteria, $sessid);
|
||||
$srchRes = $this->bsLocalSearch($criteria);
|
||||
$res = array('audioClipResults'=>NULL, 'playlistResults'=>NULL);
|
||||
switch($filetype){
|
||||
case"audioclip":
|
||||
|
@ -356,12 +356,7 @@ class LocStor extends GreenBox{
|
|||
if(PEAR::isError($ac)) return $ac;
|
||||
if(($res = $this->_authorize('write', $ac->getId(), $sessid)) !== TRUE)
|
||||
return $res;
|
||||
if($ac->isAccessed()){
|
||||
return PEAR::raiseError(
|
||||
'LocStor.php: deleteAudioClip: is accessed'
|
||||
);
|
||||
}
|
||||
$res = $this->deleteFile($ac->getId(), $sessid);
|
||||
$res = $this->bsDeleteFile($ac->getId());
|
||||
if(PEAR::isError($res)) return $res;
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -392,8 +387,6 @@ class LocStor extends GreenBox{
|
|||
{
|
||||
$this->deleteData();
|
||||
$rootHD = $this->getObjId('root', $this->storId);
|
||||
# $this->login('root', $this->config['tmpRootPass']);
|
||||
# $s = $this->sessid;
|
||||
include"../tests/sampleData.php";
|
||||
$res = array();
|
||||
foreach($sampleData as $k=>$it){
|
||||
|
@ -420,7 +413,6 @@ class LocStor extends GreenBox{
|
|||
if(PEAR::isError($r)){ return $r; }
|
||||
$res[] = $this->_gunidFromId($r);
|
||||
}
|
||||
# $this->logout($this->sessid);
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
@ -461,7 +453,7 @@ class LocStor extends GreenBox{
|
|||
if($fname == ''){
|
||||
$fname = "newFile.xml";
|
||||
}
|
||||
$res = $this->renameFile($oid, $fname, $sessid);
|
||||
$res = $this->bsRenameFile($oid, $fname);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
$res = $ac->setState('ready');
|
||||
if(PEAR::isError($res)) return $res;
|
||||
|
@ -540,12 +532,7 @@ class LocStor extends GreenBox{
|
|||
if(PEAR::isError($ac)) return $ac;
|
||||
if(($res = $this->_authorize('write', $ac->getId(), $sessid)) !== TRUE)
|
||||
return $res;
|
||||
if($this->_isEdited($playlistId)){
|
||||
return PEAR::raiseError(
|
||||
'LocStor.php: deletePlaylist: playlist is edited'
|
||||
);
|
||||
}
|
||||
$res = $this->deleteFile($ac->getId(), $sessid);
|
||||
$res = $this->bsDeleteFile($ac->getId());
|
||||
if(PEAR::isError($res)) return $res;
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -626,9 +613,8 @@ class LocStor extends GreenBox{
|
|||
*/
|
||||
function _isEdited($playlistId)
|
||||
{
|
||||
$state = StoredFile::_getState($playlistId);
|
||||
if($state == 'edited'){ return TRUE; }
|
||||
return FALSE;
|
||||
$ac =& StoredFile::recallByGunid(&$this, $playlistId);
|
||||
return $ac->isEdited($playlistId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.14 $
|
||||
Version : $Revision: 1.15 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/StoredFile.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -274,28 +274,16 @@ class StoredFile{
|
|||
* Increase access counter, create access token, insert access record,
|
||||
* call access method of RawMediaData
|
||||
*
|
||||
* @param sessid string
|
||||
* @return array with: access URL, access token
|
||||
*/
|
||||
function accessRawMediaData($sessid)
|
||||
function accessRawMediaData()
|
||||
{
|
||||
$this->dbc->query("BEGIN");
|
||||
$res = $this->dbc->query("
|
||||
UPDATE {$this->filesTable}
|
||||
SET currentlyAccessing=currentlyAccessing+1
|
||||
WHERE gunid=x'{$this->gunid}'::bigint
|
||||
");
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
# $token = $this->_createGunid();
|
||||
$realFname = $this->_getRealRADFname();
|
||||
$ext = $this->_getExt();
|
||||
|
||||
$res = $this->gb->bsAccess($realFname, $ext, $this->gunid, $sessid);
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
$res = $this->gb->bsAccess($realFname, $ext, $this->gunid);
|
||||
if(PEAR::isError($res)){ return $res; }
|
||||
$resultArray =
|
||||
array('url'=>"file://{$res['fname']}", 'token'=>$res['token']);
|
||||
$res = $this->dbc->query("COMMIT");
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
return $resultArray;
|
||||
}
|
||||
|
||||
|
@ -308,16 +296,8 @@ class StoredFile{
|
|||
*/
|
||||
function releaseRawMediaData($token)
|
||||
{
|
||||
$this->dbc->query("BEGIN");
|
||||
$res = $this->dbc->query("UPDATE {$this->filesTable}
|
||||
SET currentlyAccessing=currentlyAccessing-1
|
||||
WHERE gunid=x'{$this->gunid}'::bigint AND currentlyAccessing>0
|
||||
");
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
$res = $this->gb->bsRelease($token);
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
$res = $this->dbc->query("COMMIT");
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
if(PEAR::isError($res)){ return $res; }
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -469,12 +449,33 @@ class StoredFile{
|
|||
function isAccessed($gunid=NULL)
|
||||
{
|
||||
if(is_null($gunid)) $gunid = $this->gunid;
|
||||
return (0 < $this->dbc->getOne("
|
||||
$ca = $this->dbc->getOne("
|
||||
SELECT currentlyAccessing FROM {$this->filesTable}
|
||||
WHERE gunid=x'$gunid'::bigint
|
||||
"));
|
||||
");
|
||||
if(is_null($ca)){
|
||||
return PEAR::raiseError(
|
||||
"StoredFile::isAccessed: invalid gunid ($gunid)",
|
||||
GBERR_FOBJNEX
|
||||
);
|
||||
}
|
||||
return ($ca > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if virtual file is edited
|
||||
*
|
||||
* @param playlistId string, playlist global unique ID
|
||||
* @return boolean
|
||||
*/
|
||||
function isEdited($gunid=NULL)
|
||||
{
|
||||
if(is_null($gunid)) $gunid = $this->gunid;
|
||||
$state = $this->_getState($gunid);
|
||||
if($state == 'edited'){ return TRUE; }
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns local id of virtual file
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue