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-b7f2511e0802pull/2/head
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: */
|
Loading…
Reference in New Issue