]> git.mxchange.org Git - friendica.git/blob - src/Core/Console.php
Improved protocol storing
[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 function getHelp()
17         {
18                 $help = <<<HELP
19 Usage: bin/console [--version] [-h|--help|-?] <command> [<args>] [-v]
20
21 Commands:
22         cache                  Manage node cache
23         config                 Edit site config
24         createdoxygen          Generate Doxygen headers
25         dbstructure            Do database updates
26         docbloxerrorchecker    Check the file tree for DocBlox errors
27         extract                Generate translation string file for the Friendica project (deprecated)
28         globalcommunityblock   Block remote profile from interacting with this node
29         globalcommunitysilence Silence remote profile from global community page
30         archivecontact         Archive a contact when you know that it isn't existing anymore
31         help                   Show help about a command, e.g (bin/console help config)
32         autoinstall            Starts automatic installation of friendica based on values from htconfig.php
33         maintenance            Set maintenance mode for this node
34         newpassword            Set a new password for a given user
35         php2po                 Generate a messages.po file from a strings.php file
36         po2php                 Generate a strings.php file from a messages.po file
37         typo                   Checks for parse errors in Friendica files
38         postupdate             Execute pending post update scripts (can last days)
39         serverblock            Manage blocked servers
40         storage                Manage storage backend
41
42 Options:
43         -h|--help|-? Show help information
44         -v           Show more debug information.
45 HELP;
46                 return $help;
47         }
48
49         protected $subConsoles = [
50                 'cache'                  => __NAMESPACE__ . '\Console\Cache',
51                 'config'                 => __NAMESPACE__ . '\Console\Config',
52                 'createdoxygen'          => __NAMESPACE__ . '\Console\CreateDoxygen',
53                 'docbloxerrorchecker'    => __NAMESPACE__ . '\Console\DocBloxErrorChecker',
54                 'dbstructure'            => __NAMESPACE__ . '\Console\DatabaseStructure',
55                 'extract'                => __NAMESPACE__ . '\Console\Extract',
56                 'globalcommunityblock'   => __NAMESPACE__ . '\Console\GlobalCommunityBlock',
57                 'globalcommunitysilence' => __NAMESPACE__ . '\Console\GlobalCommunitySilence',
58                 'archivecontact'         => __NAMESPACE__ . '\Console\ArchiveContact',
59                 'autoinstall'            => __NAMESPACE__ . '\Console\AutomaticInstallation',
60                 'maintenance'            => __NAMESPACE__ . '\Console\Maintenance',
61                 'newpassword'            => __NAMESPACE__ . '\Console\NewPassword',
62                 'php2po'                 => __NAMESPACE__ . '\Console\PhpToPo',
63                 'po2php'                 => __NAMESPACE__ . '\Console\PoToPhp',
64                 'typo'                   => __NAMESPACE__ . '\Console\Typo',
65                 'postupdate'             => __NAMESPACE__ . '\Console\PostUpdate',
66                 'serverblock'            => __NAMESPACE__ . '\Console\ServerBlock',
67                 'storage'                => __NAMESPACE__ . '\Console\Storage',
68         ];
69
70         protected function doExecute()
71         {
72                 if ($this->getOption('v')) {
73                         $this->out('Executable: ' . $this->executable);
74                         $this->out('Arguments: ' . var_export($this->args, true));
75                         $this->out('Options: ' . var_export($this->options, true));
76                 }
77
78                 $subHelp = false;
79                 $command = null;
80
81                 if ($this->getOption('version')) {
82                         $this->out('Friendica Console version ' . FRIENDICA_VERSION);
83
84                         return 0;
85                 } elseif ((count($this->options) === 0 || $this->getOption($this->customHelpOptions) === true || $this->getOption($this->customHelpOptions) === 1) && count($this->args) === 0
86                 ) {
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                 /** @var Console $subconsole */
127                 $subconsole = new $className($subargs);
128
129                 foreach ($this->options as $name => $value) {
130                         $subconsole->setOption($name, $value);
131                 }
132
133                 return $subconsole;
134         }
135
136 }