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