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]
22 bin/console storage list
23 bin/console storage set <name>
24 bin/console storage move
29 protected function doExecute()
31 $a = \Friendica\BaseObject::getApp();
33 if ($this->getOption('v')) {
34 $this->out('Executable: ' . $this->executable);
35 $this->out('Class: ' . __CLASS__);
36 $this->out('Arguments: ' . var_export($this->args, true));
37 $this->out('Options: ' . var_export($this->options, true));
40 if (count($this->args) == 0) {
41 $this->out($this->getHelp());
45 switch($this->args[0]) {
47 return $this->do_list();
50 return $this->do_set();
53 return $this->do_move();
57 $this->out(sprintf('Invalid action "%s"', $this->args[0]));
61 protected function do_list()
63 $rowfmt = ' %-3s | %-20s';
64 $current = StorageManager::getBackend();
65 $this->out(sprintf($rowfmt, 'Sel', 'Name'));
66 $this->out('-----------------------');
68 foreach(StorageManager::listBackends() as $name => $class) {
70 if ($current === $class) {
74 $this->out(sprintf($rowfmt, $issel , $name ));
77 if ($current === '') {
79 $this->out('This sistem is using legacy storage system');
81 if ($current !== '' && !$isregisterd) {
83 $this->out('The current storage class (' . $current . ') is not registered!');
88 protected function do_set()
90 if (count($this->args) !== 2) {
91 throw new CommandArgsException('Invalid arguments');
94 $name = $this->args[1];
95 $class = StorageManager::getByName($name);
98 $this->out($name . ' is not a registered backend.');
102 StorageManager::setBackend($class);
106 protected function do_move()
108 if (count($this->args) !== 1) {
109 throw new CommandArgsException('Invalid arguments');
112 $current = StorageManager::getBackend();
113 $r = StorageManager::move($current);
114 $this->out(sprintf("Moved %d files", $r));