Catch VFS thrown exceptions
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 9 Mar 2010 23:17:04 +0000 (16:17 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 10 Mar 2010 01:33:37 +0000 (18:33 -0700)
29 files changed:
agora/lib/Agora.php
ansel/faces/img.php
ansel/lib/Ansel.php
ansel/lib/Api.php
ansel/lib/Application.php
ansel/lib/Faces/Base.php
ansel/lib/Image.php
folks/lib/Driver.php
framework/Scheduler/lib/Horde/Scheduler.php
framework/VFS_ISOWriter/tests/inputstrategy.phpt
framework/VFS_ISOWriter/tests/isowriter.phpt
framework/VFS_ISOWriter/tests/outputstrategy.phpt
gollem/lib/Gollem.php
horde/admin/setup/index.php
horde/services/images/view.php
hylax/lib/Storage.php
imp/attachment.php
imp/lib/Compose.php
imp/lib/LoginTasks/SystemTask/GarbageCollection.php
imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php
ingo/lib/Driver/Vfs.php
news/lib/News.php
turba/lib/Object.php
turba/view.php
whups/lib/Driver/sql.php
whups/lib/Ticket.php
whups/lib/Whups.php
whups/view.php
wicked/lib/Driver.php

index d3624f1..6c42b15 100644 (file)
@@ -226,7 +226,11 @@ class Agora {
             return PEAR::raiseError(_("The VFS backend needs to be configured to enable attachment uploads."));
         }
 
-        return VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs'));
+        try {
+            return VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs'));
+        } catch (VFS_Exception $e) {
+            return PEAR::raiseError($e);
+        }
     }
 
     function getMenu($returnType = 'object')
index 625ab92..1cb4df0 100644 (file)
@@ -29,11 +29,12 @@ if ($conf['vfs']['src'] == 'sendfile') {
     }
 
     // We definitely have an image for the face.
