const OTHER_KEY = 'other\0';
/**
- * The cache ID value.
+ * Tree changed flag. Set when something in the tree has been altered.
*
- * @var string
+ * @var boolean
*/
- public $cacheId;
+ public $changed = false;
/**
* Array containing the mailbox tree.
protected $_fulllist = null;
/**
- * Tree changed flag. Set when something in the tree has been altered.
- *
- * @var boolean
- */
- protected $_changed = false;
-
- /**
* Have we shown unsubscribed folders previously?
*
* @var boolean
}
$this->init();
- $this->__wakeup();
}
/**
}
/**
- * Tasks to do on wakeup.
- */
- public function __wakeup()
- {
- register_shutdown_function(array($this, 'shutdown'));
- }
-
- /**
- * Store a serialized version of ourself in the current session.
- */
- public function shutdown()
- {
- /* We only need to store the object if using Horde_Cache and the tree
- * has changed. */
- if (!empty($this->_changed) && $this->cacheId) {
- $GLOBALS['injector']->getInstance('Horde_Cache')->set($this->cacheId, serialize($this), 86400);
- }
- }
-
- /**
* Returns the list of mailboxes on the server.
*
* @param boolean $showunsub Show unsubscribed mailboxes?
$_SESSION['imp']['showunsub']);
/* Reset class variables to the defaults. */
- $this->_changed = true;
+ $this->changed = true;
$this->_currkey = $this->_currparent = $this->_subscribed = null;
$this->_currstack = $this->_tree = $this->_parent = array();
$this->_showunsub = $this->_unsubview = $unsubmode;
if ($this->hasChildren($elt)) {
if (!$this->isOpen($elt)) {
- $this->_changed = true;
+ $this->changed = true;
$this->_setOpen($elt, true);
}
if (isset($this->_tree[$folder]) &&
$this->isOpen($this->_tree[$folder])) {
- $this->_changed = true;
+ $this->changed = true;
$this->_setOpen($this->_tree[$folder], false);
}
}
return;
}
- $this->_changed = true;
+ $this->changed = true;
/* Set the parent array to the value in $elt['p']. */
if (empty($this->_parent[$elt['p']])) {
} else {
$this->_parent[$parent] = array_values($this->_parent[$parent]);
}
- $this->_changed = true;
+ $this->changed = true;
return true;
}
return false;
}
- $this->_changed = true;
+ $this->changed = true;
$elt = &$this->_tree[$id];
foreach ($id as $val) {
$val = $this->_convertName($val);
if (isset($this->_tree[$val])) {
- $this->_changed = true;
+ $this->changed = true;
$this->_setSubscribed($this->_tree[$val], true);
$this->_setContainer($this->_tree[$val], false);
}
/* INBOX can never be unsubscribed to. */
if (isset($this->_tree[$val]) && ($val != 'INBOX')) {
- $this->_changed = $this->_unsubview = true;
+ $this->changed = $this->_unsubview = true;
$elt = &$this->_tree[$val];
if ($changed) {
$GLOBALS['prefs']->setValue('nav_poll', serialize($this->_poll));
$GLOBALS['imp_search']->createVINBOXFolder();
- $this->_changed = true;
+ $this->changed = true;
}
}
if ($removed) {
$GLOBALS['prefs']->setValue('nav_poll', serialize($this->_poll));
$GLOBALS['imp_search']->createVINBOXFolder();
- $this->_changed = true;
+ $this->changed = true;
}
}
}
$this->_showunsub = $unsub;
- $this->_changed = true;
+ $this->changed = true;
/* If we are switching from unsubscribed to subscribed, no need
* to do anything (we just ignore unsubscribed stuff). */
*/
public function eltDiff()
{
- if (is_null($this->_eltdiff) || !$this->_changed) {
+ if (is_null($this->_eltdiff) || !$this->changed) {
return false;
}
natcasesort($vsort);
$this->_parent[self::VFOLDER_KEY] = array_keys($vsort);
$this->_setNeedSort($this->_tree[self::VFOLDER_KEY], false);
- $this->_changed = true;
+ $this->changed = true;
}
/**
if ($this->_needSort($this->_tree[$id])) {
$this->_sortList($this->_parent[$id], ($id === self::BASE_ELT));
$this->_setNeedSort($this->_tree[$id], false);
- $this->_changed = true;
+ $this->changed = true;
}
}
public function create(Horde_Injector $injector)
{
$cache = $injector->getInstance('Horde_Cache');
+ $instance = null;
if (empty($_SESSION['imp']['cache']['tree'])) {
- $_SESSION['imp']['cache']['tree'] = uniqid(mt_rand() . Horde_Auth::getAuth());
- } elseif ($instance = @unserialize($cache->get($_SESSION['imp']['cache']['tree'], 86400))) {
- return $instance;
+ if (!($cache instanceof Horde_Cache_Null)) {
+ $_SESSION['imp']['cache']['tree'] = uniqid(mt_rand() . Horde_Auth::getAuth());
+ }
+ } else {
+ $instance = @unserialize($cache->get($_SESSION['imp']['cache']['tree'], 86400));
}
- $instance = new IMP_Imap_Tree();
- $instance->cacheId = $_SESSION['imp']['cache']['tree'];
+ if (empty($instance)) {
+ $instance = new IMP_Imap_Tree();
+ }
+
+ register_shutdown_function(array($this, 'shutdown'), $instance);
return $instance;
}
+ /**
+ * Store serialized version of object in the current session.
+ */
+ public function shutdown($instance)
+ {
+ /* Only need to store the object if using Horde_Cache and the tree
+ * has changed. */
+ if ($instance->changed && isset($_SESSION['imp']['cache']['tree'])) {
+ $GLOBALS['injector']->getInstance('Horde_Cache')->set($_SESSION['imp']['cache']['tree'], serialize($instance), 86400);
+ }
+ }
+
public function equals(Horde_Injector_Binder $binder)
{
return false;