3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Core;
28 * Description of Console
30 class Console extends \Asika\SimpleConsole\Console
32 // Disables the default help handling
33 protected $helpOptions = [];
34 protected $customHelpOptions = ['h', 'help', '?'];
37 * @var Dice The DI library
41 protected function getHelp()
44 Usage: bin/console [--version] [-h|--help|-?] <command> [<args>] [-v]
47 cache Manage node cache
48 config Edit site config
49 createdoxygen Generate Doxygen headers
50 dbstructure Do database updates
51 docbloxerrorchecker Check the file tree for DocBlox errors
52 extract Generate translation string file for the Friendica project (deprecated)
53 globalcommunityblock Block remote profile from interacting with this node
54 globalcommunitysilence Silence remote profile from global community page
55 archivecontact Archive a contact when you know that it isn't existing anymore
56 help Show help about a command, e.g (bin/console help config)
57 autoinstall Starts automatic installation of friendica based on values from htconfig.php
59 maintenance Set maintenance mode for this node
61 php2po Generate a messages.po file from a strings.php file
62 po2php Generate a strings.php file from a messages.po file
63 typo Checks for parse errors in Friendica files
64 postupdate Execute pending post update scripts (can last days)
65 serverblock Manage blocked servers
66 storage Manage storage backend
69 -h|--help|-? Show help information
70 -v Show more debug information.
75 protected $subConsoles = [
76 'cache' => Friendica\Console\Cache::class,
77 'config' => Friendica\Console\Config::class,
78 'createdoxygen' => Friendica\Console\CreateDoxygen::class,
79 'docbloxerrorchecker' => Friendica\Console\DocBloxErrorChecker::class,
80 'dbstructure' => Friendica\Console\DatabaseStructure::class,
81 'extract' => Friendica\Console\Extract::class,
82 'globalcommunityblock' => Friendica\Console\GlobalCommunityBlock::class,
83 'globalcommunitysilence' => Friendica\Console\GlobalCommunitySilence::class,
84 'archivecontact' => Friendica\Console\ArchiveContact::class,
85 'autoinstall' => Friendica\Console\AutomaticInstallation::class,
86 'lock' => Friendica\Console\Lock::class,
87 'maintenance' => Friendica\Console\Maintenance::class,
88 'user' => Friendica\Console\User::class,
89 'php2po' => Friendica\Console\PhpToPo::class,
90 'po2php' => Friendica\Console\PoToPhp::class,
91 'typo' => Friendica\Console\Typo::class,
92 'postupdate' => Friendica\Console\PostUpdate::class,
93 'serverblock' => Friendica\Console\ServerBlock::class,
94 'storage' => Friendica\Console\Storage::class,
98 * CliInput Friendica constructor.
100 * @param Dice $dice The DI library
103 public function __construct(Dice $dice, array $argv = null)
105 parent::__construct($argv);
110 protected function doExecute()
112 if ($this->getOption('v')) {
113 $this->out('Executable: ' . $this->executable);
114 $this->out('Arguments: ' . var_export($this->args, true));
115 $this->out('Options: ' . var_export($this->options, true));
121 if ($this->getOption('version')) {
122 $this->out('Friendica Console version ' . FRIENDICA_VERSION);
125 } elseif ((count($this->options) === 0 || $this->getOption($this->customHelpOptions) === true || $this->getOption($this->customHelpOptions) === 1) && count($this->args) === 0
127 } elseif (count($this->args) >= 2 && $this->getArgument(0) == 'help') {
128 $command = $this->getArgument(1);
130 array_shift($this->args);
131 array_shift($this->args);
132 } elseif (count($this->args) >= 1) {
133 $command = $this->getArgument(0);
134 array_shift($this->args);
137 if (is_null($command)) {
138 $this->out($this->getHelp());
142 $console = $this->getSubConsole($command);
145 $console->setOption($this->customHelpOptions, true);
148 return $console->execute();
151 private function getSubConsole($command)
153 if ($this->getOption('v')) {
154 $this->out('Command: ' . $command);
157 if (!isset($this->subConsoles[$command])) {
158 throw new \Asika\SimpleConsole\CommandArgsException('Command ' . $command . ' doesn\'t exist');
161 $subargs = $this->args;
162 array_unshift($subargs, $this->executable);
164 $className = $this->subConsoles[$command];
166 Friendica\DI::init($this->dice);
168 /** @var Console $subconsole */
169 $subconsole = $this->dice->create($className, [$subargs]);
171 foreach ($this->options as $name => $value) {
172 $subconsole->setOption($name, $value);