From: Michael M Slusarz Date: Tue, 9 Mar 2010 23:17:04 +0000 (-0700) Subject: Catch VFS thrown exceptions X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=e9bd13ca26c027fe3ee2eca3566b3c9c82fd8756;p=horde.git Catch VFS thrown exceptions --- diff --git a/agora/lib/Agora.php b/agora/lib/Agora.php index d3624f1d5..6c42b15a8 100644 --- a/agora/lib/Agora.php +++ b/agora/lib/Agora.php @@ -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') diff --git a/ansel/faces/img.php b/ansel/faces/img.php index 625ab9263..1cb4df07d 100644 --- a/ansel/faces/img.php +++ b/ansel/faces/img.php @@ -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']); diff --git a/ansel/lib/Ansel.php b/ansel/lib/Ansel.php index 47415602d..949d0619c 100644 --- a/ansel/lib/Ansel.php +++ b/ansel/lib/Ansel.php @@ -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']); } /** diff --git a/ansel/lib/Api.php b/ansel/lib/Api.php index 2af2a7aa4..73629bcec 100644 --- a/ansel/lib/Api.php +++ b/ansel/lib/Api.php @@ -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); diff --git a/ansel/lib/Application.php b/ansel/lib/Application.php index f470d63d9..35b25fd9b 100644 --- a/ansel/lib/Application.php +++ b/ansel/lib/Application.php @@ -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'); diff --git a/ansel/lib/Faces/Base.php b/ansel/lib/Faces/Base.php index 648b0a219..bc6bf9003 100644 --- a/ansel/lib/Faces/Base.php +++ b/ansel/lib/Faces/Base.php @@ -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; diff --git a/ansel/lib/Image.php b/ansel/lib/Image.php index 39e201a75..0775350a4 100644 --- a/ansel/lib/Image.php +++ b/ansel/lib/Image.php @@ -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 { diff --git a/folks/lib/Driver.php b/folks/lib/Driver.php index 6abcb2263..dd036587f 100644 --- a/folks/lib/Driver.php +++ b/folks/lib/Driver.php @@ -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 diff --git a/framework/Scheduler/lib/Horde/Scheduler.php b/framework/Scheduler/lib/Horde/Scheduler.php index 93a49bb09..793c74bb7 100644 --- a/framework/Scheduler/lib/Horde/Scheduler.php +++ b/framework/Scheduler/lib/Horde/Scheduler.php @@ -1,8 +1,4 @@ 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; diff --git a/framework/VFS_ISOWriter/tests/inputstrategy.phpt b/framework/VFS_ISOWriter/tests/inputstrategy.phpt index 81aa3130e..da016c842 100644 --- a/framework/VFS_ISOWriter/tests/inputstrategy.phpt +++ b/framework/VFS_ISOWriter/tests/inputstrategy.phpt @@ -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; } } diff --git a/framework/VFS_ISOWriter/tests/isowriter.phpt b/framework/VFS_ISOWriter/tests/isowriter.phpt index 26b9e2a27..4e5658f90 100644 --- a/framework/VFS_ISOWriter/tests/isowriter.phpt +++ b/framework/VFS_ISOWriter/tests/isowriter.phpt @@ -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; } } diff --git a/framework/VFS_ISOWriter/tests/outputstrategy.phpt b/framework/VFS_ISOWriter/tests/outputstrategy.phpt index b7e948fda..352d560b9 100644 --- a/framework/VFS_ISOWriter/tests/outputstrategy.phpt +++ b/framework/VFS_ISOWriter/tests/outputstrategy.phpt @@ -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; } diff --git a/gollem/lib/Gollem.php b/gollem/lib/Gollem.php index d77c503ca..906af282c 100644 --- a/gollem/lib/Gollem.php +++ b/gollem/lib/Gollem.php @@ -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(); diff --git a/horde/admin/setup/index.php b/horde/admin/setup/index.php index f5c2d5310..0947dc9b2 100644 --- a/horde/admin/setup/index.php +++ b/horde/admin/setup/index.php @@ -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(); diff --git a/horde/services/images/view.php b/horde/services/images/view.php index 011f0612a..b33302c07 100644 --- a/horde/services/images/view.php +++ b/horde/services/images/view.php @@ -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; } diff --git a/hylax/lib/Storage.php b/hylax/lib/Storage.php index f4db1e567..6cbfe8076 100644 --- a/hylax/lib/Storage.php +++ b/hylax/lib/Storage.php @@ -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) diff --git a/imp/attachment.php b/imp/attachment.php index 507182f8f..b823795d7 100644 --- a/imp/attachment.php +++ b/imp/attachment.php @@ -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); diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index b6b61b3ed..fef73f780 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -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); diff --git a/imp/lib/LoginTasks/SystemTask/GarbageCollection.php b/imp/lib/LoginTasks/SystemTask/GarbageCollection.php index a1469363d..20e8fa1c9 100644 --- a/imp/lib/LoginTasks/SystemTask/GarbageCollection.php +++ b/imp/lib/LoginTasks/SystemTask/GarbageCollection.php @@ -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. */ diff --git a/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php b/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php index e0dee3e9e..dbd4cda20 100644 --- a/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php +++ b/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php @@ -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; } /** diff --git a/ingo/lib/Driver/Vfs.php b/ingo/lib/Driver/Vfs.php index 83bc49d70..7bd9f4133 100644 --- a/ingo/lib/Driver/Vfs.php +++ b/ingo/lib/Driver/Vfs.php @@ -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; } } diff --git a/news/lib/News.php b/news/lib/News.php index 5d96b6cb5..0a2314026 100644 --- a/news/lib/News.php +++ b/news/lib/News.php @@ -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; } /** diff --git a/turba/lib/Object.php b/turba/lib/Object.php index 63e6d06d8..943015cef 100644 --- a/turba/lib/Object.php +++ b/turba/lib/Object.php @@ -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); } } } diff --git a/turba/view.php b/turba/view.php index 0b26104c2..969105bd8 100644 --- a/turba/view.php +++ b/turba/view.php @@ -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)); } diff --git a/whups/lib/Driver/sql.php b/whups/lib/Driver/sql.php index 31867eb9f..5ff72b0d3 100644 --- a/whups/lib/Driver/sql.php +++ b/whups/lib/Driver/sql.php @@ -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()); } } } diff --git a/whups/lib/Ticket.php b/whups/lib/Ticket.php index 2cf2bd4f0..e3c8cc464 100644 --- a/whups/lib/Ticket.php +++ b/whups/lib/Ticket.php @@ -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()); + } } /** diff --git a/whups/lib/Whups.php b/whups/lib/Whups.php index ed59c7c8a..fe7496efb 100644 --- a/whups/lib/Whups.php +++ b/whups/lib/Whups.php @@ -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 { diff --git a/whups/view.php b/whups/view.php index 1698b28e1..a0c442d3d 100644 --- a/whups/view.php +++ b/whups/view.php @@ -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 */ diff --git a/wicked/lib/Driver.php b/wicked/lib/Driver.php index a68e861a1..bb304355b 100644 --- a/wicked/lib/Driver.php +++ b/wicked/lib/Driver.php @@ -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)