0
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2024-09-19 19:22:14 +02:00
postfixadmin/model/CliDelete.php

94 lines
1.9 KiB
PHP
Raw Permalink Normal View History

<?php
2022-06-28 14:46:11 +02:00
2018-01-26 15:45:57 +01:00
# $Id$
/**
* class to handle 'delete' in Cli
*/
2021-03-22 10:28:28 +01:00
class CliDelete extends Shell
{
/**
* Execution method always used for tasks
*/
2021-04-13 22:19:16 +02:00
public function execute()
{
if (empty($this->args)) {
return $this->__interactive();
}
if (!empty($this->args[0])) {
return $this->__handle($this->args[0]);
}
}
/**
* Interactive mode
*/
2021-04-13 22:19:16 +02:00
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'));
2018-01-26 15:45:57 +01:00
if ($create == 'y') {
return $this->__handle($address);
2018-01-26 15:45:57 +01:00
}
}
/**
* actually delete something
*
* @param string address to delete
*/
2021-04-13 22:19:16 +02:00
protected function __handle($address)
{
$handler = new $this->handler_to_use($this->new);
if (!$handler->init($address)) {
$this->err($handler->errormsg);
return 1;
2018-01-26 15:45:57 +01:00
}
if (!$handler->delete()) {
$this->err($handler->errormsg);
return 1;
2019-09-15 12:42:21 +02:00
}
$this->out($handler->infomsg);
return 0;
}
/**
* Display help contents
*
* @access public
*/
2021-04-13 22:19:16 +02:00
public function help()
{
$module = preg_replace('/Handler$/', '', $this->handler_to_use);
$module = strtolower($module);
$this->out(
2022-07-15 11:29:55 +02:00
"Usage:
postfixadmin-cli $module delete
Deletes $module in interactive mode.
- or -
postfixadmin-cli $module delete <address>
Deletes $module <address> in non-interactive mode.
2018-01-26 15:45:57 +01:00
"
);
$this->_stop(1);
}
}
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */