Przeglądaj źródła

Add --delete-all option to administration script for mass paste deletion

root 1 rok temu
rodzic
commit
302921a811
1 zmienionych plików z 41 dodań i 4 usunięć
  1. 41 4
      bin/administration

+ 41 - 4
bin/administration

@@ -72,6 +72,35 @@ class Administration
         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
      *
@@ -124,7 +153,7 @@ class Administration
     {
         echo <<<'EOT'
 Usage:
-  administration [--delete <paste id> | --empty-dirs | --help | --purge | --statistics]
+	administration [--delete <paste id> | --empty-dirs | --help | --purge | --statistics | --list-ids]
 
 Options:
   -d, --delete      deletes the requested paste ID
@@ -133,6 +162,7 @@ Options:
   -h, --help        displays this help message
   -p, --purge       purge all expired pastes
   -s, --statistics  reads all stored pastes and comments and reports statistics
+  -l, --list-ids    lists all paste IDs
 EOT, PHP_EOL;
         exit($code);
     }
@@ -177,7 +207,8 @@ EOT, PHP_EOL;
             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) {
             self::_error_echo('unsupported arguments given');
             echo PHP_EOL;
@@ -307,7 +338,13 @@ EOT, PHP_EOL;
 
         $class = 'PrivateBin\\Data\\' . $this->_conf->getKey('class', 'model');
         $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) {
             $this->_delete($pasteId);
         }
@@ -328,4 +365,4 @@ EOT, PHP_EOL;
     }
 }
 
-new Administration();
+new Administration();