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
pull/2/head
Christian Boltz 11 years ago
parent b871b47709
commit 0a71a236c2

@ -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: */

@ -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 <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

@ -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 <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

@ -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 <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

@ -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();

Loading…
Cancel
Save