From 82875a06f3663d979e5c65164773b08e1049e4ff Mon Sep 17 00:00:00 2001 From: tomas Date: Fri, 21 Jan 2005 13:42:40 +0000 Subject: [PATCH] getMdataValue method added --- .../modules/storageServer/var/BasicStor.php | 42 ++++++++++++++++++- .../modules/storageServer/var/GreenBox.php | 19 ++++++++- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/livesupport/modules/storageServer/var/BasicStor.php b/livesupport/modules/storageServer/var/BasicStor.php index 0a35ab71e..83dfe2057 100644 --- a/livesupport/modules/storageServer/var/BasicStor.php +++ b/livesupport/modules/storageServer/var/BasicStor.php @@ -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/BasicStor.php,v $ ------------------------------------------------------------------------------*/ @@ -52,7 +52,7 @@ require_once "Transport.php"; * Core of LiveSupport file storage module * * @author $Author: tomas $ - * @version $Revision: 1.22 $ + * @version $Revision: 1.23 $ * @see Alib */ class BasicStor extends Alib{ @@ -597,6 +597,43 @@ class BasicStor extends Alib{ return $ac->getMetaData(); } + /** + * Get metadata element value + * + * @param id int, virt.file's local id + * @param category string, metadata element name + * @return array of matching records + */ + function bsGetMetadataValue($id, $category) + { + $gunid = $this->_gunidFromId($id); + if(PEAR::isError($gunid)) return $gunid; + if(is_null($gunid)){ + return PEAR::raiseError( + "BasicStor::bsGetMdataValue: file not found ($id)", + GBERR_NOTF + ); + } + $catOrig = strtolower($category); + // handle predicate namespace shortcut + if(preg_match("|^([^:]+):([^:]+)$|", $catOrig, $catOrigArr)){ + $catNs = $catOrigArr[1]; $cat = $catOrigArr[2]; + }else{ $catNs=NULL; $cat=$catOrig; } + $cond = " + gunid=x'$gunid'::bigint AND objns='_L' AND + predicate='$cat' + "; + if(!is_null($catNs)) $cond .= " AND predns='$catNs'"; + $sql = " + SELECT object + FROM {$this->mdataTable} + WHERE $cond + "; + $res = $this->dbc->getCol($sql); + if(PEAR::isError($res)) return $res; + return $res; + } + /** * Search in local metadata database. * @@ -688,6 +725,7 @@ class BasicStor extends Alib{ } $rh = $this->dbc->query($sql); $cnt = $rh->numRows(); $rh->free(); $res = $this->dbc->getCol($sql.$limitPart); + if(PEAR::isError($res)) return $res; if(!is_array($res)) $res = array(); $res = array_map(array("StoredFile", "_normalizeGunid"), $res); # return array('sql'=>$sql, 'results'=>$res); diff --git a/livesupport/modules/storageServer/var/GreenBox.php b/livesupport/modules/storageServer/var/GreenBox.php index 6ebcb1ae6..483edd803 100644 --- a/livesupport/modules/storageServer/var/GreenBox.php +++ b/livesupport/modules/storageServer/var/GreenBox.php @@ -23,7 +23,7 @@ Author : $Author: tomas $ - Version : $Revision: 1.24 $ + Version : $Revision: 1.25 $ 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.24 $ + * @version $Revision: 1.25 $ * @see BasicStor */ class GreenBox extends BasicStor{ @@ -226,6 +226,21 @@ class GreenBox extends BasicStor{ return $this->bsGetMetadata($id); } + /** + * Get metadata element value + * + * @param id int, virt.file's local id + * @param category string, metadata element name + * @param sessid string, session id + * @return array of matching records + */ + function getMdataValue($id, $category, $sessid='') + { + if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE) + return $res; + return $this->bsGetMetadataValue($id, $category); + } + /** * Search in local metadata database. *