Skip to content

Commit

Permalink
Only run shutdown function once for Share factory
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Jan 28, 2014
1 parent 30177c4 commit 5665076
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions framework/Core/lib/Horde/Core/Factory/ShareBase.php
Expand Up @@ -28,6 +28,13 @@ class Horde_Core_Factory_ShareBase extends Horde_Core_Factory_Base
*/
protected $_instances = array();

/**
* Cache of session share entries.
*
* @var array
*/
protected $_sessionCache = array();

/**
* Returns the share driver instance.
*
Expand All @@ -40,8 +47,10 @@ class Horde_Core_Factory_ShareBase extends Horde_Core_Factory_Base
*/
public function create($app = null, $driver = null)
{
global $conf, $registry, $session;

if (empty($driver)) {
$driver = $GLOBALS['conf']['share']['driver'];
$driver = $conf['share']['driver'];
}
if (empty($app)) {
$app = $this->_injector->getInstance('Horde_Registry')->getApp();
Expand All @@ -53,15 +62,21 @@ public function create($app = null, $driver = null)
}

$class = $this->_getDriverName($driver, 'Horde_Share');
$ob = new $class($app, $GLOBALS['registry']->getAuth(), $this->_injector->getInstance('Horde_Perms'), $this->_injector->getInstance('Horde_Group'));
$ob = new $class($app, $registry->getAuth(), $this->_injector->getInstance('Horde_Perms'), $this->_injector->getInstance('Horde_Group'));
$cb = new Horde_Core_Share_FactoryCallback($app, $driver);
$ob->setShareCallback(array($cb, 'create'));
$ob->setLogger($this->_injector->getInstance('Horde_Log_Logger'));
if (!empty($GLOBALS['conf']['share']['cache'])) {

if (!empty($conf['share']['cache'])) {
$cache_sig = 'horde_share/' . $app . '/' . $driver;
$listCache = $GLOBALS['session']->retrieve($cache_sig);
$listCache = $session->retrieve($cache_sig);
$ob->setListCache($listCache);
register_shutdown_function(array($this, 'shutdown'), $cache_sig, $ob);

if (empty($this->_sessionCache)) {
register_shutdown_function(array($this, 'shutdown'));
}

$this->_sessionCache[$sig] = $cache_sig;
}

$this->_instances[$sig] = $ob;
Expand All @@ -71,13 +86,14 @@ public function create($app = null, $driver = null)

/**
* Shutdown function.
*
* @param string $sig Cache signature.
* @param Horde_Share_Base $share Share object to cache.
*/
public function shutdown($sig, $share)
public function shutdown()
{
$GLOBALS['session']->store($share->getListCache(), false, $sig);
global $session;

foreach ($this->_sessionCache as $sig => $cache_sig) {
$session->store($this->_instances[$sig]->getListCache(), false, $cache_sig);
}
}

}

0 comments on commit 5665076

Please sign in to comment.