mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-10-03 17:49:19 +02:00
Add --delete-all option to administration script for mass paste deletion
This commit is contained in:
parent
d220ba7c2b
commit
302921a811
1 changed files with 41 additions and 4 deletions
|
@ -72,6 +72,35 @@ class Administration
|
||||||
exit("paste $pasteId successfully deleted" . PHP_EOL);
|
exit("paste $pasteId successfully deleted" . PHP_EOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lists all stored paste IDs
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
private function _list_ids()
|
||||||
|
{
|
||||||
|
$ids = $this->_store->getAllPastes();
|
||||||
|
foreach ($ids as $pasteid) {
|
||||||
|
echo $pasteid, PHP_EOL;
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deletes all stored pastes (regardless of expiration)
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
private function _delete_all()
|
||||||
|
{
|
||||||
|
$ids = $this->_store->getAllPastes();
|
||||||
|
foreach ($ids as $pasteid) {
|
||||||
|
echo "Deleting paste ID: $pasteid" . PHP_EOL;
|
||||||
|
$this->_store->delete($pasteid);
|
||||||
|
}
|
||||||
|
exit("All pastes successfully deleted" . PHP_EOL);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removes empty directories, if current storage model uses Filesystem
|
* removes empty directories, if current storage model uses Filesystem
|
||||||
*
|
*
|
||||||
|
@ -124,7 +153,7 @@ class Administration
|
||||||
{
|
{
|
||||||
echo <<<'EOT'
|
echo <<<'EOT'
|
||||||
Usage:
|
Usage:
|
||||||
administration [--delete <paste id> | --empty-dirs | --help | --purge | --statistics]
|
administration [--delete <paste id> | --empty-dirs | --help | --purge | --statistics | --list-ids]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-d, --delete deletes the requested paste ID
|
-d, --delete deletes the requested paste ID
|
||||||
|
@ -133,6 +162,7 @@ Options:
|
||||||
-h, --help displays this help message
|
-h, --help displays this help message
|
||||||
-p, --purge purge all expired pastes
|
-p, --purge purge all expired pastes
|
||||||
-s, --statistics reads all stored pastes and comments and reports statistics
|
-s, --statistics reads all stored pastes and comments and reports statistics
|
||||||
|
-l, --list-ids lists all paste IDs
|
||||||
EOT, PHP_EOL;
|
EOT, PHP_EOL;
|
||||||
exit($code);
|
exit($code);
|
||||||
}
|
}
|
||||||
|
@ -177,7 +207,8 @@ EOT, PHP_EOL;
|
||||||
self::_help(2);
|
self::_help(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_opts = getopt('hd:eps', array('help', 'delete:', 'empty-dirs', 'purge', 'statistics'));
|
$this->_opts = getopt('hd:epsl', array('help', 'delete:', 'empty-dirs', 'purge', 'statistics', 'list-ids', 'delete-all'));
|
||||||
|
|
||||||
if (!$this->_opts) {
|
if (!$this->_opts) {
|
||||||
self::_error_echo('unsupported arguments given');
|
self::_error_echo('unsupported arguments given');
|
||||||
echo PHP_EOL;
|
echo PHP_EOL;
|
||||||
|
@ -308,6 +339,12 @@ EOT, PHP_EOL;
|
||||||
$class = 'PrivateBin\\Data\\' . $this->_conf->getKey('class', 'model');
|
$class = 'PrivateBin\\Data\\' . $this->_conf->getKey('class', 'model');
|
||||||
$this->_store = new $class($this->_conf->getSection('model_options'));
|
$this->_store = new $class($this->_conf->getSection('model_options'));
|
||||||
|
|
||||||
|
if ($this->_option('l', 'list-ids') !== null) {
|
||||||
|
$this->_list_ids();
|
||||||
|
}
|
||||||
|
if ($this->_option(null, 'delete-all') !== null) {
|
||||||
|
$this->_delete_all();
|
||||||
|
}
|
||||||
if (($pasteId = $this->_option('d', 'delete')) !== null) {
|
if (($pasteId = $this->_option('d', 'delete')) !== null) {
|
||||||
$this->_delete($pasteId);
|
$this->_delete($pasteId);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue