Skip to content

Commit

Permalink
Abstract delete code into various account objects
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Sep 24, 2013
1 parent 7ae4fe0 commit 3c38bcd
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 13 deletions.
28 changes: 15 additions & 13 deletions imp/lib/Ftree.php
Expand Up @@ -285,9 +285,14 @@ public function delete($id)
}

foreach (array_filter(array_map(array($this, 'offsetGet'), $id)) as $elt) {
if ($elt->vfolder) {
unset($this->_accounts[strval($elt)]);
} elseif ($elt->remote_auth) {
$account = $this->getAccount($elt);
if (!($mask = $account->delete($elt))) {
continue;
}

$this->_changed = true;

if ($mask & IMP_Ftree_Account::DELETE_RECURSIVE) {
$iterator = iterator_to_array(
IMP_Ftree_IteratorFilter::create(0, $elt),
false
Expand All @@ -299,15 +304,14 @@ public function delete($id)
);
$this->eltdiff->delete($val);
}
unset(
$this->_accounts[strval($elt)],
$this->_parent[strval($elt)]
);
} else {
if ($elt->inbox || $elt->namespace) {
continue;
}
unset($this->_parent[strval($elt)]);
}

if (strval($account) == strval($elt)) {
unset($this->_accounts[strval($elt)]);
}

if ($mask & IMP_Ftree_Account::DELETE_ELEMENT) {
/* Do not delete from tree if there are child elements -
* instead, convert to a container element. */
if ($elt->children) {
Expand All @@ -322,8 +326,6 @@ public function delete($id)
$this->poll->removePollList($elt);
}

$this->_changed = true;

$parent = strval($elt->parent);
$this->eltdiff->delete($elt);

Expand Down
14 changes: 14 additions & 0 deletions imp/lib/Ftree/Account.php
Expand Up @@ -26,6 +26,11 @@ abstract class IMP_Ftree_Account implements Serializable
const INIT = 1;
const UNSUB = 2;

/* Mask constants for delete(). */
const DELETE_ELEMENT = 1;
const DELETE_ELEMENT_QUICK = 2;
const DELETE_RECURSIVE = 4;

/**
* Account ID.
*
Expand Down Expand Up @@ -62,6 +67,15 @@ public function __toString()
*/
abstract public function getList($query = null);

/**
* Return the mailbox selction to delete.
*
* @param IMP_Ftree_Element $elt Element to delete.
*
* @return integer Mask of mailboxes to delete.
*/
abstract public function delete(IMP_Ftree_Element $elt);

/* Serializable methods. */

/**
Expand Down
9 changes: 9 additions & 0 deletions imp/lib/Ftree/Account/Imap.php
Expand Up @@ -172,4 +172,13 @@ public function getList($query = null)
return $out;
}

/**
*/
public function delete(IMP_Ftree_Element $elt)
{
return ($elt->inbox || $elt->namespace)
? 0
: self::DELETE_ELEMENT;
}

}
7 changes: 7 additions & 0 deletions imp/lib/Ftree/Account/Inboxonly.php
Expand Up @@ -34,4 +34,11 @@ public function getList($query = null)
);
}

/**
*/
public function delete(IMP_Ftree_Element $elt)
{
return 0;
}

}
13 changes: 13 additions & 0 deletions imp/lib/Ftree/Account/Remote.php
Expand Up @@ -79,4 +79,17 @@ public function getList($query = null)
return $out;
}

/**
*/
public function delete(IMP_Ftree_Element $elt)
{
if ($elt->remote_auth) {
return self::DELETE_ELEMENT_QUICK | self::DELETE_RECURSIVE;
}

return $elt->remote
? self::DELETE_ELEMENT_QUICK
: self::DELETE_ELEMENT;
}

}
7 changes: 7 additions & 0 deletions imp/lib/Ftree/Account/Vfolder.php
Expand Up @@ -60,4 +60,11 @@ public function getList($query = null)
return $out;
}

/**
*/
public function delete(IMP_Ftree_Element $elt)
{
return self::DELETE_ELEMENT_QUICK;
}

}

0 comments on commit 3c38bcd

Please sign in to comment.