// This is a case where it is possible that the parent element has
// changed (it now has children) but we can't catch it via the
// bitflag (since hasChildren() is dynamically determined).
- if (isset($this->_eltdiff[$elt['p']])) {
- $this->_eltdiff[$elt['p']]['changed'] = true;
+ if (!is_null($this->_eltdiff)) {
+ $this->_eltdiff['c'][$elt['p']] = 1;
}
}
$this->_parent[$elt['p']][] = $elt['v'];
$this->_tree[$elt['v']] = $elt;
+ if (!is_null($this->_eltdiff)) {
+ $this->_eltdiff['a'][$elt['v']] = 1;
+ }
+
/* Make sure we are sorted correctly. */
if (count($this->_parent[$elt['p']]) > 1) {
$this->_setNeedSort($this->_tree[$elt['p']], true);
$key = array_search($id, $this->_parent[$parent]);
unset($this->_parent[$parent][$key]);
+ if (!is_null($this->_eltdiff)) {
+ $this->_eltdiff['d'][$id] = 1;
+ }
+
if (empty($this->_parent[$parent])) {
/* This folder is now completely empty (no children). If the
* folder is a container only, we should delete the folder from
* element has changed (it no longer has children) but
* we can't catch it via the bitflag (since hasChildren()
* is dynamically determined). */
- if (isset($this->_eltdiff[$parent])) {
- $this->_eltdiff[$parent]['changed'] = true;
+ if (!is_null($this->_eltdiff)) {
+ $this->_eltdiff['c'][$parent] = 1;
}
}
}
*/
public function eltDiffStart()
{
- $this->_eltdiff = $this->_tree;
+ $this->_eltdiff = array('a' => array(), 'c' => array(), 'd' => array());
}
/**
*/
public function eltDiff()
{
- if (!$this->_changed || !$this->_eltdiff) {
+ if (!$this->_changed) {
return false;
}
- $added = $changed = $deleted = array();
-
- /* Determine the deleted items. */
- $deleted = array_values(array_diff(array_keys($this->_eltdiff), array_keys($this->_tree)));
-
- foreach ($this->_tree as $key => $val) {
- if (!isset($this->_eltdiff[$key])) {
- $added[] = $key;
- } elseif ($val != $this->_eltdiff[$key]) {
- $changed[] = $key;
- }
- }
-
- if (empty($added) && empty($changed) && empty($deleted)) {
- return false;
- } else {
- return array('a' => $added, 'c' => $changed, 'd' => $deleted);
- }
+ return array(
+ 'a' => array_keys($this->_eltdiff['a']),
+ 'c' => array_keys($this->_eltdiff['c']),
+ 'd' => array_keys($this->_eltdiff['d'])
+ );
}
/**
}
foreach (array_keys($id) as $key) {
- $adds[] = $this->VFOLDER_KEY . $this->_delimiter . $key;
+ $id_key = $this->VFOLDER_KEY . $this->_delimiter . $key;
+ if (!isset($this->_tree[$id_key])) {
+ $adds[] = $this->VFOLDER_KEY . $this->_delimiter . $key;
+ }
+ }
+
+ if (empty($adds)) {
+ return;
}
$this->insert($adds);
$_SESSION['imp']['search'] = array('q' => array());
}
if (!$no_vf) {
+ $imaptree = &IMP_IMAP_Tree::singleton();
foreach ($this->_getVFolderList() as $key => $val) {
if (!empty($val['vfolder']) &&
!$this->isVTrashFolder($key) &&
!$this->isVINBOXFolder($key)) {
- $this->_updateIMPTree('add', $key, $val['label']);
+ $imaptree->insertVFolders(array($key => $val['label']));
unset($val['uiinfo']);
$_SESSION['imp']['search']['q'][$key] = $val;
}
/**
* Deletes an IMAP search query.
*
- * @param string $id The search query id to use (by default, will use
- * the current ID set in the object).
+ * @param string $id The search query id to use (by default, will
+ * use the current ID set in the object).
+ * @param boolean $no_delete Don't delete the entry in
*
* @return string Returns the search query id.
*/
- public function deleteSearchQuery($id = null)
+ public function deleteSearchQuery($id = null, $no_delete = false)
{
$id = $this->_strip($id);
$is_vfolder = !empty($_SESSION['imp']['search']['q'][$id]['vfolder']);
$vfolders = $this->_getVFolderList();
unset($vfolders[$id]);
$this->_saveVFolderList($vfolders);
- $this->_updateIMPTree('delete', $id);
+ if (!$no_delete) {
+ $imaptree = &IMP_IMAP_Tree::singleton();
+ $imaptree->delete($id);
+ }
}
}
$vfolders[$id] = $_SESSION['imp']['search']['q'][$id];
$this->_saveVFolderList($vfolders);
}
- $this->_updateIMPTree('add', $id, $label);
+
+ $imaptree = &IMP_IMAP_Tree::singleton();
+ $imaptree->insertVFolders(array($id => $label));
+
return $id;
}
/* Delete the current Virtual Trash folder, if it exists. */
$vtrash_id = $GLOBALS['prefs']->getValue('vtrash_id');
if (!empty($vtrash_id)) {
- $this->deleteSearchQuery($vtrash_id);
+ $this->deleteSearchQuery($vtrash_id, true);
}
if (!$GLOBALS['prefs']->getValue('use_vtrash')) {
/* Delete the current Virtual Inbox folder, if it exists. */
$vinbox_id = $GLOBALS['prefs']->getValue('vinbox_id');
if (!empty($vinbox_id)) {
- $this->deleteSearchQuery($vinbox_id);
+ $this->deleteSearchQuery($vinbox_id, true);
}
if (!$GLOBALS['prefs']->getValue('use_vinbox')) {
}
/**
- * Update IMAP_Tree object.
- *
- * @param string $action Either 'delete' or 'add'.
- * @param string $id The query ID to update.
- * @param string $label If $action = 'add', the label to use for the
- * query ID.
- */
- protected function _updateIMPTree($action, $id, $label = null)
- {
- $imaptree = &IMP_IMAP_Tree::singleton();
-
- switch ($action) {
- case 'delete':
- $imaptree->delete($id);
- break;
-
- case 'add':
- $imaptree->insertVFolders(array($id => $label));
- break;
- }
- }
-
- /**
* Creates a search query.
*
* @param array $uiinfo A UI info array (see imp/search.php).