3 namespace Friendica\Core\Console;
5 use Asika\SimpleConsole\CommandArgsException;
6 use Friendica\Core\StorageManager;
9 * @brief tool to manage storage backend and stored data from CLI
12 class Storage extends \Asika\SimpleConsole\Console
14 protected $helpOptions = ['h', 'help', '?'];
16 protected function getHelp()
19 console storage - manage storage backend and stored data
21 bin/console storage [-h|--help|-?] [-v]
24 bin/console storage list
25 List available storage backends
27 bin/console storage set <name>
28 Set current storage backend
29 name storage backend to use. see "list".
31 bin/console storage move [table]
32 Move stored data to current storage backend.
33 table one of "photo" or "attach". default to both
38 protected function doExecute()
40 if ($this->getOption('v')) {
41 $this->out('Executable: ' . $this->executable);
42 $this->out('Class: ' . __CLASS__);
43 $this->out('Arguments: ' . var_export($this->args, true));
44 $this->out('Options: ' . var_export($this->options, true));
47 if (count($this->args) == 0) {
48 $this->out($this->getHelp());
52 switch($this->args[0]) {
54 return $this->do_list();
57 return $this->do_set();
60 return $this->do_move();
64 $this->out(sprintf('Invalid action "%s"', $this->args[0]));
68 protected function do_list()
70 $rowfmt = ' %-3s | %-20s';
71 $current = StorageManager::getBackend();
72 $this->out(sprintf($rowfmt, 'Sel', 'Name'));
73 $this->out('-----------------------');
75 foreach(StorageManager::listBackends() as $name => $class) {
77 if ($current === $class) {
81 $this->out(sprintf($rowfmt, $issel , $name ));
84 if ($current === '') {
86 $this->out('This sistem is using legacy storage system');
88 if ($current !== '' && !$isregisterd) {
90 $this->out('The current storage class (' . $current . ') is not registered!');
95 protected function do_set()
97 if (count($this->args) !== 2) {
98 throw new CommandArgsException('Invalid arguments');
101 $name = $this->args[1];
102 $class = StorageManager::getByName($name);
105 $this->out($name . ' is not a registered backend.');
109 StorageManager::setBackend($class);
113 protected function do_move()
116 if (count($this->args) < 1 || count($this->args) > 2) {
117 throw new CommandArgsException('Invalid arguments');
119 if (count($this->args) == 2) {
120 $table = strtolower($this->args[1]);
121 if (!in_array($table, ['photo', 'attach'])) {
122 throw new CommandArgsException('Invalid table');
126 $current = StorageManager::getBackend();
127 $r = StorageManager::move($current);
128 $this->out(sprintf('Moved %d files', $r));