]> git.mxchange.org Git - friendica.git/blob - src/Core/Console.php
Add 'storage' console command
[friendica.git] / src / Core / Console.php
1 <?php
2
3 namespace Friendica\Core;
4
5 /**
6  * Description of Console
7  *
8  * @author Hypolite Petovan <hypolite@mrpetovan.com>
9  */
10 class Console extends \Asika\SimpleConsole\Console
11 {
12         // Disables the default help handling
13         protected $helpOptions = [];
14         protected $customHelpOptions = ['h', 'help', '?'];
15
16         protected $subConsoles = [
17                 'cache'                  => __NAMESPACE__ . '\Console\Cache',
18                 'config'                 => __NAMESPACE__ . '\Console\Config',
19                 'createdoxygen'          => __NAMESPACE__ . '\Console\CreateDoxygen',
20                 'docbloxerrorchecker'    => __NAMESPACE__ . '\Console\DocBloxErrorChecker',
21                 'dbstructure'            => __NAMESPACE__ . '\Console\DatabaseStructure',
22                 'extract'                => __NAMESPACE__ . '\Console\Extract',
23                 'globalcommunityblock'   => __NAMESPACE__ . '\Console\GlobalCommunityBlock',
24                 'globalcommunitysilence' => __NAMESPACE__ . '\Console\GlobalCommunitySilence',
25                 'archivecontact'         => __NAMESPACE__ . '\Console\ArchiveContact',
26                 'autoinstall'            => __NAMESPACE__ . '\Console\AutomaticInstallation',
27                 'maintenance'            => __NAMESPACE__ . '\Console\Maintenance',
28                 'newpassword'            => __NAMESPACE__ . '\Console\NewPassword',
29                 'php2po'                 => __NAMESPACE__ . '\Console\PhpToPo',
30                 'po2php'                 => __NAMESPACE__ . '\Console\PoToPhp',
31                 'typo'                   => __NAMESPACE__ . '\Console\Typo',
32                 'postupdate'             => __NAMESPACE__ . '\Console\PostUpdate',
33                 'storage'                => __NAMESPACE__ . '\Console\Storage',
34         ];
35
36         protected function getHelp()
37         {
38                 $help = <<<HELP
39 Usage: bin/console [--version] [-h|--help|-?] <command> [<args>] [-v]
40
41 Commands:
42         cache                  Manage node cache
43         config                 Edit site config
44         createdoxygen          Generate Doxygen headers
45         dbstructure            Do database updates
46         docbloxerrorchecker    Check the file tree for DocBlox errors
47         extract                Generate translation string file for the Friendica project (deprecated)
48         globalcommunityblock   Block remote profile from interacting with this node
49         globalcommunitysilence Silence remote profile from global community page
50         archivecontact         Archive a contact when you know that it isn't existing anymore
51         help                   Show help about a command, e.g (bin/console help config)
52         autoinstall            Starts automatic installation of friendica based on values from htconfig.php
53         maintenance            Set maintenance mode for this node
54         newpassword            Set a new password for a given user
55         php2po                 Generate a messages.po file from a strings.php file
56         po2php                 Generate a strings.php file from a messages.po file
57         typo                   Checks for parse errors in Friendica files
58         postupdate             Execute pending post update scripts (can last days)
59         storage                Manage storage backend
60
61 Options:
62         -h|--help|-? Show help information
63         -v           Show more debug information.
64 HELP;
65                 return $help;
66         }
67
68         protected function doExecute()
69         {
70                 if ($this->getOption('v')) {
71                         $this->out('Executable: ' . $this->executable);
72                         $this->out('Arguments: ' . var_export($this->args, true));
73                         $this->out('Options: ' . var_export($this->options, true));
74                 }
75
76                 $showHelp = false;
77                 $subHelp = false;
78                 $command = null;
79
80                 if ($this->getOption('version')) {
81                         $this->out('Friendica Console version ' . FRIENDICA_VERSION);
82
83                         return 0;
84                 } elseif ((count($this->options) === 0 || $this->getOption($this->customHelpOptions) === true || $this->getOption($this->customHelpOptions) === 1) && count($this->args) === 0
85                 ) {
86                         $showHelp = true;
87                 } elseif (count($this->args) >= 2 && $this->getArgument(0) == 'help') {
88                         $command = $this->getArgument(1);
89                         $subHelp = true;
90                         array_shift($this->args);
91                         array_shift($this->args);
92                 } elseif (count($this->args) >= 1) {
93                         $command = $this->getArgument(0);
94                         array_shift($this->args);
95                 }
96
97                 if (is_null($command)) {
98                         $this->out($this->getHelp());
99                         return 0;
100                 }
101
102                 $console = $this->getSubConsole($command);
103
104                 if ($subHelp) {
105                         $console->setOption($this->customHelpOptions, true);
106                 }
107
108                 return $console->execute();
109         }
110
111         private function getSubConsole($command)
112         {
113                 if ($this->getOption('v')) {
114                         $this->out('Command: ' . $command);
115                 }
116
117                 if (!isset($this->subConsoles[$command])) {
118                         throw new \Asika\SimpleConsole\CommandArgsException('Command ' . $command . ' doesn\'t exist');
119                 }
120
121                 $subargs = $this->args;
122                 array_unshift($subargs, $this->executable);
123
124                 $className = $this->subConsoles[$command];
125
126                 $subconsole = new $className($subargs);
127
128                 foreach ($this->options as $name => $value) {
129                         $subconsole->setOption($name, $value);
130                 }
131
132                 return $subconsole;
133         }
134
135 }