From f4929ce3db8fb8f130261f1da8283bfc4d947f06 Mon Sep 17 00:00:00 2001 From: tomash Date: Thu, 29 Sep 2005 00:24:32 +0000 Subject: [PATCH] Extra parameters added to resetStorage method - flag for sampleData inserting and deleting only files in storage. Default values have been chosen to preserve previous calls. --- .../modules/storageServer/bin/resetStorage.sh | 2 +- .../modules/storageServer/var/BasicStor.php | 33 ++++++++++++------- .../storageServer/var/xmlrpc/XR_LocStor.php | 15 +++++++-- .../storageServer/var/xmlrpc/xr_cli_test.php | 12 ++++++- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/livesupport/modules/storageServer/bin/resetStorage.sh b/livesupport/modules/storageServer/bin/resetStorage.sh index c7b6dc6bf..a1a6b15de 100755 --- a/livesupport/modules/storageServer/bin/resetStorage.sh +++ b/livesupport/modules/storageServer/bin/resetStorage.sh @@ -39,7 +39,7 @@ echo "# storageServer root URL: $WWW_ROOT" cd $reldir/var/xmlrpc php -q xr_cli_test.php -s $WWW_ROOT/xmlrpc/xrLocStor.php \ - resetStorage || exit $? + resetStorage 1 0 || exit $? echo "# resetStorage: OK" exit 0 diff --git a/livesupport/modules/storageServer/var/BasicStor.php b/livesupport/modules/storageServer/var/BasicStor.php index b5cff5b7d..0a8ea097c 100644 --- a/livesupport/modules/storageServer/var/BasicStor.php +++ b/livesupport/modules/storageServer/var/BasicStor.php @@ -1278,23 +1278,26 @@ class BasicStor extends Alib{ /** * Reset storageServer for debugging. * - * @param loadSampleData boolean - allows deny sample data loading + * @param loadSampleData boolean - flag for allow sample data loading + * @param filesOnly boolean - flag for operate only on files in storage */ - function resetStorage($loadSampleData=TRUE) + function resetStorage($loadSampleData=TRUE, $filesOnly=FALSE) { - $this->deleteData(); + if($filesOnly) $this->deleteFiles(); + else $this->deleteData(); if(!$this->config['isArchive']){ $tr =& new Transport($this->dbc, $this, $this->config); $tr->resetData(); } + $res = array( + 'audioclips'=>array(), 'playlists'=>array(), 'webstreams'=>array() + ); + if(!$loadSampleData) return $res; $rootHD = $this->getObjId('root', $this->storId); $samples = dirname(__FILE__)."/tests/sampleData.php"; if(file_exists($samples)){ include $samples; }else $sampleData = array(); - $res = array( - 'audioclips'=>array(), 'playlists'=>array(), 'webstreams'=>array() - ); foreach($sampleData as $k=>$it){ $type = $it['type']; $xml = $it['xml']; @@ -1353,6 +1356,18 @@ class BasicStor extends Alib{ echo"
\n"; print_r($va); #exit;
     }
 
+    /**
+     *  deleteFiles
+     *
+     *  @return void
+     */
+    function deleteFiles()
+    {
+        $ids = $this->dbc->getAll("SELECT id FROM {$this->filesTable}");
+        if(is_array($ids)) foreach($ids as $i=>$item){
+            $this->bsDeleteFile($item['id'], TRUE);
+        }
+    }
     /**
      *  deleteData
      *
@@ -1360,11 +1375,7 @@ class BasicStor extends Alib{
      */
     function deleteData()
     {
-//        $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->bsDeleteFile($item['id'], TRUE);
-        }
+        $this->deleteFiles();
         parent::deleteData();
         $this->initData();
     }
diff --git a/livesupport/modules/storageServer/var/xmlrpc/XR_LocStor.php b/livesupport/modules/storageServer/var/xmlrpc/XR_LocStor.php
index 1368f4be6..ddbe56413 100644
--- a/livesupport/modules/storageServer/var/xmlrpc/XR_LocStor.php
+++ b/livesupport/modules/storageServer/var/xmlrpc/XR_LocStor.php
@@ -1870,7 +1870,15 @@ class XR_LocStor extends LocStor{
      *
      *  The XML-RPC name of this method is "locstor.resetStorage".
      *
-     *  The input parameters are an empty XML-RPC struct.
+     *  The input parameters are an empty XML-RPC struct,
+     *  or struct with the following optional fields:
+     *  
      *
      *  On success, returns a XML-RPC struct with following
      *  fields:
@@ -1899,7 +1907,10 @@ class XR_LocStor extends LocStor{
     {
         list($ok, $r) = $this->_xr_getPars($input);
         if(!$ok) return $r;
-        $res = $this->resetStorage();
+        $res = $this->resetStorage(
+            isset($r['loadSampleData']) ? $r['loadSampleData'] : TRUE,
+            isset($r['filesOnly']) ? $r['filesOnly'] : FALSE
+        );
         if(PEAR::isError($res)){
             return new XML_RPC_Response(0, 805,
                 "xr_getAudioClip: ".$res->getMessage()." ".$res->getUserInfo()
diff --git a/livesupport/modules/storageServer/var/xmlrpc/xr_cli_test.php b/livesupport/modules/storageServer/var/xmlrpc/xr_cli_test.php
index 2c5f3fb05..99d969bf1 100644
--- a/livesupport/modules/storageServer/var/xmlrpc/xr_cli_test.php
+++ b/livesupport/modules/storageServer/var/xmlrpc/xr_cli_test.php
@@ -51,6 +51,7 @@ $client = new XML_RPC_Client($url['path'], $url['host']);
 $method = array_shift($pars);
 
 if($verbose){
+    $client->debug = 1;
     echo "serverPath: $serverPath\n";
     echo "host: {$url['host']}, path: {$url['path']}\n";
     echo "method: $method\n";
@@ -105,7 +106,9 @@ $infos = array(
         'p'=>array('sessid', 'gunid', 'metadata'), 'r'=>'status'),
     "searchMetadata"    => array('m'=>"locstor.searchMetadata", 'p'=>NULL),
     "browseCategory"    => array('m'=>"locstor.browseCategory", 'p'=>NULL),
-    "resetStorage"  => array('m'=>"locstor.resetStorage", 'p'=>array()),
+    "resetStorage"  => array('m'=>"locstor.resetStorage",
+        'p'=>array()),
+#        'p'=>array('loadSampleData', 'filesOnly')),
     "storeWebstream"    => array('m'=>"locstor.storeWebstream",
         'p'=>array('sessid', 'gunid', 'metadata', 'fname', 'url'),
         'r'=>array('gunid')
@@ -184,6 +187,12 @@ case"browseCategory":
         ),
     );
     break;
+case"resetStorage":
+    $parr = array(
+        'loadSampleData'=>(boolean)$pars[0],
+        'filesOnly'=>(boolean)$pars[1],
+    );
+    break;
 default:
     $pinfo = $infos[$method]['p'];
     if(is_null($pinfo)){
@@ -215,6 +224,7 @@ if($verbose){
 $res = $client->send($msg);
 if($res->faultCode() > 0) {
     echo "xr_cli_test.php: ".$res->faultString()." ".$res->faultCode()."\n";
+#    echo var_export($res);
     exit(1);
 }