SF.net SVN: postfixadmin:[1570] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2013-11-12 19:32:15
|
Revision: 1570 http://sourceforge.net/p/postfixadmin/code/1570 Author: christian_boltz Date: 2013-11-12 19:32:12 +0000 (Tue, 12 Nov 2013) Log Message: ----------- 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 Modified Paths: -------------- trunk/scripts/shells/alias.php trunk/scripts/shells/domain.php trunk/scripts/shells/mailbox.php trunk/scripts/shells/shell.php Added Paths: ----------- trunk/model/CliDelete.php Added: trunk/model/CliDelete.php =================================================================== --- trunk/model/CliDelete.php (rev 0) +++ trunk/model/CliDelete.php 2013-11-12 19:32:12 UTC (rev 1570) @@ -0,0 +1,85 @@ +<?php +/** + * class to handle 'delete' in Cli + */ + +class CliDelete extends Shell { + + /** + * Execution method always used for tasks + */ + protected function execute() { + + if (empty($this->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 <address> + + Deletes $module <address> in non-interactive mode. +"); + $this->_stop(); + } + +} + +/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ Property changes on: trunk/model/CliDelete.php ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/scripts/shells/alias.php =================================================================== --- trunk/scripts/shells/alias.php 2013-11-11 00:13:31 UTC (rev 1569) +++ trunk/scripts/shells/alias.php 2013-11-12 19:32:12 UTC (rev 1570) @@ -52,83 +52,6 @@ } #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 <arg1>"); - //$this->hr(); - //$this->out('Commands:'); - //$this->out("\n\tdelete\n\t\tdeletes mailbox in interactive mode."); - //$this->out("\n\tdelete <address>\n\t\tdeletes mailbox with address <address>"); - //$this->out(""); - $this->_stop(); - } - -} class ViewTask extends Shell { /** * Execution method always used for tasks Modified: trunk/scripts/shells/domain.php =================================================================== --- trunk/scripts/shells/domain.php 2013-11-11 00:13:31 UTC (rev 1569) +++ trunk/scripts/shells/domain.php 2013-11-12 19:32:12 UTC (rev 1570) @@ -63,78 +63,6 @@ } -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 <arg1>"); - $this->hr(); - //$this->out('Commands:'); - //$this->out("\n\tdelete\n\t\tdeletes mailbox in interactive mode."); - //$this->out("\n\tdelete <address>\n\t\tdeletes mailbox with address <address>"); - //$this->out(""); - $this->_stop(); - } - -} -##Deleted PasswordTask because its silly in domain shell class ViewTask extends Shell { /** * Execution method always used for tasks Modified: trunk/scripts/shells/mailbox.php =================================================================== --- trunk/scripts/shells/mailbox.php 2013-11-11 00:13:31 UTC (rev 1569) +++ trunk/scripts/shells/mailbox.php 2013-11-12 19:32:12 UTC (rev 1570) @@ -51,84 +51,6 @@ } -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 <arg1>"); - $this->hr(); - $this->out('Commands:'); - $this->out("\n\tdelete\n\t\tdeletes mailbox in interactive mode."); - $this->out("\n\tdelete <address>\n\t\tdeletes mailbox with address <address>"); - $this->out(""); - $this->_stop(); - } - -} class PasswordTask extends Shell { /** * Execution method always used for tasks Modified: trunk/scripts/shells/shell.php =================================================================== --- trunk/scripts/shells/shell.php 2013-11-11 00:13:31 UTC (rev 1569) +++ trunk/scripts/shells/shell.php 2013-11-12 19:32:12 UTC (rev 1570) @@ -209,8 +209,10 @@ 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 @@ # } # } - $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 @@ } 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(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |