From 1bba11a7beb8565805f06c54d6b03b8296368c21 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 9 Dec 2008 21:55:58 -0700 Subject: [PATCH] Don't include Virtual Folders in list of updated elements. Also, improve element diff determination. --- imp/lib/IMAP/Tree.php | 52 ++++++++++++++++++++++++++------------------------- imp/lib/Search.php | 47 ++++++++++++++++------------------------------ 2 files changed, 43 insertions(+), 56 deletions(-) diff --git a/imp/lib/IMAP/Tree.php b/imp/lib/IMAP/Tree.php index e22acc674..422f26193 100644 --- a/imp/lib/IMAP/Tree.php +++ b/imp/lib/IMAP/Tree.php @@ -746,13 +746,17 @@ class IMP_IMAP_Tree // 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); @@ -842,6 +846,10 @@ class IMP_IMAP_Tree $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 @@ -858,8 +866,8 @@ class IMP_IMAP_Tree * 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; } } } @@ -1428,7 +1436,7 @@ class IMP_IMAP_Tree */ public function eltDiffStart() { - $this->_eltdiff = $this->_tree; + $this->_eltdiff = array('a' => array(), 'c' => array(), 'd' => array()); } /** @@ -1445,28 +1453,15 @@ class IMP_IMAP_Tree */ 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']) + ); } /** @@ -1489,7 +1484,14 @@ class IMP_IMAP_Tree } 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); diff --git a/imp/lib/Search.php b/imp/lib/Search.php index 43d134012..e6a5aab4b 100644 --- a/imp/lib/Search.php +++ b/imp/lib/Search.php @@ -92,11 +92,12 @@ class IMP_Search $_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; } @@ -205,12 +206,13 @@ class IMP_Search /** * 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']); @@ -220,7 +222,10 @@ class IMP_Search $vfolders = $this->_getVFolderList(); unset($vfolders[$id]); $this->_saveVFolderList($vfolders); - $this->_updateIMPTree('delete', $id); + if (!$no_delete) { + $imaptree = &IMP_IMAP_Tree::singleton(); + $imaptree->delete($id); + } } } @@ -324,7 +329,10 @@ class IMP_Search $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; } @@ -336,7 +344,7 @@ class IMP_Search /* 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')) { @@ -396,7 +404,7 @@ class IMP_Search /* 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')) { @@ -786,29 +794,6 @@ class IMP_Search } /** - * 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). -- 2.11.0