User friendlieness in scripts/delete_notice.php

This commit is contained in:
Mikael Nordfeldth 2016-02-26 00:06:04 +01:00
parent 2669c51265
commit 2730510393
1 changed files with 14 additions and 17 deletions

View File

@ -20,8 +20,8 @@
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
$shortoptions = 'i::n::u::y'; $shortoptions = 'i::u::y';
$longoptions = array('id=', 'nickname=', 'uri=', 'yes'); $longoptions = array('id=', 'uri=', 'yes');
$helptext = <<<END_OF_HELP $helptext = <<<END_OF_HELP
delete_notice.php [options] delete_notice.php [options]
@ -35,22 +35,19 @@ END_OF_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc'; require_once INSTALLDIR.'/scripts/commandline.inc';
if (have_option('i', 'id')) { try {
$id = get_option_value('i', 'id'); if (have_option('i', 'id')) {
$notice = Notice::getByID($id); $id = get_option_value('i', 'id');
if (!$notice instanceof Notice) { $notice = Notice::getByID($id);
print "Can't find notice with ID $id\n"; } else if (have_option('u', 'uri')) {
exit(1); $uri = get_option_value('u', 'uri');
$notice = Notice::getByUri($uri);
} else {
print $helptext;
throw new ClientException('You must provide either an ID or a URI.');
} }
} else if (have_option('u', 'uri')) { } catch (Exception $e) {
$uri = get_option_value('u', 'uri'); print "ERROR: {$e->getMessage()}\n";
$notice = Notice::getKV('uri', $uri);
if (!$notice instanceof Notice) {
print "Can't find notice with URI '$uri'\n";
exit(1);
}
} else {
print "You must provide either an ID, a URI or a nickname.\n";
exit(1); exit(1);
} }