diff --git a/livesupport/modules/storageServer/Makefile b/livesupport/modules/storageServer/Makefile index 9fcb3fe12..dea69fcd2 100644 --- a/livesupport/modules/storageServer/Makefile +++ b/livesupport/modules/storageServer/Makefile @@ -20,7 +20,7 @@ # # # Author : $Author: tomas $ -# Version : $Revision: 1.8 $ +# Version : $Revision: 1.9 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/Attic/Makefile,v $ # # @configure_input@ @@ -119,7 +119,6 @@ distclean: clean docclean testonly: ${TEST_RUNNER} ${TEST_RUNNER} - ${TEST_RUNNER} playlists # $(MAKE) transtest check: all testonly diff --git a/livesupport/modules/storageServer/bin/runPhpTest.sh b/livesupport/modules/storageServer/bin/runPhpTest.sh new file mode 100755 index 000000000..0cb33fe87 --- /dev/null +++ b/livesupport/modules/storageServer/bin/runPhpTest.sh @@ -0,0 +1,36 @@ +#!/bin/bash +#------------------------------------------------------------------------------- +# Copyright (c) 2004 Media Development Loan Fund +# +# This file is part of the LiveSupport project. +# http://livesupport.campware.org/ +# To report bugs, send an e-mail to bugs@campware.org +# +# LiveSupport is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# LiveSupport is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LiveSupport; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# +# Author : $Author: tomas $ +# Version : $Revision: 1.1 $ +# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/bin/runPhpTest.sh,v $ +#------------------------------------------------------------------------------- + +#------------------------------------------------------------------------------- +# +#------------------------------------------------------------------------------- + +reldir=`dirname $0`/.. +cd $reldir/var/tests +php -q $1 || exit $? +exit 0 diff --git a/livesupport/modules/storageServer/var/BasicStor.php b/livesupport/modules/storageServer/var/BasicStor.php index 8acf87a0b..f4ad54c14 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.12 $ + Version : $Revision: 1.13 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/BasicStor.php,v $ ------------------------------------------------------------------------------*/ @@ -35,6 +35,7 @@ define('GBERR_WRTYPE', 44); define('GBERR_NONE', 45); define('GBERR_AOBJNEX', 46); define('GBERR_NOTF', 47); +define('GBERR_SESS', 48); define('GBERR_NOTIMPL', 50); @@ -48,7 +49,7 @@ require_once "StoredFile.php"; * Core of LiveSupport file storage module * * @author $Author: tomas $ - * @version $Revision: 1.12 $ + * @version $Revision: 1.13 $ * @see Alib */ class BasicStor extends Alib{ diff --git a/livesupport/modules/storageServer/var/MetaData.php b/livesupport/modules/storageServer/var/MetaData.php index 72151fc11..7c3de0e26 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.9 $ + Version : $Revision: 1.10 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/MetaData.php,v $ ------------------------------------------------------------------------------*/ @@ -148,7 +148,7 @@ class MetaData{ */ function delete() { - if(file_exists($fname)) @unlink($this->fname); + if(file_exists($this->fname)) @unlink($this->fname); $res = $this->dbc->query(" DELETE FROM {$this->mdataTable} WHERE gunid=x'{$this->gunid}'::bigint diff --git a/livesupport/modules/storageServer/var/Prefs.php b/livesupport/modules/storageServer/var/Prefs.php new file mode 100644 index 000000000..da5c9af62 --- /dev/null +++ b/livesupport/modules/storageServer/var/Prefs.php @@ -0,0 +1,247 @@ +gb =& $gb; + $this->dbc =& $gb->dbc; + $this->prefTable = $gb->config['tblNamePrefix'].'pref'; + } + + /* ======================================================= public methods */ + /** + * Read preference record by session id + * + * @param sessid string, session id + * @param key string, preference key + * @return string, preference value + */ + function loadPref($sessid, $key) + { + $subjid = $this->gb->getSessUserId($sessid); + if(PEAR::isError($subjid)) return $subjid; + if(is_null($subjid)){ + return PEAR::raiseError("Prefs::loadPref: invalid session id", + GBERR_SESS); + } + $val = $this->readVal($subjid, $key); + if(PEAR::isError($val)) return $val; + return $val; + } + + /** + * Save preference record by session id + * + * @param sessid string, session id + * @param key string, preference key + * @param value string, preference value + * @return boolean + */ + function savePref($sessid, $key, $value) + { + $subjid = $this->gb->getSessUserId($sessid); + if(PEAR::isError($subjid)) return $subjid; + if(is_null($subjid)){ + return PEAR::raiseError("Prefs::loadPref: invalid session id", + GBERR_SESS); + } + $r = $this->delete($subjid, $key); + if(PEAR::isError($r)) return $r; + if($value != ''){ + $r = $this->insert($subjid, $key, $value); + if(PEAR::isError($r)) return $r; + } + return TRUE; + } + + /* ===================================================== gb level methods */ + /** + * Insert of new preference record + * + * @param subjid int, local user id + * @param keystr string, preference key + * @param valstr string, preference value + * @return int, local user id + */ + function insert($subjid, $keystr, $valstr='') + { + $id = $this->dbc->nextId("{$this->prefTable}_id_seq"); + if(PEAR::isError($id)) return $id; + $r = $this->dbc->query(" + INSERT INTO {$this->prefTable} + (id, subjid, keystr, valstr) + VALUES + ($id, $subjid, '$keystr', '$valstr') + "); + if(PEAR::isError($r)) return $r; + return $id; + } + + /** + * Read value of preference record + * + * @param subjid int, local user id + * @param keystr string, preference key + * @return string, preference value + */ + function readVal($subjid, $keystr) + { + $val = $this->dbc->getOne(" + SELECT valstr FROM {$this->prefTable} + WHERE subjid=$subjid AND keystr='$keystr' + "); + if(PEAR::isError($val)) return $val; + if(is_null($val)) return ''; + return $val; + } + + /** + * Update value of preference record + * + * @param subjid int, local user id + * @param keystr string, preference key + * @param newvalstr string, new preference value + * @return boolean + */ + function update($subjid, $keystr, $newvalstr='') + { + $r = $this->dbc->query(" + UPDATE {$this->prefTable} SET + valstr='$newvalstr' + WHERE subjid=$subjid AND keystr='$keystr' + "); + if(PEAR::isError($r)) return $r; + return TRUE; + } + + /** + * Delete preference record + * + * @param subjid int, local user id + * @param keystr string, preference key + * @return boolean + */ + function delete($subjid, $keystr) + { + $r = $this->dbc->query(" + DELETE FROM {$this->prefTable} + WHERE subjid=$subjid AND keystr='$keystr' + "); + if(PEAR::isError($r)) return $r; + return TRUE; + } + + /* ==================================================== auxiliary methods */ + /** + * Test method + * + */ + function test() + { + $sessid = $this->gb->login('root', $this->gb->config['tmpRootPass']); + $testkey = 'testKey'; + $testVal = 'abcDef 0123 ěščřžýáíé ĚŠČŘŽÝÁÍÉ'; + $r = savePref($sessid, $testKey, $testVal); + if(PEAR::isError($r)) return $r; + $val = loadPref($sessid, $testKey); + if($val != $testVal){ + echo "ERROR: preference storage test failed.\n ($testVal / $val)\n"; + return FALSE; + } + $r = savePref($sessid, $testKey, ''); + if(PEAR::isError($r)) return $r; + $val = loadPref($sessid, $testKey); + if($val != $testVal){ + echo "ERROR: preference storage test failed.\n ('' / '$val')\n"; + return FALSE; + } + return TRUE; + } + + /** + * Install database table for preference storage + * + * @return boolean + */ + function install() + { + $this->dbc->createSequence("{$this->prefTable}_id_seq"); + $r = $this->dbc->query("CREATE TABLE {$this->prefTable} ( + id int not null, + subjid int REFERENCES {$this->gb->subjTable} ON DELETE CASCADE, + keystr varchar(255), + valstr text + )"); + if(PEAR::isError($r)) return $r; + $this->dbc->query("CREATE UNIQUE INDEX {$this->prefTable}_id_idx + ON {$this->prefTable} (id)"); + $this->dbc->query("CREATE UNIQUE INDEX {$this->prefTable}_subj_key_idx + ON {$this->prefTable} (subjid, keystr)"); + $this->dbc->query("CREATE INDEX {$this->prefTable}_subjid_idx + ON {$this->prefTable} (subjid)"); + return TRUE; + } + + /** + * Uninstall database table for preference storage + * + * @return boolean + */ + function uninstall() + { + $this->dbc->query("DROP TABLE {$this->prefTable}"); + $this->dbc->dropSequence("{$this->prefTable}_id_seq"); + } + + /** + * + * / + function () + { + }*/ + +} +?> diff --git a/livesupport/modules/storageServer/var/RawMediaData.php b/livesupport/modules/storageServer/var/RawMediaData.php index 17b555039..868768422 100644 --- a/livesupport/modules/storageServer/var/RawMediaData.php +++ b/livesupport/modules/storageServer/var/RawMediaData.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/RawMediaData.php,v $ ------------------------------------------------------------------------------*/ @@ -37,7 +37,6 @@ * @see StoredFile */ -/* ================== RawMediaData ================== */ class RawMediaData{ /** @@ -216,4 +215,4 @@ class RawMediaData{ return $log; } } -?> \ No newline at end of file +?> diff --git a/livesupport/modules/storageServer/var/install/install.php b/livesupport/modules/storageServer/var/install/install.php index 9bd982c36..b476690e1 100644 --- a/livesupport/modules/storageServer/var/install/install.php +++ b/livesupport/modules/storageServer/var/install/install.php @@ -23,7 +23,7 @@ Author : $Author: tomas $ - Version : $Revision: 1.7 $ + Version : $Revision: 1.8 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/install/install.php,v $ ------------------------------------------------------------------------------*/ @@ -96,6 +96,14 @@ echo "# Install Transport submodule\n"; require_once "../Transport.php"; $tr =& new Transport(&$dbc, $config); $r = $tr->install(); +if(PEAR::isError($r)){ echo $r->getUserInfo()."\n"; exit; } +echo "\n"; + +echo "# Install Prefs submodule\n"; +require_once "../Prefs.php"; +$pr =& new Prefs(&$gb); +$r = $pr->install(); +if(PEAR::isError($r)){ echo $r->getUserInfo()."\n"; exit; } echo "\n"; $dbc->disconnect(); diff --git a/livesupport/modules/storageServer/var/install/uninstall.php b/livesupport/modules/storageServer/var/install/uninstall.php index 11e1207e2..0609a9631 100644 --- a/livesupport/modules/storageServer/var/install/uninstall.php +++ b/livesupport/modules/storageServer/var/install/uninstall.php @@ -23,7 +23,7 @@ Author : $Author: tomas $ - Version : $Revision: 1.4 $ + Version : $Revision: 1.5 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/install/uninstall.php,v $ ------------------------------------------------------------------------------*/ @@ -63,6 +63,15 @@ echo "# Uninstall Transport submodule ...\n"; require_once "../Transport.php"; $tr =& new Transport(&$dbc, $config); $r = $tr->uninstall(); +if(PEAR::isError($r)){ echo $r->getUserInfo()."\n"; exit; } +echo "\n"; + +echo "# Uninstall Prefs submodule\n"; +require_once "../Prefs.php"; +$pr =& new Prefs(&$gb); +$r = $pr->uninstall(); +if(PEAR::isError($r)){ echo $r->getUserInfo()."\n"; exit; } +echo "\n"; $dbc->disconnect(); ?> diff --git a/livesupport/modules/storageServer/var/xmlrpc/XR_LocStor.php b/livesupport/modules/storageServer/var/xmlrpc/XR_LocStor.php index ef66b3579..6fc8727d0 100644 --- a/livesupport/modules/storageServer/var/xmlrpc/XR_LocStor.php +++ b/livesupport/modules/storageServer/var/xmlrpc/XR_LocStor.php @@ -23,7 +23,7 @@ Author : $Author: tomas $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/XR_LocStor.php,v $ ------------------------------------------------------------------------------*/ @@ -1218,6 +1218,105 @@ class XR_LocStor extends LocStor{ return new XML_RPC_Response(XML_RPC_encode(array('gunids'=>$res))); } + /** + * Load user preference value + * + * The XML-RPC name of this method is "locstor.loadPref". + * + * The input parameters are an XML-RPC struct with the following + * fields: + *