From a7698073cb38d761d6a375a9b21d64a86509cf5e Mon Sep 17 00:00:00 2001 From: tomas Date: Tue, 28 Dec 2004 00:47:04 +0000 Subject: [PATCH] ftype added to files db table, resolved bug from report 0000513 at http://bugs.campware.org/view.php?id=482 --- .../modules/storageServer/var/BasicStor.php | 26 +++++--- .../modules/storageServer/var/GreenBox.php | 10 +-- .../modules/storageServer/var/LocStor.php | 20 +++++- .../modules/storageServer/var/MetaData.php | 4 +- .../modules/storageServer/var/StoredFile.php | 66 ++++++++++++++----- .../storageServer/var/xmlrpc/testRunner.sh | 39 +++++++---- .../storageServer/var/xmlrpc/xr_cli_test.py | 4 +- 7 files changed, 122 insertions(+), 47 deletions(-) diff --git a/livesupport/modules/storageServer/var/BasicStor.php b/livesupport/modules/storageServer/var/BasicStor.php index 2743c6e93..3da7a0ad6 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.5 $ + Version : $Revision: 1.6 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/BasicStor.php,v $ ------------------------------------------------------------------------------*/ @@ -48,7 +48,7 @@ require_once "Transport.php"; * Core of LiveSupport file storage module * * @author $Author: tomas $ - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * @see Alib */ class BasicStor extends Alib{ @@ -108,16 +108,18 @@ class BasicStor extends Alib{ * @param mediaFileLP string, local path of media file * @param mdataFileLP string, local path of metadata file * @param gunid string, global unique id OPTIONAL + * @param ftype string, internal file type * @return int * @exception PEAR::error */ function bsPutFile($parid, $fileName, - $mediaFileLP, $mdataFileLP, $gunid=NULL) + $mediaFileLP, $mdataFileLP, $gunid=NULL, $ftype='unKnown') { $name = "$fileName"; $id = $this->addObj($name , 'File', $parid); $ac =& StoredFile::insert( - &$this, $id, $name, $mediaFileLP, $mdataFileLP, 'file', $gunid + &$this, $id, $name, $mediaFileLP, $mdataFileLP, 'file', + $gunid, $ftype ); if(PEAR::isError($ac)) return $ac; return $id; @@ -971,16 +973,24 @@ class BasicStor extends Alib{ *
  • ready
  • *
  • edited
  • * + + * file types: + * */ function install() { parent::install(); - echo "{$this->filesTable}\n"; + #echo "{$this->filesTable}\n"; $r = $this->dbc->query("CREATE TABLE {$this->filesTable} ( id int not null, gunid bigint not null, -- global unique ID name varchar(255) not null default'', -- human file id ;) - type varchar(255) not null default'', -- mime type + mime varchar(255) not null default'', -- mime type + ftype varchar(128) not null default'', -- file type state varchar(128) not null default'empty', -- file state currentlyAccessing int not null default 0 -- access counter )"); @@ -992,7 +1002,7 @@ class BasicStor extends Alib{ $this->dbc->query("CREATE INDEX {$this->filesTable}_name_idx ON {$this->filesTable} (name)"); - echo "{$this->mdataTable}\n"; + #echo "{$this->mdataTable}\n"; $this->dbc->createSequence("{$this->mdataTable}_id_seq"); $r = $this->dbc->query("CREATE TABLE {$this->mdataTable} ( id int not null, @@ -1015,7 +1025,7 @@ class BasicStor extends Alib{ $this->dbc->query("CREATE INDEX {$this->mdataTable}_pred_idx ON {$this->mdataTable} (predns, predicate)"); - echo "{$this->accessTable}\n"; + #echo "{$this->accessTable}\n"; $r = $this->dbc->query("CREATE TABLE {$this->accessTable} ( gunid bigint, sessid char(32) not null default'', diff --git a/livesupport/modules/storageServer/var/GreenBox.php b/livesupport/modules/storageServer/var/GreenBox.php index c03fb82be..d1f9df93e 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.13 $ + Version : $Revision: 1.14 $ 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.13 $ + * @version $Revision: 1.14 $ * @see BasicStor */ class GreenBox extends BasicStor{ @@ -67,16 +67,18 @@ class GreenBox extends BasicStor{ * @param mdataFileLP string, local path of metadata file * @param sessid string, session id * @param gunid string, global unique id OPTIONAL + * @param ftype string, internal file type * @return int * @exception PEAR::error */ function putFile($parid, $fileName, - $mediaFileLP, $mdataFileLP, $sessid='', $gunid=NULL) + $mediaFileLP, $mdataFileLP, $sessid='', + $gunid=NULL, $ftype='audioclip') { if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE) return $res; return $this->bsPutFile( - $parid, $fileName, $mediaFileLP, $mdataFileLP, $gunid + $parid, $fileName, $mediaFileLP, $mdataFileLP, $gunid, $ftype ); } diff --git a/livesupport/modules/storageServer/var/LocStor.php b/livesupport/modules/storageServer/var/LocStor.php index 2913eadfb..be16b17c9 100644 --- a/livesupport/modules/storageServer/var/LocStor.php +++ b/livesupport/modules/storageServer/var/LocStor.php @@ -23,7 +23,7 @@ Author : $Author: tomas $ - Version : $Revision: 1.12 $ + Version : $Revision: 1.13 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/LocStor.php,v $ ------------------------------------------------------------------------------*/ @@ -79,7 +79,8 @@ class LocStor extends GreenBox{ $oid = $this->addObj($tmpid , 'File', $parid); if(PEAR::isError($oid)) return $oid; $ac =& StoredFile::insert( - &$this, $oid, '', '', $metadata, 'string', $gunid + &$this, $oid, '', '', $metadata, 'string', + $gunid, 'audioclip' ); if(PEAR::isError($ac)){ $res = $this->removeObj($oid); @@ -255,6 +256,20 @@ class LocStor extends GreenBox{ * @see GreenBox */ function existsAudioClip($sessid, $gunid) + { + return LocStor::existsFile($sessid, $gunid, 'audioclip'); + } + + /** + * Check if file exists in the storage + * + * @param sessid string + * @param gunid string + * @param ftype string, internal file type + * @return boolean + * @see GreenBox + */ + function existsFile($sessid, $gunid, $ftype=NULL) { $ac =& StoredFile::recallByGunid(&$this, $gunid); if(PEAR::isError($ac)){ @@ -267,6 +282,7 @@ class LocStor extends GreenBox{ default: return $ac; } } + if(!is_null($ftype) && $ac->_getType() != $ftype) return FALSE; if(($res = $this->_authorize('read', $ac->getId(), $sessid)) !== TRUE) return $res; return $ac->exists(); diff --git a/livesupport/modules/storageServer/var/MetaData.php b/livesupport/modules/storageServer/var/MetaData.php index cc3ac6aa0..1b1a2d6c4 100644 --- a/livesupport/modules/storageServer/var/MetaData.php +++ b/livesupport/modules/storageServer/var/MetaData.php @@ -23,7 +23,7 @@ Author : $Author: tomas $ - Version : $Revision: 1.6 $ + Version : $Revision: 1.7 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/MetaData.php,v $ ------------------------------------------------------------------------------*/ @@ -386,7 +386,7 @@ class MetaData{ $row = $this->dbc->getRow(" SELECT * FROM {$this->mdataTable} WHERE gunid=x'{$this->gunid}'::bigint - AND subjns='_G' AND subject=x'{$this->gunid}'::bigint + AND subjns='_G' AND subject='{$this->gunid}' "); if(PEAR::isError($row)) return $row; if(is_null($row)){ diff --git a/livesupport/modules/storageServer/var/StoredFile.php b/livesupport/modules/storageServer/var/StoredFile.php index e962cc9b8..31287033c 100644 --- a/livesupport/modules/storageServer/var/StoredFile.php +++ b/livesupport/modules/storageServer/var/StoredFile.php @@ -23,7 +23,7 @@ Author : $Author: tomas $ - Version : $Revision: 1.9 $ + Version : $Revision: 1.10 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/StoredFile.php,v $ ------------------------------------------------------------------------------*/ @@ -83,21 +83,22 @@ class StoredFile{ * @return instace of StoredFile object */ function insert(&$gb, $oid, $name, - $mediaFileLP='', $metadata='', $mdataLoc='file', $gunid=NULL) + $mediaFileLP='', $metadata='', $mdataLoc='file', + $gunid=NULL, $type=NULL) { $ac =& new StoredFile(&$gb, ($gunid ? $gunid : NULL)); $ac->name = $name; $ac->id = $oid; - $ac->type = "unKnown"; + $ac->mime = "unKnown"; $emptyState = TRUE; if($ac->name=='') $ac->name=$ac->gunid; $this->dbc->query("BEGIN"); $res = $ac->dbc->query(" INSERT INTO {$ac->filesTable} - (id, name, gunid, type, state) + (id, name, gunid, mime, state, ftype) VALUES ('$oid', '{$ac->name}', x'{$ac->gunid}'::bigint, - '{$ac->type}', 'incomplete') + '{$ac->mime}', 'incomplete', '$type') "); if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; } // --- metadata insert: @@ -159,7 +160,7 @@ class StoredFile{ : "gunid=x'$gunid'::bigint" ); $row = $gb->dbc->getRow(" - SELECT id, to_hex(gunid)as gunid, type, name + SELECT id, to_hex(gunid)as gunid, mime, name FROM {$gb->filesTable} WHERE $cond "); if(PEAR::isError($row)) return $row; @@ -171,7 +172,7 @@ class StoredFile{ } $gunid = StoredFile::_normalizeGunid($row['gunid']); $ac =& new StoredFile(&$gb, $gunid); - $ac->type = $row['type']; + $ac->mime = $row['mime']; $ac->name = $row['name']; $ac->id = $row['id']; return $ac; @@ -220,7 +221,10 @@ class StoredFile{ */ function copyOf(&$src, $nid) { - $ac =& StoredFile::insert(&$src->gb, $nid, $src->name, $src->_getRealRADFname(), ''); + $ac =& StoredFile::insert( + &$src->gb, $nid, $src->name, $src->_getRealRADFname(), + '', '', NULL, $src->_getType() + ); if(PEAR::isError($ac)) return $ac; $ac->md->replace($src->md->getMetaData(), 'xml'); return $ac; @@ -441,13 +445,13 @@ class StoredFile{ /** * Set mime-type of virtual file * - * @param type string, mime-type + * @param mime string, mime-type * @return boolean or error */ - function setType($type) + function setType($mime) { $res = $this->dbc->query(" - UPDATE {$this->filesTable} SET type='$type' + UPDATE {$this->filesTable} SET mime='$mime' WHERE gunid=x'{$this->gunid}'::bigint "); if(PEAR::isError($res)){ return $res; } @@ -576,7 +580,7 @@ class StoredFile{ */ function _getExt() { - switch($this->type){ + switch($this->mime){ case"audio/mpeg": $ext="mp3"; break; case"audio/x-wave": $ext="wav"; break; case"application/x-ogg": $ext="ogg"; break; @@ -586,14 +590,46 @@ class StoredFile{ } /** - * Get filetype from global id + * Get mime-type from global id * * @param gunid string, optional, global unique id of file + * @return string, mime-type */ - function _getType($gunid) + function _getMime($gunid=NULL) { + if(is_null($gunid)) $gunid = $this->gunid; return $this->dbc->getOne(" - SELECT type FROM {$this->filesTable} + SELECT mime FROM {$this->filesTable} + WHERE gunid=x'$gunid'::bigint + "); + } + + /** + * Get storage-internal file type + * + * @param gunid string, optional, global unique id of file + * @return string, see install() + */ + function _getType($gunid=NULL) + { + if(is_null($gunid)) $gunid = $this->gunid; + return $this->dbc->getOne(" + SELECT ftype FROM {$this->filesTable} + WHERE gunid=x'$gunid'::bigint + "); + } + + /** + * Get storage-internal file state + * + * @param gunid string, optional, global unique id of file + * @return string, see install() + */ + function _getState($gunid=NULL) + { + if(is_null($gunid)) $gunid = $this->gunid; + return $this->dbc->getOne(" + SELECT state FROM {$this->filesTable} WHERE gunid=x'$gunid'::bigint "); } diff --git a/livesupport/modules/storageServer/var/xmlrpc/testRunner.sh b/livesupport/modules/storageServer/var/xmlrpc/testRunner.sh index 8276a761f..abf9dbd57 100755 --- a/livesupport/modules/storageServer/var/xmlrpc/testRunner.sh +++ b/livesupport/modules/storageServer/var/xmlrpc/testRunner.sh @@ -23,7 +23,7 @@ # # # Author : $Author: tomas $ -# Version : $Revision: 1.8 $ +# Version : $Revision: 1.9 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/testRunner.sh,v $ #------------------------------------------------------------------------------- @@ -33,6 +33,9 @@ COMM=$1 shift GUNID=$1 +METADATA=" +ěščřžé" + echo "" XMLRPC=`cd var/install; php -q getXrUrl.php` || exit $? echo "# storageServer XMLRPC URL: $XMLRPC" @@ -52,7 +55,7 @@ test() { } existsAudioClip() { - echo "# existsAudioClip: " + echo -n "# existsAudioClip (${GUNID}): " $XR_CLI existsAudioClip $SESSID $GUNID || exit $? } @@ -60,23 +63,20 @@ storeAudioClip() { # echo -n "# storeAudioClip: " # MEDIA=../tests/ex1.mp3 MEDIA=var/tests/ex1.mp3 -# METADATA=var/tests/mdata4.xml -# RGUNID=`$XR_CLI storeAudioClip "$SESSID" '' "$MEDIA" "$METADATA"` || \ -# { ERN=$?; echo $RGUNID; exit $ERN; } MD5=`md5sum $MEDIA`; for i in $MD5; do MD5=$i; break; done echo "md5=$MD5" echo -n "# storeAudioClipOpen: " - RES=`$XR_CLI storeAudioClipOpen "$SESSID" '' 'ěščřžé' "$MD5"` || \ + RES=`$XR_CLI storeAudioClipOpen "$SESSID" '' "$METADATA" "$MD5"` || \ { ERN=$?; echo $RES; exit $ERN; } unset URL for i in $RES; do if [ -z $URL ] ; then URL=$i; else TOKEN=$i; fi; done echo $TOKEN echo $URL - if [ $DEBUG ]; then echo -n "Pres a key ..."; read KEY; fi + if [ $DEBUG ]; then echo -n "Press enter ..."; read KEY; fi echo -n "# curl (PUT): " curl -C 0 -T $MEDIA $URL || { ERN=$?; echo $RGUNID; exit $ERN; } echo "status: $?" - if [ $DEBUG ]; then echo -n "Pres a key ..."; read KEY; fi + if [ $DEBUG ]; then echo -n "Press enter ..."; read KEY; fi echo -n "# storeAudioClipClose: " RGUNID=`$XR_CLI storeAudioClipClose "$SESSID" "$TOKEN"` || \ { ERN=$?; echo $RGUNID; exit $ERN; } @@ -91,7 +91,7 @@ accessRawAudioData() { for i in $RES; do if [ -z $URL ] ; then URL=$i; else TOKEN=$i; fi; done echo $TOKEN echo $URL - if [ $DEBUG ]; then echo -n "Pres a key ..."; read KEY; fi + if [ $DEBUG ]; then echo -n "Press enter ..."; read KEY; fi echo -n "# releaseRawAudioData: " $XR_CLI releaseRawAudioData $SESSID $TOKEN || exit $? } @@ -104,7 +104,7 @@ downloadRAD() { for i in $RES; do if [ -z $URL ] ; then URL=$i; else TOKEN=$i; fi; done echo $TOKEN echo $URL - if [ $DEBUG ]; then echo -n "Pres a key ..."; read KEY; fi + if [ $DEBUG ]; then echo -n "Press enter ..."; read KEY; fi echo -n "# curl: " curl -Ifs $URL > /dev/null || { ERN=$?; echo $RES; exit $ERN; } echo "status: $?" @@ -120,12 +120,21 @@ downloadMeta() { for i in $RES; do if [ -z $URL ] ; then URL=$i; else TOKEN=$i; fi; done echo $TOKEN echo $URL - if [ $DEBUG ]; then echo -n "Pres a key ..."; read KEY; fi + if [ $DEBUG ]; then echo -n "Press enter ..."; read KEY; fi echo -n "# curl: " - if [ $DEBUG ]; then lynx -source $URL; else - curl -Ifs $URL > /dev/null || { ERN=$?; echo $RES; exit $ERN; } +# curl -Ifs $URL > /dev/null || { ERN=$?; echo $RES; exit $ERN; } + METAOUT=`curl -fs $URL;` || { ERN=$?; echo $RES; exit $ERN; } + echo "OK" + if [ $DEBUG ]; then echo $METAOUT; echo -n "Press enter ..."; read KEY; fi + echo -n "# metadata check:" + if [ "x$METAOUT" != "x$METADATA" ] ; then + echo " NOT MATCH" + echo " Expected:"; echo $METADATA + echo " Downloaded:"; echo $METAOUT + exit 1 + else + echo " OK" fi - echo "status: $?" echo -n "# downloadMetadataClose: " $XR_CLI downloadMetadataClose $SESSID $TOKEN || exit $? } @@ -199,10 +208,12 @@ elif [ "x$COMM" == "x" ]; then login storeAudioClip GUNID=$RGUNID + existsAudioClip accessRawAudioData downloadRAD downloadMeta deleteAudioClip + existsAudioClip logout echo "#XMLRPC tests: OK." echo "" diff --git a/livesupport/modules/storageServer/var/xmlrpc/xr_cli_test.py b/livesupport/modules/storageServer/var/xmlrpc/xr_cli_test.py index 6f3861fdd..490671f58 100755 --- a/livesupport/modules/storageServer/var/xmlrpc/xr_cli_test.py +++ b/livesupport/modules/storageServer/var/xmlrpc/xr_cli_test.py @@ -24,7 +24,7 @@ # # # Author : $Author: tomas $ -# Version : $Revision: 1.7 $ +# Version : $Revision: 1.8 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/Attic/xr_cli_test.py,v $ # #------------------------------------------------------------------------------ @@ -113,7 +113,7 @@ try: elif method=="deleteAudioClip": print server.locstor.deleteAudioClip({'sessid':pars[0], 'gunid':pars[1]}) elif method=="existsAudioClip": - print server.locstor.existsAudioClip({'sessid':pars[0], 'gunid':pars[1]} )['exists'] + print server.locstor.existsAudioClip({'sessid':pars[0], 'gunid':pars[1]}) elif method=="updateAudioClipMetadata": print server.locstor.updateAudioClipMetadata({'sessid':pars[0], 'gunid':pars[1], 'mdataFileLP':pars[2]}) elif method=="searchMetadata":