From 28afc29b2359fc8cb0b73bdf541b30e79a1b3f30 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 17 Mar 2010 16:36:54 -0600 Subject: [PATCH] Use global injector binder to get VFS object using Horde vfs config --- agora/lib/Agora.php | 2 +- ansel/scripts/garbage_collection.php | 2 +- framework/Core/lib/Horde/Core/Binder/Vfs.php | 16 +++++++++ framework/Core/lib/Horde/Registry.php | 1 + framework/Core/package.xml | 2 ++ framework/Scheduler/lib/Horde/Scheduler.php | 6 ++-- horde/services/images/view.php | 2 +- hylax/lib/Storage.php | 9 ++--- imp/attachment.php | 2 +- imp/lib/Compose.php | 38 ++++++++++++++-------- .../LoginTasks/SystemTask/GarbageCollection.php | 2 +- .../LoginTasks/Task/DeleteAttachmentsMonthly.php | 2 +- whups/lib/Driver/sql.php | 6 ++-- whups/lib/Ticket.php | 12 +++---- whups/lib/Whups.php | 6 ++-- wicked/lib/Driver.php | 3 +- 16 files changed, 64 insertions(+), 47 deletions(-) create mode 100644 framework/Core/lib/Horde/Core/Binder/Vfs.php diff --git a/agora/lib/Agora.php b/agora/lib/Agora.php index 6c42b15a8..6170288e9 100644 --- a/agora/lib/Agora.php +++ b/agora/lib/Agora.php @@ -227,7 +227,7 @@ class Agora { } try { - return VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs')); + return $GLOBALS['injector']->getInstance('Horde_Vfs'); } catch (VFS_Exception $e) { return PEAR::raiseError($e); } diff --git a/ansel/scripts/garbage_collection.php b/ansel/scripts/garbage_collection.php index 59d4d9b26..94a94182b 100755 --- a/ansel/scripts/garbage_collection.php +++ b/ansel/scripts/garbage_collection.php @@ -36,7 +36,7 @@ foreach ($opts as $opt) { } } -$vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type'])); +$vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); $vfspath = '.horde/ansel/'; $garbagepath = $vfspath . 'garbage/'; diff --git a/framework/Core/lib/Horde/Core/Binder/Vfs.php b/framework/Core/lib/Horde/Core/Binder/Vfs.php new file mode 100644 index 000000000..fab94013a --- /dev/null +++ b/framework/Core/lib/Horde/Core/Binder/Vfs.php @@ -0,0 +1,16 @@ +setLogger($injector->getInstance('Horde_Log_Logger')); + + return $vfs; + } + + public function equals(Horde_Injector_Binder $binder) + { + return false; + } +} diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index bb56192eb..b5e6d42ac 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -241,6 +241,7 @@ class Horde_Registry 'Horde_Notification' => new Horde_Core_Binder_Notification(), 'Horde_Perms' => new Horde_Core_Binder_Perms(), 'Horde_Template' => new Horde_Core_Binder_Template(), + 'Horde_Vfs' => new Horde_Core_Binder_Vfs(), 'Net_DNS_Resolver' => new Horde_Core_Binder_Dns() ); diff --git a/framework/Core/package.xml b/framework/Core/package.xml index 2412cfbd3..c7062208b 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -72,6 +72,7 @@ Application Framework. + @@ -199,6 +200,7 @@ Application Framework. + diff --git a/framework/Scheduler/lib/Horde/Scheduler.php b/framework/Scheduler/lib/Horde/Scheduler.php index 5ef91e96e..68330ffb6 100644 --- a/framework/Scheduler/lib/Horde/Scheduler.php +++ b/framework/Scheduler/lib/Horde/Scheduler.php @@ -82,8 +82,7 @@ class Horde_Scheduler public function serialize($id = '') { try { - $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], - Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type'])); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); $vfs->writeData('.horde/scheduler', Horde_String::lower(get_class($this)) . $id, serialize($this), true); return true; } catch (VFS_Exception $e) { @@ -112,8 +111,7 @@ class Horde_Scheduler $scheduler = new $class; try { - $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], - Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type'])); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); $data = $vfs->read('.horde/scheduler', $class . $id); if ($tmp = @unserialize($data)) { $scheduler = $tmp; diff --git a/horde/services/images/view.php b/horde/services/images/view.php index 7a107a777..e531c61d2 100644 --- a/horde/services/images/view.php +++ b/horde/services/images/view.php @@ -34,7 +34,7 @@ case 'vfs': /* Getting a file from Horde's VFS. */ $path = Horde_Util::getFormData('p'); try { - $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type'])); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); $file_data = $vfs->read($path, $file); } catch (VFS_Exception $e) { Horde::logMessage(sprintf('Error displaying image [%s]: %s', $path . '/' . $file, $e->getMessage()), 'ERR'); diff --git a/hylax/lib/Storage.php b/hylax/lib/Storage.php index b879bb286..da5985359 100644 --- a/hylax/lib/Storage.php +++ b/hylax/lib/Storage.php @@ -32,17 +32,14 @@ class Hylax_Storage { */ function Hylax_Storage($params) { - global $conf; - $this->_params = $params; /* Set up the VFS storage. */ - if (!isset($conf['vfs']['type'])) { + if (!isset($GLOBALS['conf']['vfs']['type'])) { Horde::fatal(_("You must configure a VFS backend to use Hylax."), __FILE__, __LINE__); } - $vfs_driver = $conf['vfs']['type']; - $vfs_params = Horde::getDriverConfig('vfs', $vfs_driver); - $this->_vfs = VFS::singleton($vfs_driver, $vfs_params); + + $this->_vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); } function saveFaxData($data, $type = '.ps') diff --git a/imp/attachment.php b/imp/attachment.php index f9fea8815..767f8d4d6 100644 --- a/imp/attachment.php +++ b/imp/attachment.php @@ -34,7 +34,7 @@ if (is_null($mail_user) || is_null($time_stamp) || is_null($file_name)) { // Initialize the VFS. try { - $vfsroot = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type'])); + $vfsroot = $injector->getInstance('Horde_Vfs'); } catch (VFS_Exception $e) { throw new IMP_Exception(sprintf(_("Could not create the VFS backend: %s"), $e->getMessage())); } diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index 6e7aaaf9c..81f5adc34 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -1882,14 +1882,12 @@ class IMP_Compose */ protected function _storeAttachment($part, $data, $vfs_file = true) { - global $conf; - /* Store in VFS. */ - if ($conf['compose']['use_vfs']) { - $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type'])); - $cacheID = uniqid(mt_rand()); - + if ($GLOBALS['conf']['compose']['use_vfs']) { try { + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); + $cacheID = uniqid(mt_rand()); + if ($vfs_file) { $vfs->write(self::VFS_ATTACH_PATH, $cacheID, $data, true); } else { @@ -1945,8 +1943,10 @@ class IMP_Compose switch ($atc['filetype']) { case 'vfs': /* Delete from VFS. */ - $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type'])); - $vfs->deleteFile(self::VFS_ATTACH_PATH, $atc['filename']); + try { + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); + $vfs->deleteFile(self::VFS_ATTACH_PATH, $atc['filename']); + } catch (VFS_Exception $e) {} break; case 'file': @@ -2037,8 +2037,10 @@ class IMP_Compose switch ($this->_cache[$id]['filetype']) { case 'vfs': // TODO: Use streams - $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type'])); - $part->setContents($vfs->read(self::VFS_ATTACH_PATH, $this->_cache[$id]['filename'])); + try { + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); + $part->setContents($vfs->read(self::VFS_ATTACH_PATH, $this->_cache[$id]['filename'])); + } catch (VFS_Exception $e) {} break; case 'file': @@ -2318,7 +2320,11 @@ class IMP_Compose $auth = Horde_Auth::getAuth(); $baseurl = Horde::applicationUrl('attachment.php', true)->setRaw(true); - $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type'])); + try { + $GLOBALS['injector']->getInstance('Horde_Vfs'); + } catch (VFS_Exception $e) { + throw new IMP_Compose_Exception($e); + } $ts = time(); $fullpath = sprintf('%s/%s/%d', self::VFS_LINK_ATTACH_PATH, $auth, $ts); @@ -2615,7 +2621,7 @@ class IMP_Compose } try { - $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type'])); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); $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.")); @@ -2632,7 +2638,13 @@ class IMP_Compose } $filename = hash('md5', Horde_Auth::getAuth()); - $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type'])); + + try { + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); + } catch (VFS_Exception $e) { + return; + } + if ($vfs->exists(self::VFS_DRAFTS_PATH, $filename)) { try { $data = $vfs->read(self::VFS_DRAFTS_PATH, $filename); diff --git a/imp/lib/LoginTasks/SystemTask/GarbageCollection.php b/imp/lib/LoginTasks/SystemTask/GarbageCollection.php index 20e8fa1c9..45a81de0b 100644 --- a/imp/lib/LoginTasks/SystemTask/GarbageCollection.php +++ b/imp/lib/LoginTasks/SystemTask/GarbageCollection.php @@ -34,7 +34,7 @@ class IMP_LoginTasks_SystemTask_GarbageCollection extends Horde_LoginTasks_Syste /* Do garbage collection on compose VFS data. */ if ($GLOBALS['conf']['compose']['use_vfs']) { try { - $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type'])); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); VFS_GC::gc($vfs, IMP_Compose::VFS_ATTACH_PATH, 86400); } catch (VFS_Exception $e) {} } diff --git a/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php b/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php index dbd4cda20..395891bf3 100644 --- a/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php +++ b/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php @@ -34,7 +34,7 @@ class IMP_LoginTasks_Task_DeleteAttachmentsMonthly extends Horde_LoginTasks_Task $del_time = gmmktime(0, 0, 0, date('n') - $GLOBALS['prefs']->getValue('delete_attachments_monthly_keep'), 1, date('Y')); try { - $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type'])); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); } catch (VFS_Exception $e) { return false; } diff --git a/whups/lib/Driver/sql.php b/whups/lib/Driver/sql.php index bb2cef9d2..3fca21e95 100644 --- a/whups/lib/Driver/sql.php +++ b/whups/lib/Driver/sql.php @@ -490,8 +490,6 @@ class Whups_Driver_sql extends Whups_Driver { function deleteTicket($info) { - global $conf; - $id = (int)$info['id']; $tables = array('whups_ticket_listeners', @@ -500,9 +498,9 @@ class Whups_Driver_sql extends Whups_Driver { 'whups_tickets', 'whups_attributes'); - if (!empty($conf['vfs']['type'])) { + if (!empty($GLOBALS['conf']['vfs']['type'])) { try { - $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs')); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); } catch (VFS_Exception $e) { return PEAR::raiseError($e->getMessage()); } diff --git a/whups/lib/Ticket.php b/whups/lib/Ticket.php index 05da3ea76..98a8daf22 100644 --- a/whups/lib/Ticket.php +++ b/whups/lib/Ticket.php @@ -427,14 +427,12 @@ class Whups_Ticket { */ function addAttachment(&$attachment_name, $attachment_file) { - global $conf; - - if (!isset($conf['vfs']['type'])) { + if (!isset($GLOBALS['conf']['vfs']['type'])) { return PEAR::raiseError(_("The VFS backend needs to be configured to enable attachment uploads."), 'horde.error'); } try { - $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs')); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); } catch (VFS_Exception $e) { return PEAR::raiseError($e->getMessage()); } @@ -479,14 +477,12 @@ class Whups_Ticket { */ function deleteAttachment($attachment_name) { - global $conf; - - if (!isset($conf['vfs']['type'])) { + if (!isset($GLOBALS['conf']['vfs']['type'])) { return PEAR::raiseError(_("The VFS backend needs to be configured to enable attachment uploads."), 'horde.error'); } try { - $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs')); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); } catch (VFS_Exception $e) { return PEAR::raiseError($e->getMessage()); } diff --git a/whups/lib/Whups.php b/whups/lib/Whups.php index dda1212b6..1e3564190 100644 --- a/whups/lib/Whups.php +++ b/whups/lib/Whups.php @@ -783,14 +783,12 @@ class Whups { */ function getAttachments($ticket, $name = null) { - global $conf; - - if (empty($conf['vfs']['type'])) { + if (empty($GLOBALS['conf']['vfs']['type'])) { return false; } try { - $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs')); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); } catch (VFS_Exception $e) { return PEAR::raiseError($vfs->getMessage()); } diff --git a/wicked/lib/Driver.php b/wicked/lib/Driver.php index bb304355b..a043379d8 100644 --- a/wicked/lib/Driver.php +++ b/wicked/lib/Driver.php @@ -60,8 +60,7 @@ class Wicked_Driver { { if (!$this->_vfs) { try { - $this->_vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], - Horde::getDriverConfig('vfs')); + $this->_vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); } catch (VFS_Exception $e) { return PEAR::raiseError($e->getMessage()); } -- 2.11.0