]> git.mxchange.org Git - friendica.git/blob - src/Core/Console.php
Fix undefined offset notices in Protocol\Email
[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         ];
34
35         protected function getHelp()
36         {
37                 $help = <<<HELP
38 Usage: bin/console [--version] [-h|--help|-?] <command> [<args>] [-v]
39
40 Commands:
41         cache                  Manage node cache
42         config                 Edit site config
43         createdoxygen          Generate Doxygen headers
44         dbstructure            Do database updates
45         docbloxerrorchecker    Check the file tree for DocBlox errors
46         extract                Generate translation string file for the Friendica project (deprecated)
47         globalcommunityblock   Block remote profile from interacting with this node
48         globalcommunitysilence Silence remote profile from global community page
49         archivecontact         Archive a contact when you know that it isn't existing anymore
50         help                   Show help about a command, e.g (bin/console help config)
51         autoinstall            Starts automatic installation of friendica based on values from htconfig.php
52         maintenance            Set maintenance mode for this node
53         newpassword            Set a new password for a given user
54         php2po                 Generate a messages.po file from a strings.php file
55         po2php                 Generate a strings.php file from a messages.po file
56         typo                   Checks for parse errors in Friendica files
57         postupdate             Execute pending post update scripts (can last days)
58
59 Options:
60         -h|--help|-? Show help information
61         -v           Show more debug information.
62 HELP;
63                 return $help;
64         }
65
66         protected function doExecute()
67         {
68                 if ($this->getOption('v')) {
69                         $this->out('Executable: ' . $this->executable);
70                         $this->out('Arguments: ' . var_export($this->args, true));
71                         $this->out('Options: ' . var_export($this->options, true));
72                 }
73
74                 $showHelp = false;
75                 $subHelp = false;
76                 $command = null;
77
78                 if ($this->getOption('version')) {
79                         $this->out('Friendica Console version ' . FRIENDICA_VERSION);
80
81                         return 0;
82                 } elseif ((count($this->options) === 0 || $this->getOption($this->customHelpOptions) === true || $this->getOption($this->customHelpOptions) === 1) && count($this->args) === 0
83                 ) {
84                         $showHelp = true;
85                 } elseif (count($this->args) >= 2 && $this->getArgument(0) == 'help') {
86                         $command = $this->getArgument(1);
87                         $subHelp = true;
88                         array_shift($this->args);
89                         array_shift($this->args);
90                 } elseif (count($this->args) >= 1) {
91                         $command = $this->getArgument(0);
92                         array_shift($this->args);
93                 }
94
95                 if (is_null($command)) {
96                         $this->out($this->getHelp());
97                         return 0;
98                 }
99
100                 $console = $this->getSubConsole($command);
101
102                 if ($subHelp) {
103                         $console->setOption($this->customHelpOptions, true);
104                 }
105
106                 return $console->execute();
107         }
108
109         private function getSubConsole($command)
110         {
111                 if ($this->getOption('v')) {
112                         $this->out('Command: ' . $command);
113                 }
114
115                 if (!isset($this->subConsoles[$command])) {
116                         throw new \Asika\SimpleConsole\CommandArgsException('Command ' . $command . ' doesn\'t exist');
117                 }
118
119                 $subargs = $this->args;
120                 array_unshift($subargs, $this->executable);
121
122                 $className = $this->subConsoles[$command];
123
124                 $subconsole = new $className($subargs);
125
126                 foreach ($this->options as $name => $value) {
127                         $subconsole->setOption($name, $value);
128                 }
129
130                 return $subconsole;
131         }
132
133 }