From 0a71a236c28110976edef4655c224fea974f7aec Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Tue, 12 Nov 2013 19:32:12 +0000 Subject: [PATCH] model/CliDelete.php - new file, handles deleting something with the CLI (based on DeleteTask in scripts/shells/*.php) scripts/shells/*.php - remove DeleteTask, obsoleted by model/CliDelete.php scripts/shells/shell.php: - use CliDelete instead of DeleteTask git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1570 a1433add-5e2c-0410-b055-b7f2511e0802 --- model/CliDelete.php | 85 ++++++++++++++++++++++++++++++++++++++ scripts/shells/alias.php | 77 ---------------------------------- scripts/shells/domain.php | 72 -------------------------------- scripts/shells/mailbox.php | 78 ---------------------------------- scripts/shells/shell.php | 19 +++++---- 5 files changed, 95 insertions(+), 236 deletions(-) create mode 100644 model/CliDelete.php diff --git a/model/CliDelete.php b/model/CliDelete.php new file mode 100644 index 00000000..8537ba5b --- /dev/null +++ b/model/CliDelete.php @@ -0,0 +1,85 @@ +args)) { + $this->__interactive(); + } + + if (!empty($this->args[0])) { + $this->__handle($this->args[0]); + } + } + + /** + * Interactive mode + */ + protected function __interactive() { + $module = preg_replace('/Handler$/', '', $this->handler_to_use); + $module = strtolower($module); + + $question = "Which $module do you want to delete?"; + $address = $this->in($question); + + $question = "Do you really want to delete '$address'?"; + $create = $this->in($question, array('y','n')); + + if ($create == 'y') $this->__handle($address); + } + + /** + * actually delete something + * + * @param string address to delete + */ + protected function __handle($address) { + $handler = new $this->handler_to_use($this->new); + + if (!$handler->init($address)) { + $this->err($handler->errormsg); + return; + } + + if (!$handler->delete()) { + $this->err($handler->errormsg); + } else { + $this->out($handler->infomsg); + } + } + + /** + * Display help contents + * + * @access public + */ + protected function help() { + $module = preg_replace('/Handler$/', '', $this->handler_to_use); + $module = strtolower($module); + + $this->out( +"Usage: + + postfixadmin-cli $module delete + + Deletes $module in interactive mode. + +- or - + + postfixadmin-cli $module delete
+ + Deletes $module
in non-interactive mode. +"); + $this->_stop(); + } + +} + +/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ diff --git a/scripts/shells/alias.php b/scripts/shells/alias.php index 6388b2a2..e47c4f1e 100644 --- a/scripts/shells/alias.php +++ b/scripts/shells/alias.php @@ -52,83 +52,6 @@ class PostfixAdminAlias extends Shell { } #TODO: implement -class DeleteTask extends Shell { -/** - * Execution method always used for tasks - * - * @access public - */ - function execute() { - - if (empty($this->args)) { -# $this->help(); - $this->__interactive(); - } - - if (!empty($this->args[0])) { - $this->__handle($this->args[0]); - } - } -/** - * Interactive - * - * @access private - */ - function __interactive() { - $question[] = "Which Address do you want to delete?"; - - $address = $this->in(join("\n", $question)); - - - $question = "Do you really want to delete the alias '$address'?"; - - $create = $this->in($question, array('y','n')); - - $create == 'y' ? $create = true : $create = false; - - if ($create) - $this->__handle($address); - - - - } - /** - * Interactive - * - * @access private - */ - function __handle($address) { - - $handler = new AliasHandler(); - $handler->init($address); - $status = $handler->delete(); - if ($status == true) { - $this->out("Alias '$address' was deleted."); - - } else { - $this->err($handler->errormsg); - } - return; - - } -/** - * Displays help contents - * - * @access public - */ - function help() { - $this->hr(); - $this->out("NOT implemented yet."); - //$this->out("Usage: postfixadmin-cli user model "); - //$this->hr(); - //$this->out('Commands:'); - //$this->out("\n\tdelete\n\t\tdeletes mailbox in interactive mode."); - //$this->out("\n\tdelete
\n\t\tdeletes mailbox with address
"); - //$this->out(""); - $this->_stop(); - } - -} class ViewTask extends Shell { /** * Execution method always used for tasks diff --git a/scripts/shells/domain.php b/scripts/shells/domain.php index f54d89ee..793d1cc9 100644 --- a/scripts/shells/domain.php +++ b/scripts/shells/domain.php @@ -63,78 +63,6 @@ class PostfixAdminDomain extends Shell { } -class DeleteTask extends Shell { -/** - * Execution method always used for tasks - * - * @access public - */ - function execute() { - - if (empty($this->args)) { - $this->__interactive(); - } - - if (!empty($this->args[0])) { - $output = $this->__handle($this->args[0]); - $this->out($output); - } - } -/** - * Interactive - * - * @access private - */ - function __interactive() { - $question = "Which domain do you want to delete?"; - $address = $this->in($question); - - $question = "Do you really want to delete domain '$address'?"; - $create = $this->in($question, array('y','n')); - - if ($create == 'y') $this->__handle($address); - } - /** - * Interactive - * - * @access private - */ - function __handle($address) { - $handler = new DomainHandler(); - if (!$handler->init($address)) { - $this->err($handler->errormsg); - return; - } - - $status = $handler->delete(); - if ($status == true) { - $this->out("Domain '$address' was deleted."); - - } else { - $this->err($handler->errormsg); - } - return; - - } -/** - * Displays help contents - * - * @access public - */ - function help() { - $this->out("NOT Implemented yet."); - $this->hr(); - $this->out("Usage: postfixadmin-cli user model "); - $this->hr(); - //$this->out('Commands:'); - //$this->out("\n\tdelete\n\t\tdeletes mailbox in interactive mode."); - //$this->out("\n\tdelete
\n\t\tdeletes mailbox with address
"); - //$this->out(""); - $this->_stop(); - } - -} -##Deleted PasswordTask because its silly in domain shell class ViewTask extends Shell { /** * Execution method always used for tasks diff --git a/scripts/shells/mailbox.php b/scripts/shells/mailbox.php index ad9082c8..455bcd01 100644 --- a/scripts/shells/mailbox.php +++ b/scripts/shells/mailbox.php @@ -51,84 +51,6 @@ class PostfixAdminMailbox extends Shell { } -class DeleteTask extends Shell { -/** - * Execution method always used for tasks - * - * @access public - */ - function execute() { - - if (empty($this->args)) { - $this->__interactive(); - } - - if (!empty($this->args[0])) { - $output = $this->__handle($this->args[0]); - $this->out($output); - - } - } -/** - * Interactive - * - * @access private - */ - function __interactive() { - $question[] = "Which Address do you want to delete?"; - - $address = $this->in(join("\n", $question)); - - - $question = "Do you really want to delete mailbox of '$address'?"; - - $create = $this->in($question, array('y','n')); - - $create == 'y' ? $create = true : $create = false; - - if ($create) - $this->__handle($address); - - } - /** - * Interactive - * - * @access private - */ - function __handle($address) { - - $handler = new MailboxHandler(); - if (!$handler->init($address)) { - $this->error("Error:", join("\n", $handler->errormsg)); - } - - $status = $handler->delete(); - if ( ! $status ) { - $this->err($handler->errormsg); - - } else { - $this->out("Mailbox of '$address' was deleted."); - } - return; - - } -/** - * Displays help contents - * - * @access public - */ - function help() { - $this->hr(); - $this->out("Usage: postfixadmin-cli mailbox model "); - $this->hr(); - $this->out('Commands:'); - $this->out("\n\tdelete\n\t\tdeletes mailbox in interactive mode."); - $this->out("\n\tdelete
\n\t\tdeletes mailbox with address
"); - $this->out(""); - $this->_stop(); - } - -} class PasswordTask extends Shell { /** * Execution method always used for tasks diff --git a/scripts/shells/shell.php b/scripts/shells/shell.php index 28f1bbf0..8bbfc714 100644 --- a/scripts/shells/shell.php +++ b/scripts/shells/shell.php @@ -209,8 +209,10 @@ if ( empty($this->params['q'] ) ) { if ($taskName == 'Add' || $taskName == 'Update') { $taskClass = 'CliEdit'; + } elseif ($taskName == 'Delete') { + $taskClass = 'CliDelete'; + } - } # elseif (!class_exists($taskClass)) { # foreach ($this->Dispatch->shellPaths as $path) { # $taskPath = $path . 'tasks' . DS . $task.'.php'; @@ -221,12 +223,8 @@ if ( empty($this->params['q'] ) ) { # } # } - $this->taskNames[] = $taskName; -# if (!PHP5) { -# $this->{$taskName} = new $taskClass($this->Dispatch); -# } else { - $this->{$taskName} = new $taskClass($this->Dispatch); -# } + $this->taskNames[] = $taskName; + $this->{$taskName} = new $taskClass($this->Dispatch); if ($taskName == 'Add') { $this->{$taskName}->handler_to_use = ucfirst($this->shell) . 'Handler'; @@ -234,8 +232,11 @@ if ( empty($this->params['q'] ) ) { } elseif ($taskName == 'Update') { $this->{$taskName}->handler_to_use = ucfirst($this->shell) . 'Handler'; $this->{$taskName}->new = 0; - } - + } elseif ($taskName == 'Delete') { + $this->{$taskName}->handler_to_use = ucfirst($this->shell) . 'Handler'; + $this->{$taskName}->new = 0; + } + if (!isset($this->{$taskName})) { $this->err("Task '".$taskName."' could not be loaded"); $this->_stop();