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 $a = \Friendica\BaseObject::getApp();
42 if ($this->getOption('v')) {
43 $this->out('Executable: ' . $this->executable);
44 $this->out('Class: ' . __CLASS__);
45 $this->out('Arguments: ' . var_export($this->args, true));
46 $this->out('Options: ' . var_export($this->options, true));
49 if (count($this->args) == 0) {
50 $this->out($this->getHelp());
54 switch($this->args[0]) {
56 return $this->do_list();
59 return $this->do_set();
62 return $this->do_move();
66 $this->out(sprintf('Invalid action "%s"', $this->args[0]));
70 protected function do_list()
72 $rowfmt = ' %-3s | %-20s';
73 $current = StorageManager::getBackend();
74 $this->out(sprintf($rowfmt, 'Sel', 'Name'));
75 $this->out('-----------------------');
77 foreach(StorageManager::listBackends() as $name => $class) {
79 if ($current === $class) {
83 $this->out(sprintf($rowfmt, $issel , $name ));
86 if ($current === '') {
88 $this->out('This sistem is using legacy storage system');
90 if ($current !== '' && !$isregisterd) {
92 $this->out('The current storage class (' . $current . ') is not registered!');
97 protected function do_set()
99 if (count($this->args) !== 2) {
100 throw new CommandArgsException('Invalid arguments');
103 $name = $this->args[1];
104 $class = StorageManager::getByName($name);
107 $this->out($name . ' is not a registered backend.');
111 StorageManager::setBackend($class);
115 protected function do_move()
118 if (count($this->args) < 1 || count($this->args) > 2) {
119 throw new CommandArgsException('Invalid arguments');
121 if (count($this->args) == 2) {
122 $table = strtolower($this->args[1]);
123 if (!in_array($table, ['photo', 'attach'])) {
124 throw new CommandArgsException('Invalid table');
128 $current = StorageManager::getBackend();
129 $r = StorageManager::move($current);
130 $this->out(sprintf('Moved %d files', $r));