-    $filename = $ansel_vfs->readFile(
-        Ansel_Faces::getVFSPath($face['image_id']) . 'faces',
-        $face_id . Ansel_Faces::getExtension());
-    if (is_a($filename, 'PEAR_ERROR')) {
-        Horde::logMessage($filename, __FILE__, __LINE__, PEAR_LOG_ERR);
+    try {
+        $filename = $ansel_vfs->readFile(
+            Ansel_Faces::getVFSPath($face['image_id']) . 'faces',
+            $face_id . Ansel_Faces::getExtension());
+    } catch (VFS_Exception $e) {
+        Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
         exit;
     }
     header('Content-type: image/' . $GLOBALS['conf']['image']['type']);
index 4741560..949d061 100644 (file)
@@ -63,24 +63,12 @@ class Ansel
     /**
      * Create and initialize the VFS object
      *
-     * @return VFS object or fatals on error.
+     * @return  VFS object.
      */
-    static public function &getVFS()
+    static public function getVFS()
     {
         $v_params = Horde::getVFSConfig('images');
-        if (is_a($v_params, 'PEAR_Error')) {
-            Horde::fatal(_("You must configure a VFS backend to use Ansel."),
-                         __FILE__, __LINE__);
-        }
-        if ($v_params['type'] != 'none') {
-            $vfs = VFS::singleton($v_params['type'], $v_params['params']);
-        }
-        if (empty($vfs) || is_a($vfs, 'PEAR_ERROR')) {
-            Horde::fatal(_("You must configure a VFS backend to use Ansel."),
-                         __FILE__, __LINE__);
-        }
-
-        return $vfs;
+        return VFS::singleton($v_params['type'], $v_params['params']);
     }
 
     /**
index 2af2a7a..73629bc 100644 (file)
@@ -650,8 +650,12 @@ class Ansel_Api extends Horde_Registry_Api
                 return PEAR::RaiseError(sprintf(_("Access denied downloading photos from \"%s\"."), $gallery->get('name')));
             }
 
-            $data = $GLOBALS['ansel_vfs']->read($image->getVFSPath('full'),
-                $image->getVFSName('full'));
+            try {
+                $data = $GLOBALS['ansel_vfs']->read($image->getVFSPath('full'),
+                    $image->getVFSName('full'));
+            } catch (VFS_Exception $e) {
+                return PEAR::raiseError($data->getMessage());
+            }
         } else {
             // Load View
             $result = $image->load($view, $style);
index f470d63..35b25fd 100644 (file)
@@ -60,7 +60,7 @@ class Ansel_Application extends Horde_Registry_Application
         if (!$GLOBALS['conf']['image']['driver']) {
             throw new Horde_Exception('You must configure a Horde_Image driver to use Ansel');
         }
-        
+
         // Create a cache object if we need it.
         if ($GLOBALS['conf']['ansel_cache']['usecache']) {
             $GLOBALS['cache'] = $GLOBALS['injector']->getInstance('Horde_Cache');
index 648b0a2..bc6bf90 100644 (file)
@@ -376,9 +376,10 @@ class Ansel_Faces_Base
         $vfspath = Ansel_Faces::getVFSPath($face['image_id']) . 'faces';
         $vfsname = $face_id . Ansel_Faces::getExtension();
         $img = Ansel::getImageObject();
-        $data = $GLOBALS['ansel_vfs']->read($vfspath, $vfsname);
-        if ($data instanceof PEAR_Error) {
-            throw new Horde_Exception_Prior($data);
+        try {
+            $data = $GLOBALS['ansel_vfs']->read($vfspath, $vfsname);
+        } catch (VFS_Exception $e) {
+            throw new Horde_Exception_Prior($e);
         }
         $img->loadString($data);
 
@@ -611,10 +612,11 @@ class Ansel_Faces_Base
         $ext = Ansel_Faces::getExtension();
         $path = Ansel_Faces::getVFSPath($image->id);
         $image->_image->resize(50, 50, false);
-        $result = $GLOBALS['ansel_vfs']->writeData($path . 'faces', $face_id . $ext,
-                                                   $image->_image->raw(), true);
-        if (is_a($result, 'PEAR_Error')) {
-            throw new Horde_Exception_Prior($result);
+        try {
+            $GLOBALS['ansel_vfs']->writeData($path . 'faces', $face_id . $ext,
+                                             $image->_image->raw(), true);
+        } catch (VFS_Exception $e) {
+            throw new Horde_Exception_Prior($e);
         }
 
         return $face_id;
index 39e201a..0775350 100644 (file)
@@ -306,10 +306,11 @@ class Ansel_Image Implements Iterator
         $vfspath = $this->getVFSPath($view, $style);
 
         /* Read in the requested view. */
-        $data = $GLOBALS['ansel_vfs']->read($vfspath, $this->getVFSName($view));
-        if ($data instanceof PEAR_Error) {
-            Horde::logMessage($date, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Ansel_Exception($data);
+        try {
+            $data = $GLOBALS['ansel_vfs']->read($vfspath, $this->getVFSName($view));
+        } catch (VFS_Exception $e) {
+            Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
+            throw new Ansel_Exception($e);
         }
 
         /* We've definitely successfully loaded the image now. */
@@ -382,10 +383,11 @@ class Ansel_Image Implements Iterator
         if ($GLOBALS['ansel_vfs']->exists($vfspath, $this->getVFSName($view))) {
             return true;
         }
-        $data = $GLOBALS['ansel_vfs']->read($this->getVFSPath('full'), $this->getVFSName('full'));
-        if ($data instanceof PEAR_Error) {
-            Horde::logMessage($data, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Ansel_Exception($data);
+        try {
+            $data = $GLOBALS['ansel_vfs']->read($this->getVFSPath('full'), $this->getVFSName('full'));
+        } catch (VFS_Exception $e) {
+            Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
+            throw new Ansel_Exception($e);
         }
 
         $vHash = $this->getViewHash($view, $style);
@@ -449,12 +451,12 @@ class Ansel_Image Implements Iterator
     {
         $this->_dirty = false;
 
-        $results = $GLOBALS['ansel_vfs']->writeData($this->getVFSPath('full'),
-                                                $this->getVFSName('full'),
-                                                $this->_data['full'], true);
-
-        if ($results instanceof PEAR_Error) {
-            throw new Ansel_Exception($results);
+        try {
+            $GLOBALS['ansel_vfs']->writeData($this->getVFSPath('full'),
+                                             $this->getVFSName('full'),
+                                             $this->_data['full'], true);
+        } catch (VFS_Exception $e) {
+            throw new Ansel_Exception($e);
         }
 
         return true;
@@ -483,12 +485,12 @@ class Ansel_Image Implements Iterator
             $this->deleteCache();
         }
 
-        $results = $GLOBALS['ansel_vfs']->writeData($this->getVFSPath($view),
-                                                $this->getVFSName($view),
-                                                $data, true);
-
-        if ($results instanceof PEAR_Error) {
-            throw new Ansel_Exception($results);
+        try {
+            $GLOBALS['ansel_vfs']->writeData($this->getVFSPath($view),
+                                             $this->getVFSName($view),
+                                             $data, true);
+        } catch (VFS_Exception $e) {
+            throw new Ansel_Exception($e);
         }
     }
 
@@ -628,10 +630,11 @@ class Ansel_Image Implements Iterator
         $this->_exif = array();
 
         /* Get the data */
-        $imageFile = $GLOBALS['ansel_vfs']->readFile($this->getVFSPath('full'),
-                                                     $this->getVFSName('full'));
-        if ($imageFile instanceof PEAR_Error) {
-            throw new Ansel_Exception($imageFile);
+        try {
+            $imageFile = $GLOBALS['ansel_vfs']->readFile($this->getVFSPath('full'),
+                                                         $this->getVFSName('full'));
+        } catch (VFS_Exception $e) {
+            throw new Ansel_Exception($e);
         }
         $exif = Horde_Image_Exif::factory($GLOBALS['conf']['exif']['driver'], !empty($GLOBALS['conf']['exif']['params']) ? $GLOBALS['conf']['exif']['params'] : array());
 
@@ -845,11 +848,11 @@ class Ansel_Image Implements Iterator
                 throw Horde_Exception_PermissionDenied(sprintf(_("Access denied downloading photos from \"%s\"."), $gallery->get('name')));
             }
 
-            $data = $GLOBALS['ansel_vfs']->read($this->getVFSPath('full'),
-                                                $this->getVFSName('full'));
-
-            if ($data instanceof PEAR_Error) {
-                throw new Ansel_Exception($data);
+            try {
+                $data = $GLOBALS['ansel_vfs']->read($this->getVFSPath('full'),
+                                                    $this->getVFSName('full'));
+            } catch (VFS_Exception $e) {
+                throw new Ansel_Exception($e);
             }
             echo $data;
         } else {
index 6abcb22..dd03658 100644 (file)
@@ -68,8 +68,11 @@ class Folks_Driver {
     protected function _loadVFS()
     {
         $v_params = Horde::getVFSConfig('images');
-
-        return VFS::singleton($v_params['type'], $v_params['params']);
+        try {
+            return VFS::singleton($v_params['type'], $v_params['params']);
+        } catch (VFS_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
+        }
     }
 
     /**
@@ -82,6 +85,7 @@ class Folks_Driver {
     {
         global $conf;
 
+        try {
         $vfs = $this->_loadVFS();
         if ($vfs instanceof PEAR_Error) {
             return $vfs;
@@ -112,9 +116,10 @@ class Folks_Driver {
                         min($conf['images']['screen_height'], $dimensions['height']));
 
         // Store big image
-        $result = $vfs->writeData($vfspath . '/big/', $vfs_name, $img->raw(), true);
-        if ($result instanceof PEAR_Error) {
-            return $result;
+        try {
+            $vfs->writeData($vfspath . '/big/', $vfs_name, $img->raw(), true);
+        } catch (VFS_Exception $e) {
+            return PEAR::raiseError($result->getMessage());
         }
 
         // Resize thumbnail
@@ -142,14 +147,11 @@ class Folks_Driver {
         $vfspath = Folks::VFS_PATH . '/' . substr(str_pad($p, 2, 0, STR_PAD_LEFT), -2) . '/';
         $vfs_name = $p . '.' . $GLOBALS['conf']['images']['image_type'];
 
-        $result = $vfs->deleteFile($vfspath . '/big/', $vfs_name);
-        if ($result instanceof PEAR_Error) {
-            return $result;
-        }
-
-        $result = $vfs->deleteFile($vfspath . '/small/', $vfs_name);
-        if ($result instanceof PEAR_Error) {
-            return $result;
+        try {
+            $vfs->deleteFile($vfspath . '/big/', $vfs_name);
+            $vfs->deleteFile($vfspath . '/small/', $vfs_name);
+        } catch (VFS_Exception $e) {
+            return $e->getMessage();
         }
 
         // Delete cache
index 93a49bb..793c74b 100644 (file)
@@ -1,8 +1,4 @@
 <?php
-
-require_once 'Horde.php';
-require_once 'VFS.php';
-
 /**
  * Horde_Scheduler
  *
@@ -63,20 +59,15 @@ class Horde_Scheduler {
      */
     function serialize($id = '')
     {
-        $vfs = &VFS::singleton($GLOBALS['conf']['vfs']['type'],
-                               Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
-        if (is_a($vfs, 'PEAR_Error')) {
-            Horde::logMessage($vfs, __FILE__, __LINE__, PEAR_LOG_ERR);
+        try {
+            $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'],
+                                  Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
+            $vfs->writeData('.horde/scheduler', Horde_String::lower(get_class($this)) . $id, serialize($this), true);
+            return true;
+        } catch (VFS_Exception $e) {
+            Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
             return false;
         }
-
-        $result = $vfs->writeData('.horde/scheduler', Horde_String::lower(get_class($this)) . $id, serialize($this), true);
-        if (is_a($result, 'PEAR_Error')) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return false;
-        }
-
-        return true;
     }
 
     /**
@@ -98,24 +89,19 @@ class Horde_Scheduler {
         $class = strtolower($class);
         $scheduler = new $class;
 
-        $vfs = &VFS::singleton($GLOBALS['conf']['vfs']['type'],
-                               Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
-        if (is_a($vfs, 'PEAR_Error')) {
-            Horde::logMessage($vfs, __FILE__, __LINE__, PEAR_LOG_ERR);
-        } else {
+        try {
+            $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'],
+                              Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
             $data = $vfs->read('.horde/scheduler', $class . $id);
-            if (is_a($data, 'PEAR_Error')) {
-                Horde::logMessage($data, __FILE__, __LINE__, PEAR_LOG_INFO);
-            } else {
-                $scheduler = @unserialize($data);
-                if (!$scheduler) {
-                    $scheduler = new $class;
-                }
+            if ($tmp = @unserialize($data)) {
+                $scheduler = $tmp;
             }
+        } catch (VFS_Exception $e) {
+            Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
         }
 
         if ($autosave) {
-            register_shutdown_function(array(&$scheduler, 'serialize'));
+            register_shutdown_function(array($scheduler, 'serialize'));
         }
 
         return $scheduler;
index 81aa313..da016c8 100644 (file)
@@ -23,7 +23,7 @@ function testDirectInputStrategy()
 {
     echo "Testing direct input strategy... ";
 
-    $vfs = &VFS::factory('file', array('vfsroot' => '/tmp'));
+    $vfs = VFS::factory('file', array('vfsroot' => '/tmp'));
     testInputStrategy($vfs, 'vfs_isowriter_realinputstrategy_direct');
 }
 
@@ -51,9 +51,10 @@ function testInputStrategy(&$vfs, $expectClass)
             $file = $name;
         }
 
-        $res = $vfs->writeData('root/' . $dir, $file, $data, true);
-        if (is_a($res, 'PEAR_Error')) {
-            printf("ERROR(1): %s: %s\n", $name, $res->getMessage());
+        try {
+            $vfs->writeData('root/' . $dir, $file, $data, true);
+        } catch (VFS_Exception $e) {
+            printf("ERROR(1): %s: %s\n", $name, $e->getMessage());
             return;
         }
     }
index 26b9e2a..4e5658f 100644 (file)
@@ -9,9 +9,10 @@ require_once dirname(__FILE__) . '/../ISOWriter.php';
 echo "Load... ok\n";
 
 echo "Creating VFS... ";
-$vfs = &VFS::factory('file', array('vfsroot' => '/tmp'));
-if (is_a($vfs, 'PEAR_Error')) {
-    printf("ERROR(1): %s\n", $vfs->getMessage);
+try {
+    $vfs = VFS::factory('file', array('vfsroot' => '/tmp'));
+} catch (VFS_Exception $e) {
+    printf("ERROR(1): %s\n", $e->getMessage);
     exit;
 }
 echo "ok\n";
@@ -25,9 +26,10 @@ foreach ($FILES as $fname => $data) {
     preg_match('!^(.*)/([^/]*)$!', 'root/' . $fname, $matches);
     $path = $matches[1];
     $file = $matches[2];
-    $res = $vfs->writeData($path, $file, $data, true);
-    if (is_a($res, 'PEAR_Error')) {
-        printf("ERROR(1): %s\n", $res->getMessage());
+    try {
+        $vfs->writeData($path, $file, $data, true);
+    } catch (VFS_Exception $e) {
+        printf("ERROR(1): %s\n", $e->getMessage());
         exit;
     }
 }
index b7e948f..352d560 100644 (file)
@@ -22,25 +22,24 @@ function testDirectOutputStrategy()
 {
     echo "Testing direct output strategy... ";
 
-    $vfs = &VFS::factory('file', array('vfsroot' => '/tmp'));
-    testOutputStrategy($vfs, 'vfs_isowriter_realoutputstrategy_direct');
+    try {
+        $vfs = VFS::factory('file', array('vfsroot' => '/tmp'));
+        testOutputStrategy($vfs, 'vfs_isowriter_realoutputstrategy_direct');
+    } catch (VFS_Exception $e) {
+        echo "ERROR(1): ", $e->getMessage(), "\n";
+    }
 }
 
 function testCopyOutputStrategy()
 {
     echo "Testing copy output strategy... ";
 
-    $vfs = &new VFS_notfile(array('vfsroot' => '/tmp'));
+    $vfs = new VFS_notfile(array('vfsroot' => '/tmp'));
     testOutputStrategy($vfs, 'vfs_isowriter_realoutputstrategy_copy');
 }
 
 function testOutputStrategy(&$vfs, $expectClass)
 {
-    if (is_a($vfs, 'PEAR_Error')) {
-        echo "ERROR(1): ", $vfs->getMessage(), "\n";
-        return;
-    }
-
     $outputStrategy = &VFS_ISOWriter_RealOutputStrategy::factory($vfs, 'foo');
     if (is_a($outputStrategy, 'PEAR_Error')) {
         echo "ERROR(2): ", $outputStrategy->getMessage(), "\n";
@@ -74,9 +73,10 @@ function testOutputStrategy(&$vfs, $expectClass)
         return;
     }
 
-    $res = $vfs->read('/', 'foo');
-    if (is_a($res, 'PEAR_Error')) {
-        echo "ERROR(7): ", $res->getMessage(), "\n";
+    try {
+        $res = $vfs->read('/', 'foo');
+    } catch (VFS_Exception $e) {
+        echo "ERROR(7): ", $e->getMessage(), "\n";
         return;
     }
 
index d77c503..906af28 100644 (file)
@@ -207,6 +207,7 @@ class Gollem
      * @param string $dir  The directory name.
      *
      * @return array  The sorted list of files.
+     * @throws VFS_Exception
      */
     static public function listFolder($dir)
     {
@@ -228,15 +229,13 @@ class Gollem
         }
 
         $files = $GLOBALS['gollem_vfs']->listFolder($dir, isset($GLOBALS['gollem_be']['filter']) ? $GLOBALS['gollem_be']['filter'] : null, $GLOBALS['prefs']->getValue('show_dotfiles'));
-        if (!is_a($files, 'PEAR_Error')) {
-            $sortcols = array(
-                self::SORT_TYPE => 'sortType',
-                self::SORT_NAME => 'sortName',
-                self::SORT_DATE => 'sortDate',
-                self::SORT_SIZE => 'sortSize',
-            );
-            usort($files, array('Gollem', $sortcols[$GLOBALS['prefs']->getValue('sortby')]));
-        }
+        $sortcols = array(
+            self::SORT_TYPE => 'sortType',
+            self::SORT_NAME => 'sortName',
+            self::SORT_DATE => 'sortDate',
+            self::SORT_SIZE => 'sortSize',
+        );
+        usort($files, array('Gollem', $sortcols[$GLOBALS['prefs']->getValue('sortby')]));
 
         if (isset($cache)) {
             $cache->set($key, Horde_Serialize::serialize($files, Horde_Serialize::BASIC), $conf['foldercache']['lifetime']);
@@ -332,6 +331,7 @@ class Gollem
      * @param string $name  The folder to create.
      *
      * @return mixed  True on success or a PEAR_Error object on failure.
+     * @throws VFS_Exception
      */
     static public function createFolder($dir, $name)
     {
@@ -346,15 +346,8 @@ class Gollem
         $dir = substr($totalpath, 0, $pos);
         $name = substr($totalpath, $pos + 1);
 
-        $res = $GLOBALS['gollem_vfs']->autocreatePath($dir);
-        if (is_a($res, 'PEAR_Error')) {
-            return $res;
-        }
-
-        $res = $GLOBALS['gollem_vfs']->createFolder($dir, $name);
-        if (is_a($res, 'PEAR_Error')) {
-            return $res;
-        }
+        $GLOBALS['gollem_vfs']->autocreatePath($dir);
+        $GLOBALS['gollem_vfs']->createFolder($dir, $name);
 
         if (!empty($GLOBALS['gollem_be']['params']['permissions'])) {
             $GLOBALS['gollem_vfs']->changePermissions($dir, $name, $GLOBALS['gollem_be']['params']['permissions']);
@@ -371,11 +364,11 @@ class Gollem
      * @param string $newDir  New directory name.
      * @param string $old     New file name.
      *
-     * @return mixed  True on success or a PEAR_Error object on failure.
+     * @throws VFS_Exception
      */
     static public function renameItem($oldDir, $old, $newDir, $new)
     {
-        return $GLOBALS['gollem_vfs']->rename($oldDir, $old, $newDir, $new);
+        $GLOBALS['gollem_vfs']->rename($oldDir, $old, $newDir, $new);
     }
 
     /**
@@ -384,7 +377,7 @@ class Gollem
      * @param string $dir   The subdirectory name.
      * @param string $name  The folder name to delete.
      *
-     * @return mixed  True on success or a PEAR_Error object on failure.
+     * @throws VFS_Exception
      */
     static public function deleteFolder($dir, $name)
     {
@@ -392,7 +385,7 @@ class Gollem
             return PEAR::raiseError(sprintf(_("Access denied to folder \"%s\"."), $dir));
         }
 
-        return ($GLOBALS['prefs']->getValue('recursive_deletes') != 'disabled')
+        ($GLOBALS['prefs']->getValue('recursive_deletes') != 'disabled')
             ? $GLOBALS['gollem_vfs']->deleteFolder($dir, $name, true)
             : $GLOBALS['gollem_vfs']->deleteFolder($dir, $name, false);
     }
@@ -403,14 +396,14 @@ class Gollem
      * @param string $dir   The directory name.
      * @param string $name  The filename to delete.
      *
-     * @return mixed  True on success or a PEAR_Error object on failure.
+     * @throws VFS_Exception
      */
     static public function deleteFile($dir, $name)
     {
         if (!Gollem::verifyDir($dir)) {
             return PEAR::raiseError(sprintf(_("Access denied to folder \"%s\"."), $dir));
         }
-        return $GLOBALS['gollem_vfs']->deleteFile($dir, $name);
+        $GLOBALS['gollem_vfs']->deleteFile($dir, $name);
     }
 
     /**
@@ -420,14 +413,14 @@ class Gollem
      * @param string $name        The filename to change permissions on.
      * @param string $permission  The permission mode to set.
      *
-     * @return mixed  True on success or a PEAR_Error object on failure.
+     * @throws VFS_Exception
      */
     static public function changePermissions($dir, $name, $permission)
     {
         if (!Gollem::verifyDir($dir)) {
             return PEAR::raiseError(sprintf(_("Access denied to folder \"%s\"."), $dir));
         }
-        return $GLOBALS['gollem_vfs']->changePermissions($dir, $name, $permission);
+        $GLOBALS['gollem_vfs']->changePermissions($dir, $name, $permission);
     }
 
     /**
@@ -437,20 +430,14 @@ class Gollem
      * @param string $name      The filename to create.
      * @param string $filename  The local file containing the file data.
      *
-     * @return mixed  True on success or a PEAR_Error object on failure.
+     * @thows VFS_Exception
      */
     static public function writeFile($dir, $name, $filename)
     {
-        $res = $GLOBALS['gollem_vfs']->write($dir, $name, $filename);
-        if (is_a($res, 'PEAR_Error')) {
-            return $res;
-        }
-
+        $GLOBALS['gollem_vfs']->write($dir, $name, $filename);
         if (!empty($GLOBALS['gollem_be']['params']['permissions'])) {
             $GLOBALS['gollem_vfs']->changePermissions($dir, $name, $GLOBALS['gollem_be']['params']['permissions']);
         }
-
-        return true;
     }
 
     /**
@@ -462,12 +449,12 @@ class Gollem
      * @param string $backend_t The backend to move the file to.
      * @param string $newdir    The directory to move the file to.
      *
-     * @return mixed  True on success or a PEAR_Error object on failure.
+     * @throws VFS_Exception
      */
     static public function moveFile($backend_f, $dir, $name, $backend_t,
                                     $newdir)
     {
-        return Gollem::_copyFile('move', $backend_f, $dir, $name, $backend_t, $newdir);
+        Gollem::_copyFile('move', $backend_f, $dir, $name, $backend_t, $newdir);
     }
 
     /**
@@ -479,16 +466,18 @@ class Gollem
      * @param string $backend_t The backend to copy the file to.
      * @param string $newdir    The directory to copy the file to.
      *
-     * @return mixed  True on success or a PEAR_Error object on failure.
+     * @throws VFS_Exception
      */
     static public function copyFile($backend_f, $dir, $name, $backend_t,
                                     $newdir)
     {
-        return Gollem::_copyFile('copy', $backend_f, $dir, $name, $backend_t, $newdir);
+        Gollem::_copyFile('copy', $backend_f, $dir, $name, $backend_t, $newdir);
     }
 
     /**
      * Private function that copies/moves files.
+     *
+     * @throws VFS_Exception
      */
     static protected function _copyFile($mode, $backend_f, $dir, $name,
                                         $backend_t, $newdir)
@@ -500,10 +489,7 @@ class Gollem
                 $ob = &$GLOBALS['gollem_vfs'];
             } else {
                 $ob = Gollem::getVFSOb($backend_f);
-                $valid = $ob->checkCredentials();
-                if (is_a($valid, 'PEAR_Error')) {
-                    return $valid;
-                }
+                $ob->checkCredentials();
             }
             return ($mode == 'copy') ? $ob->copy($dir, $name, $newdir) : $ob->move($dir, $name, $newdir);
         }
@@ -513,40 +499,26 @@ class Gollem
             $from_be = &$GLOBALS['gollem_vfs'];
         } else {
             $from_be = Gollem::getVFSOb($backend_f);
-            $valid = $from_be->checkCredentials();
-            if (is_a($valid, 'PEAR_Error')) {
-                return $valid;
-            }
+            $from_be->checkCredentials();
         }
 
         if ($backend_t == $_SESSION['gollem']['backend_key']) {
             $to_be = &$GLOBALS['gollem_vfs'];
         } else {
             $from_be = Gollem::getVFSOb($backend_t);
-            $valid = $to_be->checkCredentials();
-            if (is_a($valid, 'PEAR_Error')) {
-                return $valid;
-            }
+            $to_be->checkCredentials();
         }
 
         /* Read the source data. */
         $data = $from_be->read($dir, $name);
-        if (is_a($data, 'PEAR_Error')) {
-            return $data;
-        }
 
         /* Write the target data. */
-        $res = $to_be->writeData($newdir, $name, $data);
-        if (is_a($res, 'PEAR_Error')) {
-            return $res;
-        }
+        $to_be->writeData($newdir, $name, $data);
 
         /* If moving, delete the source data. */
         if ($mode == 'move') {
             $from_be->deleteFile($dir, $name);
         }
-
-        return true;
     }
 
     /**
@@ -829,9 +801,6 @@ class Gollem
 
         // Create VFS object
         $ob = VFS::singleton($be_config['driver'], $params);
-        if (is_a($ob, 'PEAR_Error')) {
-            return $ob;
-        }
 
         // Enable logging within VFS
         $logger = Horde::getLogger();
index f5c2d53..0947dc9 100644 (file)
@@ -21,9 +21,10 @@ function _uploadFTP($params)
     global $registry, $notification;
 
     $params['hostspec'] = 'localhost';
-    $vfs = VFS::singleton('ftp', $params);
-    if (is_a($vfs, 'PEAR_Error')) {
-        $notification->push(sprintf(_("Could not connect to server \"%s\" using FTP: %s"), $params['hostspec'], $vfs->getMessage()), 'horde.error');
+    try {
+        $vfs = VFS::singleton('ftp', $params);
+    } catch (VFS_Exception $e) {
+        $notification->push(sprintf(_("Could not connect to server \"%s\" using FTP: %s"), $params['hostspec'], $e->getMessage()), 'horde.error');
         return false;
     }
 
@@ -33,22 +34,21 @@ function _uploadFTP($params)
         $path = $registry->get('fileroot', $app) . '/config';
         /* Try to back up the current conf.php. */
         if ($vfs->exists($path, 'conf.php')) {
-            if (($result = $vfs->rename($path, 'conf.php', $path, '/conf.bak.php')) === true) {
+            try {
+                $vfs->rename($path, 'conf.php', $path, '/conf.bak.php');
                 $notification->push(_("Successfully saved backup configuration."), 'horde.success');
-            } elseif (is_a($result, 'PEAR_Error')) {
-                $notification->push(sprintf(_("Could not save a backup configuation: %s"), $result->getMessage()), 'horde.error');
-            } else {
-                $notification->push(_("Could not save a backup configuation."), 'horde.error');
+            } catch (VFS_Exception $e) {
+                $notification->push(sprintf(_("Could not save a backup configuation: %s"), $e->getMessage()), 'horde.error');
             }
         }
 
-        $write = $vfs->writeData($path, 'conf.php', $config);
-        if (is_a($write, 'PEAR_Error')) {
-            $no_errors = false;
-            $notification->push(sprintf(_("Could not write configuration for \"%s\": %s"), $app, $write->getMessage()), 'horde.error');
-        } else {
+        try {
+            $vfs->writeData($path, 'conf.php', $config);
             $notification->push(sprintf(_("Successfully wrote %s"), Horde_Util::realPath($path . '/conf.php')), 'horde.success');
             unset($_SESSION['_config'][$app]);
+        } catch (VFS_Exception $e) {
+            $no_errors = false;
+            $notification->push(sprintf(_("Could not write configuration for \"%s\": %s"), $app, $e->getMessage()), 'horde.error');
         }
     }
     $registry->clearCache();
index 011f061..b33302c 100644 (file)
@@ -32,11 +32,12 @@ case 'vfs':
     $pushed = $registry->pushApp($app_conf);
 
     /* Getting a file from Horde's VFS. */
-    $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type']));
     $path = Horde_Util::getFormData('p');
-    $file_data = $vfs->read($path, $file);
-    if (is_a($file_data, 'PEAR_Error')) {
-        Horde::logMessage(sprintf('Error displaying image [%s]: %s', $path . '/' . $file, $file_data->getMessage()), __FILE__, __LINE__, PEAR_LOG_ERR);
+    try {
+        $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type']));
+        $file_data = $vfs->read($path, $file);
+    } catch (VFS_Exception $e) {
+        Horde::logMessage(sprintf('Error displaying image [%s]: %s', $path . '/' . $file, $e->getMessage()), __FILE__, __LINE__, PEAR_LOG_ERR);
         exit;
     }
 
index f4db1e5..6cbfe80 100644 (file)
@@ -28,6 +28,7 @@ class Hylax_Storage {
      * Constructor
      *
      * @param array $params  Any parameters needed for this storage driver.
+     * @throws VFS_Exception
      */
     function Hylax_Storage($params)
     {
@@ -41,8 +42,7 @@ class Hylax_Storage {
         }
         $vfs_driver = $conf['vfs']['type'];
         $vfs_params = Horde::getDriverConfig('vfs', $vfs_driver);
-        require_once 'VFS.php';
-        $this->_vfs = &VFS::singleton($vfs_driver, $vfs_params);
+        $this->_vfs = VFS::singleton($vfs_driver, $vfs_params);
     }
 
     function saveFaxData($data, $type = '.ps')
@@ -56,10 +56,11 @@ class Hylax_Storage {
         /* Save data to VFS backend. */
         $path = Hylax::getVFSPath($fax_id);
         $file = $fax_id . $type;
-        $saved = $this->_vfs->writeData($path, $file, $data, true);
-        if (is_a($saved, 'PEAR_Error')) {
-            Horde::logMessage('Could not save fax file to VFS: ' . $saved->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
-            return $saved;
+        try {
+            $this->_vfs->writeData($path, $file, $data, true);
+        } catch (VFS_Exception $e) {
+            Horde::logMessage('Could not save fax file to VFS: ' . $e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
+            throw $e;
         }
         return $fax_id;
     }
@@ -111,11 +112,12 @@ class Hylax_Storage {
     {
         $path = Hylax::getVFSPath($fax_id);
         $file = $fax_id . '.ps';
-        $data = $this->_vfs->read($path, $file);
-        if (is_a($data, 'PEAR_Error')) {
-            Horde::logMessage(sprintf("%s '%s/%s'.", $data->getMessage(), $path, $file), __FILE__, __LINE__, PEAR_LOG_ERR);
+        try {
+            return $this->_vfs->read($path, $file);
+        } catch (VFS_Exception $e) {
+            Horde::logMessage(sprintf("%s '%s/%s'.", $e->getMessage(), $path, $file), __FILE__, __LINE__, PEAR_LOG_ERR);
+            throw $e;
         }
-        return $data;
     }
 
     function listFaxes($folder)
index 507182f..b823795 100644 (file)
@@ -33,9 +33,10 @@ if (is_null($mail_user) || is_null($time_stamp) || is_null($file_name)) {
 }
 
 // Initialize the VFS.
-$vfsroot = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type']));
-if ($vfsroot instanceof PEAR_Error) {
-    throw new IMP_Exception(sprintf(_("Could not create the VFS backend: %s"), $vfsroot->getMessage()));
+try {
+    $vfsroot = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type']));
+} catch (VFS_Exception $e) {
+    throw new IMP_Exception(sprintf(_("Could not create the VFS backend: %s"), $e->getMessage()));
 }
 
 // Check if the file exists.
@@ -51,22 +52,23 @@ if (!$vfsroot->exists($full_path, $file_name)) {
 if ($conf['compose']['link_attachments_notify']) {
     if ($vfsroot->exists($full_path, $file_name . '.notify')) {
         $delete_id = Horde_Util::getFormData('d');
-        $read_id = $vfsroot->read($full_path, $file_name . '.notify');
-        if ($read_id instanceof PEAR_Error) {
-            Horde::logMessage($read_id, __FILE__, __LINE__, PEAR_LOG_ERR);
-        } elseif ($delete_id == $read_id) {
-            $vfsroot->deleteFile($full_path, $file_name);
-            $vfsroot->deleteFile($full_path, $file_name . '.notify');
-            printf(_("Attachment %s deleted."), $file_name);
-            exit;
+        try {
+            $read_id = $vfsroot->read($full_path, $file_name . '.notify');
+            if ($delete_id == $read_id) {
+                $vfsroot->deleteFile($full_path, $file_name);
+                $vfsroot->deleteFile($full_path, $file_name . '.notify');
+                printf(_("Attachment %s deleted."), $file_name);
+                exit;
+            }
+        } catch (VFS_Exception $e) {
+            Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
         }
     } else {
         /* Create a random identifier for this file. */
         $id = uniqid(mt_rand());
-        $res = $vfsroot->writeData($full_path, $file_name . '.notify', $id, true);
-        if ($res instanceof PEAR_Error) {
-            Horde::logMessage($res, __FILE__, __LINE__, PEAR_LOG_ERR);
-        } else {
+        try {
+            $vfsroot->writeData($full_path, $file_name . '.notify', $id, true);
+
             /* Load $mail_user's preferences so that we can use their
              * locale information for the notification message. */
             $prefs = Horde_Prefs::singleton($conf['prefs']['driver'], 'horde', $mail_user);
@@ -103,14 +105,17 @@ if ($conf['compose']['link_attachments_notify']) {
 
                 $msg->send($mail_address, $msg_headers);
             }
+        } catch (VFS_Exception $e) {
+            Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
         }
     }
 }
 
 // Find the file's mime-type.
-$file_data = $vfsroot->read($full_path, $file_name);
-if ($file_data instanceof PEAR_Error) {
-    Horde::logMessage($file_data, __FILE__, __LINE__, PEAR_LOG_ERR);
+try {
+    $file_data = $vfsroot->read($full_path, $file_name);
+} catch (VFS_Exception $e) {
+    Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
     throw new IMP_Exception(_("The specified file cannot be read."));
 }
 $mime_type = Horde_Mime_Magic::analyzeData($file_data, isset($conf['mime']['magic_db']) ? $conf['mime']['magic_db'] : null);
index b6b61b3..fef73f7 100644 (file)
@@ -1782,7 +1782,7 @@ class IMP_Compose
         }
 
         /* Store the data. */
-        $result = $this->_storeAttachment($part, $attachment);
+        $this->_storeAttachment($part, $attachment);
 
         return $filename;
     }
@@ -1860,6 +1860,8 @@ class IMP_Compose
      *                                or, if $vfs_file is false, the
      *                                attachment data.
      * @param boolean $vfs_file       If using VFS, is $data a filename?
+     *
+     * @throws IMP_Compose_Exception
      */
     protected function _storeAttachment($part, $data, $vfs_file = true)
     {
@@ -1870,11 +1872,14 @@ class IMP_Compose
             $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type']));
             $cacheID = uniqid(mt_rand());
 
-            $result = $vfs_file
-                ? $vfs->write(self::VFS_ATTACH_PATH, $cacheID, $data, true)
-                : $vfs->writeData(self::VFS_ATTACH_PATH, $cacheID, $data, true);
-            if ($result instanceof PEAR_Error) {
-                return $result;
+            try {
+                if ($vfs_file) {
+                    $vfs->write(self::VFS_ATTACH_PATH, $cacheID, $data, true);
+                } else {
+                    $vfs->writeData(self::VFS_ATTACH_PATH, $cacheID, $data, true);
+                }
+            } catch (VFS_Exception $e) {
+                throw new IMP_Compose_Exception($e);
             }
 
             $this->_cache[] = array(
@@ -2314,15 +2319,17 @@ class IMP_Compose
 
         foreach ($this->getAttachments() as $att) {
             $trailer .= "\n" . $baseurl->copy()->add(array('u' => $auth, 't' => $ts, 'f' => $att->getName()));
-            if ($conf['compose']['use_vfs']) {
-                $res = $vfs->rename(self::VFS_ATTACH_PATH, $att->getInformation('temp_filename'), $fullpath, escapeshellcmd($att->getName()));
-            } else {
-                $data = file_get_contents($att->getInformation('temp_filename'));
-                $res = $vfs->writeData($fullpath, escapeshellcmd($att->getName()), $data, true);
-            }
-            if ($res instanceof PEAR_Error) {
-                Horde::logMessage($res, __FILE__, __LINE__, PEAR_LOG_ERR);
-                return IMP_Compose_Exception($res);
+
+            try {
+                if ($conf['compose']['use_vfs']) {
+                    $vfs->rename(self::VFS_ATTACH_PATH, $att->getInformation('temp_filename'), $fullpath, escapeshellcmd($att->getName()));
+                } else {
+                    $data = file_get_contents($att->getInformation('temp_filename'));
+                    $vfs->writeData($fullpath, escapeshellcmd($att->getName()), $data, true);
+                }
+            } catch (VFS_Exception $e) {
+                Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
+                return IMP_Compose_Exception($e);
             }
         }
 
@@ -2590,13 +2597,12 @@ class IMP_Compose
             return;
         }
 
-        $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
-        $result = $vfs->writeData(self::VFS_DRAFTS_PATH, hash('md5', Horde_Util::getFormData('user')), $body, true);
-        if ($result instanceof PEAR_Error) {
-            return;
-        }
+        try {
+            $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
+            $vfs->writeData(self::VFS_DRAFTS_PATH, hash('md5', Horde_Util::getFormData('user')), $body, true);
 
-        $GLOBALS['notification']->push(_("The message you were composing has been saved as a draft. The next time you login, you may resume composing your message."));
+            $GLOBALS['notification']->push(_("The message you were composing has been saved as a draft. The next time you login, you may resume composing your message."));
+        } catch (VFS_Exception $e) {}
     }
 
     /**
@@ -2611,11 +2617,12 @@ class IMP_Compose
         $filename = hash('md5', Horde_Auth::getAuth());
         $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
         if ($vfs->exists(self::VFS_DRAFTS_PATH, $filename)) {
-            $data = $vfs->read(self::VFS_DRAFTS_PATH, $filename);
-            if ($data instanceof PEAR_Error) {
+            try {
+                $data = $vfs->read(self::VFS_DRAFTS_PATH, $filename);
+                $vfs->deleteFile(self::VFS_DRAFTS_PATH, $filename);
+            } catch (VFS_Exception $e) {
                 return;
             }
-            $vfs->deleteFile(self::VFS_DRAFTS_PATH, $filename);
 
             try {
                 $this->_saveDraftServer($data);
index a146936..20e8fa1 100644 (file)
@@ -33,8 +33,10 @@ class IMP_LoginTasks_SystemTask_GarbageCollection extends Horde_LoginTasks_Syste
 
         /* Do garbage collection on compose VFS data. */
         if ($GLOBALS['conf']['compose']['use_vfs']) {
-            $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
-            VFS_GC::gc($vfs, IMP_Compose::VFS_ATTACH_PATH, 86400);
+            try {
+                $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
+                VFS_GC::gc($vfs, IMP_Compose::VFS_ATTACH_PATH, 86400);
+            } catch (VFS_Exception $e) {}
         }
 
         /* Purge non-existent search sorts. */
index e0dee3e..dbd4cda 100644 (file)
@@ -33,23 +33,32 @@ class IMP_LoginTasks_Task_DeleteAttachmentsMonthly extends Horde_LoginTasks_Task
          * purge. */
         $del_time = gmmktime(0, 0, 0, date('n') - $GLOBALS['prefs']->getValue('delete_attachments_monthly_keep'), 1, date('Y'));
 
-        $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
+        try {
+            $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
+        } catch (VFS_Exception $e) {
+            return false;
+        }
         $path = IMP_Compose::VFS_LINK_ATTACH_PATH . '/' . Horde_Auth::getAuth();
 
         /* Make sure cleaning is done recursively. */
-        $files = $vfs->listFolder($path, null, true, false, true);
-        if (($files instanceof PEAR_Error) || !is_array($files)) {
+        try {
+            $files = $vfs->listFolder($path, null, true, false, true);
+        } catch (VFS_Exception $e) {
             return false;
         }
 
+        $retval = false;
         foreach ($files as $dir) {
             $filetime = (isset($dir['date'])) ? $dir['date'] : intval(basename($dir['name']));
             if ($del_time > $filetime) {
-                $vfs->deleteFolder($path, $dir['name'], true);
+                try {
+                    $vfs->deleteFolder($path, $dir['name'], true);
+                    $retval = true;
+                } catch (VFS_Exception $e) {}
             }
         }
 
-        return true;
+        return $retval;
     }
 
     /**
index 83bc49d..7bd9f41 100644 (file)
@@ -46,17 +46,21 @@ class Ingo_Driver_Vfs extends Ingo_Driver
     {
         $this->_connect();
 
-        $result = empty($script)
-            ? $this->_vfs->deleteFile($this->_params['vfs_path'], $this->_params['filename'])
-            : $this->_vfs->writeData($this->_params['vfs_path'], $this->_params['filename'], $script, true);
-        if ($result instanceof PEAR_Error) {
-            throw new Ingo_Exception($result);
+        try {
+            if (empty($script)) {
+                $this->_vfs->deleteFile($this->_params['vfs_path'], $this->_params['filename']);
+            } else {
+                $this->_vfs->writeData($this->_params['vfs_path'], $this->_params['filename'], $script, true);
+            }
+        } catch (VFS_Exception $e) {
+            throw new Ingo_Exception($e);
         }
 
         if (isset($this->_params['file_perms']) && !empty($script)) {
-            $result = $this->_vfs->changePermissions($this->_params['vfs_path'], $this->_params['filename'], $this->_params['file_perms']);
-            if ($result instanceof PEAR_Error) {
-                throw new Ingo_Exception($result);
+            try {
+                $this->_vfs->changePermissions($this->_params['vfs_path'], $this->_params['filename'], $this->_params['file_perms']);
+            } catch (VFS_Exception $e) {
+                throw new Ingo_Exception($e);
             }
         }
 
@@ -66,17 +70,21 @@ class Ingo_Driver_Vfs extends Ingo_Driver
         if (($backend['script'] == 'procmail') &&
             isset($backend['params']['forward_file']) &&
             isset($backend['params']['forward_string'])) {
-            $result = empty($script)
-                ? $this->_vfs->deleteFile($this->_params['vfs_forward_path'], $backend['params']['forward_file'])
-                : $this->_vfs->writeData($this->_params['vfs_forward_path'], $backend['params']['forward_file'], $backend['params']['forward_string'], true);
-            if ($result instanceof PEAR_Error) {
-                throw new Ingo_Exception($result);
+            try {
+                if (empty($script)) {
+                    $this->_vfs->deleteFile($this->_params['vfs_forward_path'], $backend['params']['forward_file']);
+                } else {
+                    $this->_vfs->writeData($this->_params['vfs_forward_path'], $backend['params']['forward_file'], $backend['params']['forward_string'], true);
+                }
+            } catch (VFS_Exception $e) {
+                throw new Ingo_Exception($e);
             }
 
             if (isset($this->_params['file_perms']) && !empty($script)) {
-                $result = $this->_vfs->changePermissions($this->_params['vfs_forward_path'], $backend['params']['forward_file'], $this->_params['file_perms']);
-                if ($result instanceof PEAR_Error) {
-                    throw new Ingo_Exception($result);
+                try {
+                    $this->_vfs->changePermissions($this->_params['vfs_forward_path'], $backend['params']['forward_file'], $this->_params['file_perms']);
+                } catch (VFS_Exception $e) {
+                    throw new Ingo_Exception($e);
                 }
             }
         }
@@ -124,11 +132,12 @@ class Ingo_Driver_Vfs extends Ingo_Driver
             return true;
         }
 
-        $this->_vfs = VFS::singleton($this->_params['vfstype'], $this->_params);
-        if ($this->_vfs instanceof PEAR_Error) {
+        try {
+            $this->_vfs = VFS::singleton($this->_params['vfstype'], $this->_params);
+        } catch (VFS_Exception $e) {
             $error = new Ingo_Exception($this->_vfs);
             unset($this->_vfs);
-            throw new Ingo_Exception($error);
+            throw $error;
         }
     }
 
index 5d96b6c..0a23140 100644 (file)
@@ -228,6 +228,7 @@ class News {
      * Load VFS Backend
      *
      * @throws Horde_Exception
+     * @throws VFS_Exception
      */
     static public function loadVFS()
     {
@@ -238,9 +239,7 @@ class News {
         }
 
         $v_params = Horde::getVFSConfig('images');
-
-        $vfs = VFS::singleton($v_params['type'], $v_params['params']);
-        return $vfs;
+        return VFS::singleton($v_params['type'], $v_params['params']);
     }
 
     /**
@@ -256,10 +255,6 @@ class News {
         global $conf;
 
         $vfs = self::loadVFS();
-        if ($vfs instanceof PEAR_Error) {
-            return $vfs;
-        }
-
         $vfspath = self::VFS_PATH . '/images/' . $type;
         $vfs_name = $id . '.' . $conf['images']['image_type'];
 
@@ -278,10 +273,7 @@ class News {
         if ($type == 'news') {
 
             // Store full image
-            $result = $vfs->writeData($vfspath . '/full/', $vfs_name, $img->raw(), true);
-            if ($result instanceof PEAR_Error) {
-                return $result;
-            }
+            $vfs->writeData($vfspath . '/full/', $vfs_name, $img->raw(), true);
 
             // Resize big image?
             if ($resize) {
@@ -298,10 +290,7 @@ class News {
             }
 
             // Store big image
-            $result = $vfs->writeData($vfspath . '/big/', $vfs_name, $img->raw(), true);
-            if ($result instanceof PEAR_Error) {
-                return $result;
-            }
+            $vfs->writeData($vfspath . '/big/', $vfs_name, $img->raw(), true);
         }
 
         // Resize thumbnail
@@ -329,16 +318,10 @@ class News {
     static public function deleteImage($id)
     {
         $vfs = self::loadVFS();
-        if ($vfs instanceof PEAR_Error) {
-            return $vfs;
-        }
-
         $vfs_name = $id . '.' . $GLOBALS['conf']['images']['image_type'];
-        $result = $vfs->deleteFile(self::VFS_PATH . '/images/news/full', $vfs_name);
-        $result = $vfs->deleteFile(self::VFS_PATH . '/images/news/small', $vfs_name);
-        $result = $vfs->deleteFile(self::VFS_PATH . '/images/news/big', $vfs_name);
-
-        return $result;
+        $vfs->deleteFile(self::VFS_PATH . '/images/news/full', $vfs_name);
+        $vfs->deleteFile(self::VFS_PATH . '/images/news/small', $vfs_name);
+        $vfs->deleteFile(self::VFS_PATH . '/images/news/big', $vfs_name);
     }
 
     /**
@@ -350,11 +333,7 @@ class News {
     static public function saveFile($file_id, $file_src)
     {
         $vfs = self::loadVFS();
-        if ($vfs instanceof PEAR_Error) {
-            return $vfs;
-        }
-
-        return $vfs->writeData(self::VFS_PATH . '/files/', $file_id, file_get_contents($file_src), true);
+        $vfs->writeData(self::VFS_PATH . '/files/', $file_id, file_get_contents($file_src), true);
     }
 
     /**
@@ -365,11 +344,7 @@ class News {
     static public function getFile($file_id)
     {
         $vfs = self::loadVFS();
-        if ($vfs instanceof PEAR_Error) {
-            return $vfs;
-        }
-
-        return $vfs->read(self::VFS_PATH . '/files/', $file_id);
+        $vfs->read(self::VFS_PATH . '/files/', $file_id);
     }
 
     /**
@@ -380,15 +355,9 @@ class News {
     static public function deleteFile($file_id)
     {
         $vfs = self::loadVFS();
-        if ($vfs instanceof PEAR_Error) {
-            return $vfs;
-        }
-
         if ($vfs->exists(self::VFS_PATH . '/files/', $file_id)) {
-            return $vfs->deleteFile(self::VFS_PATH . '/files/', $file_id);
+            $vfs->deleteFile(self::VFS_PATH . '/files/', $file_id);
         }
-
-        return true;
     }
 
     /**
index 63e6d06..943015c 100644 (file)
@@ -239,13 +239,11 @@ class Turba_Object {
      *
      * @param array $info  A hash with the file information as returned from a
      *                     Horde_Form_Type_file.
+     * @throws Turba_Exception
      */
     function addFile($info)
     {
-        $result = $this->_vfsInit();
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
+        $this->_vfsInit();
 
         $dir = TURBA_VFS_PATH . '/' . $this->getValue('__uid');
         $file = $info['name'];
@@ -262,37 +260,44 @@ class Turba_Object {
             }
         }
 
-        return $this->_vfs->write($dir, $file, $info['tmp_name'], true);
+        try {
+            $this->_vfs->write($dir, $file, $info['tmp_name'], true);
+        } catch (VFS_Exception $e) {
+            throw new Turba_Exception($e);
+        }
     }
 
     /**
      * Deletes a file from the VFS backend associated with this object.
      *
      * @param string $file  The file name.
+     * @throws Turba_Exception
      */
     function deleteFile($file)
     {
-        if (!is_a($result = $this->_vfsInit(), 'PEAR_Error')) {
-            return $this->_vfs->deleteFile(TURBA_VFS_PATH . '/' . $this->getValue('__uid'), $file);
-        } else {
-            return $result;
+        $this->_vfsInit();
+        try {
+            $this->_vfs->deleteFile(TURBA_VFS_PATH . '/' . $this->getValue('__uid'), $file);
+        } catch (VFS_Exception $e) {
+            throw new Turba_Exception($e);
         }
     }
 
     /**
      * Deletes all files from the VFS backend associated with this object.
+     *
+     * @throws Turba_Exception
      */
     function deleteFiles()
     {
-        if (!is_a($result = $this->_vfsInit(), 'PEAR_Error')) {
-            if ($this->_vfs->exists(TURBA_VFS_PATH, $this->getValue('__uid'))) {
-                return $this->_vfs->deleteFolder(TURBA_VFS_PATH, $this->getValue('__uid'), true);
+        $this->_vfsInit();
+        if ($this->_vfs->exists(TURBA_VFS_PATH, $this->getValue('__uid'))) {
+            try {
+                $this->_vfs->deleteFolder(TURBA_VFS_PATH, $this->getValue('__uid'), true);
+            } catch (VFS_Exception $e) {
+                throw new Turba_Exception($e);
             }
-
-            return true;
         }
-
-        return $result;
     }
 
     /**
@@ -302,13 +307,14 @@ class Turba_Object {
      */
     function listFiles()
     {
-        $result = $this->_vfsInit();
+        try {
+            $this->_vfsInit();
+            if ($this->_vfs->exists(TURBA_VFS_PATH, $this->getValue('__uid'))) {
+                return $this->_vfs->listFolder(TURBA_VFS_PATH . '/' . $this->getValue('__uid'));
+            }
+        } catch (VFS_Exception $e) {}
 
-        if (!is_a($result, 'PEAR_Error') && $this->_vfs->exists(TURBA_VFS_PATH, $this->getValue('__uid'))) {
-            return $this->_vfs->listFolder(TURBA_VFS_PATH . '/' . $this->getValue('__uid'));
-        } else {
-            return array();
-        }
+        return array();
     }
 
     /**
@@ -389,16 +395,16 @@ class Turba_Object {
     function _vfsInit()
     {
         if (!isset($this->_vfs)) {
-            $v_params = Horde::getVFSConfig('documents');
-            if (is_a($v_params, 'PEAR_Error')) {
-                throw new Turba_Exception($v_params);
+            try {
+                $v_params = Horde::getVFSConfig('documents');
+            } catch (Horde_Exception $e) {
+                throw new Turba_Exception($e);
             }
-            $result = VFS::singleton($v_params['type'], $v_params['params']);
-            if (is_a($result, 'PEAR_Error')) {
-                return $result;
-            } else {
-                $this->_vfs = &$result;
-                return true;
+
+            try {
+                $this->_vfs = VFS::singleton($v_params['type'], $v_params['params']);
+            } catch (VFS_Exception $e) {
+                throw new Turba_Exception($e);
             }
         }
     }
index 0b26104..969105b 100644 (file)
@@ -38,18 +38,21 @@ if (!$object->hasPermission(Horde_Perms::READ)) {
     throw new Turba_Exception(_("You do not have permission to view this contact."));
 }
 
-$v_params = Horde::getVFSConfig('documents');
-if (is_a($v_params, 'PEAR_Error')) {
-    throw new Turba_Exception($v_params);
+try {
+    $v_params = Horde::getVFSConfig('documents');
+} catch (Horde_Exception $e) {
+    throw new Turba_Exception($e);
 }
-$vfs = VFS::singleton($v_params['type'], $v_params['params']);
-if (is_a($vfs, 'PEAR_Error')) {
-    throw new Turba_Exception($vfs);
-} else {
-    $data = $vfs->read(TURBA_VFS_PATH . '/' . $object->getValue('__uid'), $filename);
+try {
+    $vfs = VFS::singleton($v_params['type'], $v_params['params']);
+} catch (VFS_Exception $e) {
+    throw new Turba_Exception($e);
 }
-if (is_a($data, 'PEAR_Error')) {
-    Horde::logMessage($data, __FILE__, __LINE__, PEAR_LOG_ERR);
+
+try {
+    $data = $vfs->read(TURBA_VFS_PATH . '/' . $object->getValue('__uid'), $filename);
+} catch (VFS_Exception $e) {
+    Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
     throw new Turba_Exception(sprintf(_("Access denied to %s"), $filename));
 }
 
index 31867eb..5ff72b0 100644 (file)
@@ -511,16 +511,17 @@ class Whups_Driver_sql extends Whups_Driver {
                         'whups_attributes');
 
         if (!empty($conf['vfs']['type'])) {
-            require_once 'VFS.php';
-            $vfs = &VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs'));
-            if (is_a($vfs, 'PEAR_Error')) {
-                return $vfs;
-            } else {
-                if ($vfs->isFolder(WHUPS_VFS_ATTACH_PATH, $id)) {
-                    $result = $vfs->deleteFolder(WHUPS_VFS_ATTACH_PATH, $id, true);
-                    if (is_a($result, 'PEAR_Error')) {
-                        return $result;
-                    }
+            try {
+                $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs'));
+            } catch (VFS_Exception $e) {
+                return PEAR::raiseError($e->getMessage());
+            }
+
+            if ($vfs->isFolder(WHUPS_VFS_ATTACH_PATH, $id)) {
+                try {
+                    $vfs->deleteFolder(WHUPS_VFS_ATTACH_PATH, $id, true);
+                } catch (VFS_Exception $e) {
+                    return PEAR::raiseError($e->getMessage());
                 }
             }
         }
index 2cf2bd4..e3c8cc4 100644 (file)
@@ -433,11 +433,10 @@ class Whups_Ticket {
             return PEAR::raiseError(_("The VFS backend needs to be configured to enable attachment uploads."), 'horde.error');
         }
 
-        require_once 'VFS.php';
-        $vfs = &VFS::singleton($conf['vfs']['type'],
-                               Horde::getDriverConfig('vfs'));
-        if (is_a($vfs, 'PEAR_Error')) {
-            return $vfs;
+        try {
+            $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs'));
+        } catch (VFS_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
         }
 
         // Get existing attachment names.
@@ -463,7 +462,12 @@ class Whups_Ticket {
             }
         }
 
-        return $vfs->write($dir, $attachment_name, $attachment_file, true);
+        try {
+            $vfs->write($dir, $attachment_name, $attachment_file, true);
+            return true;
+        } catch (VFS_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
+        }
     }
 
     /**
@@ -481,11 +485,10 @@ class Whups_Ticket {
             return PEAR::raiseError(_("The VFS backend needs to be configured to enable attachment uploads."), 'horde.error');
         }
 
-        require_once 'VFS.php';
-        $vfs = &VFS::singleton($conf['vfs']['type'],
-                               Horde::getDriverConfig('vfs'));
-        if (is_a($vfs, 'PEAR_Error')) {
-            return $vfs;
+        try {
+            $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs'));
+        } catch (VFS_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
         }
 
         $dir = WHUPS_VFS_ATTACH_PATH . '/' . $this->_id;
@@ -495,7 +498,12 @@ class Whups_Ticket {
                                     'horde.error');
         }
 
-        return $vfs->deleteFile($dir, $attachment_name);
+        try {
+            $vfs->deleteFile($dir, $attachment_name);
+            return true;
+        } catch (VFS_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
+        }
     }
 
     /**
index ed59c7c..fe7496e 100644 (file)
@@ -789,14 +789,18 @@ class Whups {
             return false;
         }
 
-        require_once 'VFS.php';
-        $vfs = &VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs'));
-        if (is_a($vfs, 'PEAR_Error')) {
-            return $vfs;
+        try {
+            $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs'));
+        } catch (VFS_Exception $e) {
+            return PEAR::raiseError($vfs->getMessage());
         }
 
         if ($vfs->isFolder(WHUPS_VFS_ATTACH_PATH, $ticket)) {
-            $files = $vfs->listFolder(WHUPS_VFS_ATTACH_PATH . '/' . $ticket);
+            try {
+                $files = $vfs->listFolder(WHUPS_VFS_ATTACH_PATH . '/' . $ticket);
+            } catch (VFS_Exception $e) {
+                $files = array();
+            }
             if (is_null($name)) {
                 return $files;
             } else {
index 1698b28..a0c442d 100644 (file)
@@ -42,15 +42,11 @@ if (empty($conf['vfs']['type'])) {
     Horde::fatal(_("The VFS backend needs to be configured to enable attachment uploads."), __FILE__, __LINE__);
 }
 
-require_once 'VFS.php';
 $vfs = VFS::factory($conf['vfs']['type'], Horde::getDriverConfig('vfs'));
-if (is_a($vfs, 'PEAR_Error')) {
-    Horde::fatal($vfs, __FILE__, __LINE__);
-} else {
+try {
     $data = $vfs->read(WHUPS_VFS_ATTACH_PATH . '/' . $id, $filename);
-}
-if (is_a($data, 'PEAR_Error')) {
-    Horde::fatal(sprintf(_("Access denied to %s"), $filename), __FILE__, __LINE__);
+} catch (VFS_Exception $e) {
+    throw Horde_Exception(sprintf(_("Access denied to %s"), $filename));
 }
 
 /* Run through action handlers */
index a68e861..bb30435 100644 (file)
@@ -53,12 +53,18 @@ class Wicked_Driver {
 
     /**
      * Accessor to manage a VFS instance.
+     *
+     * @throws VFS_Exception
      */
-    function &getVFS()
+    function getVFS()
     {
         if (!$this->_vfs) {
-            $this->_vfs =& VFS::singleton($GLOBALS['conf']['vfs']['type'],
-                                          Horde::getDriverConfig('vfs'));
+            try {
+                $this->_vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'],
+                                             Horde::getDriverConfig('vfs'));
+            } catch (VFS_Exception $e) {
+                return PEAR::raiseError($e->getMessage());
+            }
         }
 
         return $this->_vfs;
@@ -309,7 +315,11 @@ class Wicked_Driver {
         /* We encode the path quoted printable so we won't get any nasty
          * characters the filesystem might reject. */
         $path = WICKED_VFS_ATTACH_PATH . '/' . $file['page_id'];
-        return $vfs->writeData($path, $file['attachment_name'] . ';' . $result, $data, true);
+        try {
+            $vfs->writeData($path, $file['attachment_name'] . ';' . $result, $data, true);
+        } catch (VFS_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
+        }
     }
 
     /**
@@ -342,9 +352,10 @@ class Wicked_Driver {
                 if (!$vfs->exists($path, $attachment . ';' . $fileversion)) {
                     continue;
                 }
-                $result = $vfs->deleteFile($path, $attachment . ';' . $fileversion);
-                if (is_a($result, 'PEAR_Error')) {
-                    return $result;
+                try {
+                    $vfs->deleteFile($path, $attachment . ';' . $fileversion);
+                } catch (VFS_Exception $e) {
+                    return PEAR::raiseError($result->getMessage());
                 }
             }
         }
@@ -369,7 +380,13 @@ class Wicked_Driver {
         if (!$vfs->isFolder(WICKED_VFS_ATTACH_PATH, $pageId)) {
             return true;
         }
-        return $vfs->deleteFolder(WICKED_VFS_ATTACH_PATH, $pageId, true);
+
+        try {
+            $vfs->deleteFolder(WICKED_VFS_ATTACH_PATH, $pageId, true);
+            return true;
+        } catch (VFS_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
+        }
     }
 
     /**
@@ -410,7 +427,12 @@ class Wicked_Driver {
         }
 
         $path = WICKED_VFS_ATTACH_PATH . '/' . $pageId;
-        return $vfs->read($path, $filename . ';' . $version);
+
+        try {
+            return $vfs->read($path, $filename . ';' . $version);
+        } catch (VFS_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
+        }
     }
 
     function removeVersion($pagename, $version)