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')
}
// 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']);
/**
* 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']);
}
/**
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);
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');
$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);
$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;
$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. */
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);
{
$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;
$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);
}
}
$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());
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 {
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());
+ }
}
/**
{
global $conf;
+ try {
$vfs = $this->_loadVFS();
if ($vfs instanceof PEAR_Error) {
return $vfs;
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
$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
<?php
-
-require_once 'Horde.php';
-require_once 'VFS.php';
-
/**
* 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;
}
/**
$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;
{
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');
}
$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;
}
}
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";
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;
}
}
{
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";
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;
}
* @param string $dir The directory name.
*
* @return array The sorted list of files.
+ * @throws VFS_Exception
*/
static public function listFolder($dir)
{
}
$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']);
* @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)
{
$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']);
* @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);
}
/**
* @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)
{
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);
}
* @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);
}
/**
* @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);
}
/**
* @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;
}
/**
* @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);
}
/**
* @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)
$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);
}
$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;
}
/**
// 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();
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;
}
$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();
$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;
}
* Constructor
*
* @param array $params Any parameters needed for this storage driver.
+ * @throws VFS_Exception
*/
function Hylax_Storage($params)
{
}
$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')
/* 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;
}
{
$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)
}
// 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.
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);
$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);
}
/* Store the data. */
- $result = $this->_storeAttachment($part, $attachment);
+ $this->_storeAttachment($part, $attachment);
return $filename;
}
* 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)
{
$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(
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);
}
}
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) {}
}
/**
$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);
/* 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. */
* 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;
}
/**
{
$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);
}
}
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);
}
}
}
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;
}
}
* Load VFS Backend
*
* @throws Horde_Exception
+ * @throws VFS_Exception
*/
static public function loadVFS()
{
}
$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']);
}
/**
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'];
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) {
}
// 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
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);
}
/**
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);
}
/**
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);
}
/**
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;
}
/**
*
* @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'];
}
}
- 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;
}
/**
*/
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();
}
/**
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);
}
}
}
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));
}
'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());
}
}
}
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.
}
}
- 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());
+ }
}
/**
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;
'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());
+ }
}
/**
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 {
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 */
/**
* 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;
/* 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());
+ }
}
/**
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());
}
}
}
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());
+ }
}
/**
}
$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)