From 9aa96dabd0cb6f620855b8fbec7266f30fac3746 Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Fri, 31 Dec 2010 19:23:31 +0000 Subject: [PATCH] (mostly) make CLI "alias delete" working shells/alias.php: - execute still called help() instead of __handle() model/AliasHandler.php - delete(): - remove useless $address parameter from delete() (we have $this->username) - added error messages - fixed variable names for db_log Reason for the "mostly": The $this->is_mailbox_alias() in delete() always returns true and therefore forbids deletion. git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@930 a1433add-5e2c-0410-b055-b7f2511e0802 --- model/AliasHandler.php | 17 +++++++++-------- scripts/shells/alias.php | 6 +----- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/model/AliasHandler.php b/model/AliasHandler.php index 34a132de..a8940428 100644 --- a/model/AliasHandler.php +++ b/model/AliasHandler.php @@ -207,21 +207,22 @@ class AliasHandler { * @param alias address * @return true on success false on failure */ - public function delete($address){ -# TODO: use $this->username instead of $address function parameter? - if( ! $this->get($address) ) { - # TODO: error message "no such alias" + public function delete(){ + if( ! $this->get($this->username) ) { + $this->errormsg[] = 'An alias with that address does not exist.'; # TODO: make translatable return false; } - if (is_mailbox_alias($address) ) { - # TODO: error message "alias belongs to a mailbox and can't be deleted" + if ($this->is_mailbox_alias($this->username) ) { ### FIXME use different check, this one always returns true :-( + ### FIXME best solution might be to lookup the mailbox table (via UserHandler) + $this->errormsg[] = 'This alias belongs to a mailbox and can\'t be deleted.'; # TODO: make translatable return false; } - $result = db_delete('alias', 'address', $address); + $result = db_delete('alias', 'address', $this->username); if( $result == 1 ) { - db_log ($SESSID_USERNAME, $fDomain, 'delete_alias', $fDelete); + list(/*NULL*/,$domain) = explode('@', $this->username); + db_log ('CLI', $domain, 'delete_alias', $this->username); # TODO: replace hardcoded CLI return true; } } diff --git a/scripts/shells/alias.php b/scripts/shells/alias.php index fd4f9333..f6a5c112 100644 --- a/scripts/shells/alias.php +++ b/scripts/shells/alias.php @@ -189,10 +189,7 @@ class DeleteTask extends Shell { } if (!empty($this->args[0])) { - $this->help(); - // $output = $this->__handle($this->args[0]); - // $this->out($output); - + $this->__handle($this->args[0]); } } /** @@ -259,7 +256,6 @@ class DeleteTask extends Shell { } } -### PasswordTask was a rest of Copy Paste :D Deleted. Check it! class ViewTask extends Shell { /** * Execution method always used for tasks