Delete operation replaced by moving to trash.

+ #887 feature added
+ #885 fixed
This commit is contained in:
tomas 2005-04-27 23:59:50 +00:00
parent c153560ab9
commit ecf5284a5c
5 changed files with 124 additions and 78 deletions

View file

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.6 $ Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/subj.php,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/subj.php,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -39,7 +39,7 @@ define('ALIBERR_BADSMEMB', 21);
* (allow adding users to groups or groups to groups) * (allow adding users to groups or groups to groups)
* *
* @author $Author: tomas $ * @author $Author: tomas $
* @version $Revision: 1.6 $ * @version $Revision: 1.7 $
* @see ObjClasses * @see ObjClasses
* @see Alib * @see Alib
*/ */
@ -127,17 +127,20 @@ class Subjects extends ObjClasses{
* Change user password * Change user password
* *
* @param login string * @param login string
* @param oldpass string * @param oldpass string, old password (optional for 'superuser mode')
* @param pass string, optional * @param pass string, optional
* @return boolean/err * @return boolean/err
*/ */
function passwd($login, $oldpass, $pass='') function passwd($login, $oldpass=null, $pass='')
{ {
$cpass = md5($pass); $cpass = md5($pass);
if(!is_null($oldpass)){
$oldcpass = md5($oldpass); $oldcpass = md5($oldpass);
$oldpCond = "AND pass='$oldcpass'";
}else{ $oldpCond = ''; }
$this->dbc->query(" $this->dbc->query("
UPDATE {$this->subjTable} SET pass='$cpass' UPDATE {$this->subjTable} SET pass='$cpass'
WHERE login='$login' AND pass='$oldcpass' AND type='U' WHERE login='$login' $oldpCond AND type='U'
"); ");
if(PEAR::isError($id)) return $id; if(PEAR::isError($id)) return $id;
return TRUE; return TRUE;

View file

@ -452,7 +452,7 @@ class uiHandler extends uiBase {
{ {
if (PEAR::isError( if (PEAR::isError(
$this->gb->addPerm( $this->gb->addPerm(
$this->sessid, $subj, $permAction, $id, $allowDeny $subj, $permAction, $id, $allowDeny, $this->sessid
) )
)) { )) {
$this->_retMsg('Access denied.'); $this->_retMsg('Access denied.');
@ -472,7 +472,7 @@ class uiHandler extends uiBase {
*/ */
function removePerm($permid, $oid) function removePerm($permid, $oid)
{ {
if (PEAR::isError($this->gb->removePerm($this->sessid, $permid))) { if (PEAR::isError($this->gb->removePerm($permid, NULL, NULL, $this->sessid))) {
$this->_retMsg('Access denied.'); $this->_retMsg('Access denied.');
return FALSE; return FALSE;
} }

View file

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.46 $ Version : $Revision: 1.47 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/BasicStor.php,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/BasicStor.php,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -53,7 +53,7 @@ require_once "Transport.php";
* Core of LiveSupport file storage module * Core of LiveSupport file storage module
* *
* @author $Author: tomas $ * @author $Author: tomas $
* @version $Revision: 1.46 $ * @version $Revision: 1.47 $
* @see Alib * @see Alib
*/ */
class BasicStor extends Alib{ class BasicStor extends Alib{
@ -236,9 +236,32 @@ class BasicStor extends Alib{
*/ */
function bsDeleteFile($id, $forced=FALSE) function bsDeleteFile($id, $forced=FALSE)
{ {
// full delete:
if(!$this->config['useTrash'] || $forced){
$res = $this->removeObj($id, $forced); $res = $this->removeObj($id, $forced);
return $res; return $res;
} }
// move to trash:
$did = $this->getObjId($this->config['TrashName'], $this->storId);
if($this->dbc->isError($did)) return $did;
switch($this->getObjType($id)){
case"audioclip":
case"playlist":
case"webstream":
$ac =& StoredFile::recall($this, $id);
if($this->dbc->isError($ac)) return $ac;
if(is_null($did)){
return PEAR::raiseError("BasicStor::bsDeleteFile: ".
"trash not found", GBERR_NOTF);
}
$res = $ac->setState('deleted');
if($this->dbc->isError($res)) return $res;
break;
default:
}
$res = $this->bsMoveFile($id, $did);
return $res;
}
/* ----------------------------------------------------- put, access etc. */ /* ----------------------------------------------------- put, access etc. */
/** /**
@ -1311,9 +1334,14 @@ class BasicStor extends Alib{
// if($this->dbc->isError($p = parent::test())) return $p; // if($this->dbc->isError($p = parent::test())) return $p;
$this->deleteData(); $this->deleteData();
$this->testData(); $this->testData();
if($this->config['useTrash']){
$trash = "{$this->config['TrashName']}\n ";
}else{
$trash = "";
}
if(!$this->config['isArchive']){ if(!$this->config['isArchive']){
$this->test_correct = " StorageRoot $this->test_correct = " StorageRoot
root {$trash}root
test1 test1
file1.mp3 file1.mp3
public public
@ -1332,7 +1360,7 @@ class BasicStor extends Alib{
"; ";
}else{ }else{
$this->test_correct = " StorageRoot $this->test_correct = " StorageRoot
root {$trash}root
test1 test1
file1.mp3 file1.mp3
test1_folder1 test1_folder1
@ -1349,9 +1377,9 @@ class BasicStor extends Alib{
$this->test_dump = $this->dumpTree($this->storId, ' ', ' ', '{name}'); $this->test_dump = $this->dumpTree($this->storId, ' ', ' ', '{name}');
if($this->test_dump==$this->test_correct) if($this->test_dump==$this->test_correct)
{ $this->test_log.="# BasicStor::test: OK\n"; return true; } { $this->test_log.="# BasicStor::test: OK\n"; return true; }
else PEAR::raiseError('BasicStor::test:', 1, PEAR_ERROR_DIE, '%s'. else return PEAR::raiseError(
"<pre>\ncorrect:\n.{$this->test_correct}.\n". "BasicStor::test:\ncorrect:\n.{$this->test_correct}.\n".
"dump:\n.{$this->test_dump}.\n</pre>\n"); "dump:\n.{$this->test_dump}.\n", 1, PEAR_ERROR_RETURN);
} }
/** /**
@ -1365,7 +1393,16 @@ class BasicStor extends Alib{
$this->addObj('StorageRoot', 'Folder', $this->rootId); $this->addObj('StorageRoot', 'Folder', $this->rootId);
$rootUid = parent::addSubj('root', $this->config['tmpRootPass']); $rootUid = parent::addSubj('root', $this->config['tmpRootPass']);
$res = parent::addPerm($rootUid, '_all', $this->rootId, 'A'); $res = parent::addPerm($rootUid, '_all', $this->rootId, 'A');
if($this->dbc->isError($res)) return $res;
$res = parent::addPerm($rootUid, 'subjects', $this->rootId, 'A');
if($this->dbc->isError($res)) return $res;
$fid = $this->bsCreateFolder($this->storId, 'root'); $fid = $this->bsCreateFolder($this->storId, 'root');
if($this->dbc->isError($fid)) return $fid;
if($this->config['useTrash']){
$tfid = $this->bsCreateFolder(
$this->storId, $this->config["TrashName"]);
if($this->dbc->isError($tfid)) return $tfid;
}
if(!$this->config['isArchive']){ if(!$this->config['isArchive']){
$stPrefGr = parent::addSubj($this->config['StationPrefsGr']); $stPrefGr = parent::addSubj($this->config['StationPrefsGr']);
$this->addSubj2Gr('root', $this->config['StationPrefsGr']); $this->addSubj2Gr('root', $this->config['StationPrefsGr']);
@ -1377,6 +1414,7 @@ class BasicStor extends Alib{
if($this->dbc->isError($r)) return $r; if($this->dbc->isError($r)) return $r;
} }
} }
/** /**
* install - create tables * install - create tables
* *
@ -1386,6 +1424,7 @@ class BasicStor extends Alib{
* <li>incomplete</li> * <li>incomplete</li>
* <li>ready</li> * <li>ready</li>
* <li>edited</li> * <li>edited</li>
* <li>deleted</li>
* </ul> * </ul>
* file types: * file types:

View file

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.8 $ Version : $Revision: 1.9 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/DataEngine.php,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/DataEngine.php,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -100,7 +100,7 @@ class DataEngine{
$whereArr = array(); $whereArr = array();
if(is_array($conditions)){ if(is_array($conditions)){
foreach($conditions as $cond){ foreach($conditions as $cond){
$catQn = strtolower($cond['cat']); $catQn = $cond['cat'];
$op = strtolower($cond['op']); $op = strtolower($cond['op']);
$value = strtolower($cond['val']); $value = strtolower($cond['val']);
$splittedQn = XML_Util::splitQualifiedName($catQn); $splittedQn = XML_Util::splitQualifiedName($catQn);
@ -112,7 +112,8 @@ class DataEngine{
$opVal = str_replace("%", "%%", $opVal); $opVal = str_replace("%", "%%", $opVal);
$sqlCond = $sqlCond =
" %s.predicate = '{$cat}' AND". " %s.predicate = '{$cat}' AND".
" %s.objns='_L' AND lower(%s.object) {$opVal}\n"; " %s.objns='_L' AND %s.predxml='T'".
" AND lower(%s.object) {$opVal}\n";
if(!is_null($catNs)){ if(!is_null($catNs)){
$catNs = str_replace("%", "%%", $catNs); $catNs = str_replace("%", "%%", $catNs);
$sqlCond = " %s.predns = '{$catNs}' AND $sqlCond"; $sqlCond = " %s.predns = '{$catNs}' AND $sqlCond";
@ -140,7 +141,7 @@ class DataEngine{
{ {
$innerBlocks = array(); $innerBlocks = array();
foreach($whereArr as $i=>$v){ foreach($whereArr as $i=>$v){
$whereArr[$i] = sprintf($v, "md$i", "md$i", "md$i", "md$i"); $whereArr[$i] = sprintf($v, "md$i", "md$i", "md$i", "md$i", "md$i");
$lastTbl = ($i==0 ? "f" : "md".($i-1)); $lastTbl = ($i==0 ? "f" : "md".($i-1));
$innerBlocks[] = $innerBlocks[] =
"INNER JOIN {$this->mdataTable} md$i ON md$i.gunid = $lastTbl.gunid\n"; "INNER JOIN {$this->mdataTable} md$i ON md$i.gunid = $lastTbl.gunid\n";
@ -149,7 +150,8 @@ class DataEngine{
$sql = "SELECT $fldsPart\nFROM {$this->filesTable} f\n".join("", $innerBlocks); $sql = "SELECT $fldsPart\nFROM {$this->filesTable} f\n".join("", $innerBlocks);
if($browse){ if($browse){
$sql .= "INNER JOIN {$this->mdataTable} br". $sql .= "INNER JOIN {$this->mdataTable} br".
"\n ON br.gunid = f.gunid AND br.objns='_L' AND br.predicate='{$brFld}'"; "\n ON br.gunid = f.gunid AND br.objns='_L'".
" AND br.predicate='{$brFld}' AND br.predxml='T'";
if(!is_null($brFldNs)) $sql .= " AND br.predns='{$brFldNs}'"; if(!is_null($brFldNs)) $sql .= " AND br.predns='{$brFldNs}'";
$sql .= "\n"; $sql .= "\n";
} }
@ -178,7 +180,7 @@ class DataEngine{
$fldsPart, $whereArr, $fileCond, $browse, $brFldNs, $brFld); $fldsPart, $whereArr, $fileCond, $browse, $brFldNs, $brFld);
$isectBlocks = array(); $isectBlocks = array();
foreach($whereArr as $i=>$v){ foreach($whereArr as $i=>$v){
$whereArr[$i] = sprintf($v, "md$i", "md$i", "md$i", "md$i"); $whereArr[$i] = sprintf($v, "md$i", "md$i", "md$i", "md$i", "md$i");
$isectBlocks[] = $isectBlocks[] =
" SELECT gunid FROM {$this->mdataTable} md$i\n". " SELECT gunid FROM {$this->mdataTable} md$i\n".
" WHERE\n {$whereArr[$i]}"; " WHERE\n {$whereArr[$i]}";
@ -195,7 +197,7 @@ class DataEngine{
"SELECT $fldsPart\n".$isectBlock; "SELECT $fldsPart\n".$isectBlock;
if($browse){ if($browse){
$sql .= "\nINNER JOIN {$this->mdataTable} br ON br.gunid = f.gunid\n". $sql .= "\nINNER JOIN {$this->mdataTable} br ON br.gunid = f.gunid\n".
"WHERE br.objns='_L' AND br.predicate='{$brFld}'"; "WHERE br.objns='_L' AND br.predxml='T' AND br.predicate='{$brFld}'";
if(!is_null($brFldNs)) $sql .= " AND br.predns='{$brFldNs}'"; if(!is_null($brFldNs)) $sql .= " AND br.predns='{$brFldNs}'";
$glue = " AND"; $glue = " AND";
}else{ $glue = "WHERE";} }else{ $glue = "WHERE";}
@ -218,15 +220,16 @@ class DataEngine{
function _makeOrSql($fldsPart, $whereArr, $fileCond, $browse, function _makeOrSql($fldsPart, $whereArr, $fileCond, $browse,
$brFldNs=NULL, $brFld=NULL) $brFldNs=NULL, $brFld=NULL)
{ {
$whereArr[] = " FALSE\n"; //$whereArr[] = " FALSE\n";
foreach($whereArr as $i=>$v){ foreach($whereArr as $i=>$v){
$whereArr[$i] = sprintf($v, "md", "md", "md", "md"); $whereArr[$i] = sprintf($v, "md", "md", "md", "md", "md");
} }
// query construcion: // query construcion:
$sql = "SELECT $fldsPart\nFROM {$this->filesTable} f\n"; $sql = "SELECT $fldsPart\nFROM {$this->filesTable} f\n";
if($browse){ if($browse){
$sql .= "INNER JOIN {$this->mdataTable} br". $sql .= "INNER JOIN {$this->mdataTable} br".
"\n ON br.gunid = f.gunid AND br.objns='_L' AND br.predicate='{$brFld}'"; "\n ON br.gunid = f.gunid AND br.objns='_L'".
" AND br.predxml='T' AND br.predicate='{$brFld}'";
if(!is_null($brFldNs)) $sql .= " AND br.predns='{$brFldNs}'"; if(!is_null($brFldNs)) $sql .= " AND br.predns='{$brFldNs}'";
$sql .= "\n"; $sql .= "\n";
} }
@ -278,8 +281,8 @@ class DataEngine{
$operator = strtolower($criteria['operator']); $operator = strtolower($criteria['operator']);
$desc = (isset($criteria['desc']) ? $criteria['desc'] : NULL); $desc = (isset($criteria['desc']) ? $criteria['desc'] : NULL);
$whereArr = $this->_makeWhereArr($criteria['conditions']); $whereArr = $this->_makeWhereArr($criteria['conditions']);
$orderbyQn = (isset($criteria['orderby']) ? $orderbyQn =
strtolower($criteria['orderby']) : NULL); (isset($criteria['orderby']) ? $criteria['orderby'] : NULL);
$obSplitQn = XML_Util::splitQualifiedName($orderbyQn); $obSplitQn = XML_Util::splitQualifiedName($orderbyQn);
$obNs = $obSplitQn['namespace']; $obNs = $obSplitQn['namespace'];
$orderby = $obSplitQn['localPart']; $orderby = $obSplitQn['localPart'];
@ -309,7 +312,8 @@ class DataEngine{
"SELECT to_hex(sq2.gunid)as gunid, m.object\n". "SELECT to_hex(sq2.gunid)as gunid, m.object\n".
"FROM (\n$sql\n)sq2\n". "FROM (\n$sql\n)sq2\n".
"LEFT JOIN ls_mdata m\n". "LEFT JOIN ls_mdata m\n".
" ON m.gunid = sq2.gunid AND m.predicate='$orderby' AND m.objns='_L'". " ON m.gunid = sq2.gunid AND m.predicate='$orderby'".
" AND m.objns='_L' AND m.predxml='T'".
(!is_null($obNs)? " AND m.predns='$obNs'":'')."\n". (!is_null($obNs)? " AND m.predns='$obNs'":'')."\n".
"ORDER BY m.object".($desc? ' DESC':'')."\n"; "ORDER BY m.object".($desc? ' DESC':'')."\n";
} }
@ -339,14 +343,14 @@ class DataEngine{
*/ */
function browseCategory($category, $limit=0, $offset=0, $criteria=NULL) function browseCategory($category, $limit=0, $offset=0, $criteria=NULL)
{ {
$category = strtolower($category); //$category = strtolower($category);
$r = XML_Util::splitQualifiedName($category); $r = XML_Util::splitQualifiedName($category);
$catNs = $r['namespace']; $catNs = $r['namespace'];
$cat = $r['localPart']; $cat = $r['localPart'];
if(is_array($criteria) && count($criteria)>0){ if(is_array($criteria) && count($criteria)>0){
return $this->_localGenSearch($criteria, $limit, $offset, $catNs, $cat); return $this->_localGenSearch($criteria, $limit, $offset, $catNs, $cat);
} }
$sqlCond = "m.predicate='$cat' AND m.objns='_L'"; $sqlCond = "m.predicate='$cat' AND m.objns='_L' AND m.predxml='T'";
if(!is_null($catNs)){ if(!is_null($catNs)){
$sqlCond = "m.predns = '{$catNs}' AND $sqlCond"; $sqlCond = "m.predns = '{$catNs}' AND $sqlCond";
} }

View file

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.57 $ Version : $Revision: 1.58 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/GreenBox.php,v $ 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 * LiveSupport file storage module
* *
* @author $Author: tomas $ * @author $Author: tomas $
* @version $Revision: 1.57 $ * @version $Revision: 1.58 $
* @see BasicStor * @see BasicStor
*/ */
class GreenBox extends BasicStor{ class GreenBox extends BasicStor{
@ -222,41 +222,6 @@ class GreenBox extends BasicStor{
return $this->bsDeleteFile($id); return $this->bsDeleteFile($id);
} }
/* ---------------------------------------------- replicas, versions etc. */
/**
* Create replica.<br>
* <b>TODO: NOT FINISHED</b>
*
* @param id int, virt.file's local id
* @param did int, destination folder local id
* @param replicaName string, name of new replica
* @param sessid string, session id
* @return int, local id of new object
*/
function createReplica($id, $did, $replicaName='', $sessid='')
{
if(($res = $this->_authorize(
array('read', 'write'), array($id, $did), $sessid
)) !== TRUE) return $res;
return $this->bsCreateReplica($id, $did, $replicaName);
}
/**
* Create version.<br>
* <b>TODO: NOT FINISHED</b>
*
* @param id int, virt.file's local id
* @param did int, destination folder local id
* @param versionLabel string, name of new version
* @param sessid string, session id
* @return int, local id of new object
*/
function createVersion($id, $did, $versionLabel, $sessid='')
{
return $this->bsCreateVersion($id, $did, $versionLabel);
}
/* ------------------------------------------------------------- metadata */ /* ------------------------------------------------------------- metadata */
/** /**
@ -867,17 +832,50 @@ class GreenBox extends BasicStor{
return $pa; return $pa;
} }
/**
* Change user password.
*
* ('superuser mode'= superuser is changing some password without
* knowledge of the old password)
*
* @param login string
* @param oldpass string, old password
* (should be null or empty for 'superuser mode')
* @param pass string, optional
* @param sessid string, session id, required for 'superuser mode'
* @return boolean/err
*/
function passwd($login, $oldpass=null, $pass='', $sessid='')
{
if(is_null($oldpass) || $oldpass == ''){
if(($res = $this->_authorize('subjects', $this->rootId, $sessid))
!== TRUE
){ sleep(2); return $res; }
else $oldpass=null;
}else{
if(FALSE === $this->authenticate($login, $oldpass)){
sleep(2);
return PEAR::raiseError(
"GreenBox::passwd: access denied (oldpass)", GBERR_DENY);
}
}
return PEAR::raiseError("GreenBox::passwd: OK");
$res = parent::passwd($login, $oldpass, $pass);
if(PEAR::isError($res)) return $res;
return TRUE;
}
/** /**
* Insert permission record * Insert permission record
* *
* @param sessid string, session id
* @param sid int - local user/group id * @param sid int - local user/group id
* @param action string * @param action string
* @param oid int - local object id * @param oid int - local object id
* @param type char - 'A'|'D' (allow/deny) * @param type char - 'A'|'D' (allow/deny)
* @param sessid string, session id
* @return int - local permission id * @return int - local permission id
*/ */
function addPerm($sessid, $sid, $action, $oid, $type='A') function addPerm($sid, $action, $oid, $type='A', $sessid='')
{ {
$parid = $this->getParent($oid); $parid = $this->getParent($oid);
if(($res = $this->_authorize('editPerms', $parid, $sessid)) !== TRUE){ if(($res = $this->_authorize('editPerms', $parid, $sessid)) !== TRUE){
@ -889,14 +887,15 @@ class GreenBox extends BasicStor{
/** /**
* Remove permission record * Remove permission record
* *
* @param sessid string, session id
* @param permid int OPT - local permission id * @param permid int OPT - local permission id
* @param subj int OPT - local user/group id * @param subj int OPT - local user/group id
* @param obj int OPT - local object id * @param obj int OPT - local object id
* @param sessid string, session id
* @return boolean/error * @return boolean/error
*/ */
function removePerm($sessid, $permid=NULL, $subj=NULL, $obj=NULL) function removePerm($permid=NULL, $subj=NULL, $obj=NULL, $sessid='')
{ {
if(!is_null($permid)){
$oid = $this->_getPermOid($permid); $oid = $this->_getPermOid($permid);
if(PEAR::isError($oid)) return $oid; if(PEAR::isError($oid)) return $oid;
if(!is_null($oid)){ if(!is_null($oid)){
@ -904,6 +903,7 @@ class GreenBox extends BasicStor{
if(($res = $this->_authorize('editPerms', $parid, $sessid)) !== TRUE) if(($res = $this->_authorize('editPerms', $parid, $sessid)) !== TRUE)
return $res; return $res;
} }
}
$res = parent::removePerm($permid, $subj, $obj); $res = parent::removePerm($permid, $subj, $obj);
return $res; return $res;
} }