3 * @copyright Copyright (C) 2010-2022, the Friendica project
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 addon Addon management
48 cache Manage node cache
49 config Edit site config
50 contact Contact management
51 createdoxygen Generate Doxygen headers
52 dbstructure Do database updates
53 docbloxerrorchecker Check the file tree for DocBlox errors
54 extract Generate translation string file for the Friendica project (deprecated)
55 globalcommunityblock Block remote profile from interacting with this node
56 globalcommunitysilence Silence a profile from the global community page
57 archivecontact Archive a contact when you know that it isn't existing anymore
58 help Show help about a command, e.g (bin/console help config)
59 autoinstall Starts automatic installation of friendica based on values from htconfig.php
61 maintenance Set maintenance mode for this node
62 movetoavatarcache Move cached avatars to the file based avatar cache
64 php2po Generate a messages.po file from a strings.php file
65 po2php Generate a strings.php file from a messages.po file
66 typo Checks for parse errors in Friendica files
67 postupdate Execute pending post update scripts (can last days)
68 serverblock Manage blocked servers
69 storage Manage storage backend
70 relay Manage ActivityPub relay servers
73 -h|--help|-? Show help information
74 -v Show more debug information.
79 protected $subConsoles = [
80 'addon' => Friendica\Console\Addon::class,
81 'archivecontact' => Friendica\Console\ArchiveContact::class,
82 'autoinstall' => Friendica\Console\AutomaticInstallation::class,
83 'cache' => Friendica\Console\Cache::class,
84 'config' => Friendica\Console\Config::class,
85 'contact' => Friendica\Console\Contact::class,
86 'createdoxygen' => Friendica\Console\CreateDoxygen::class,
87 'docbloxerrorchecker' => Friendica\Console\DocBloxErrorChecker::class,
88 'dbstructure' => Friendica\Console\DatabaseStructure::class,
89 'extract' => Friendica\Console\Extract::class,
90 'fixapdeliveryworkertaskparameters' => Friendica\Console\FixAPDeliveryWorkerTaskParameters::class,
91 'globalcommunityblock' => Friendica\Console\GlobalCommunityBlock::class,
92 'globalcommunitysilence' => Friendica\Console\GlobalCommunitySilence::class,
93 'lock' => Friendica\Console\Lock::class,
94 'maintenance' => Friendica\Console\Maintenance::class,
95 'movetoavatarcache' => Friendica\Console\MoveToAvatarCache::class,
96 'php2po' => Friendica\Console\PhpToPo::class,
97 'postupdate' => Friendica\Console\PostUpdate::class,
98 'po2php' => Friendica\Console\PoToPhp::class,
99 'relay' => Friendica\Console\Relay::class,
100 'serverblock' => Friendica\Console\ServerBlock::class,
101 'storage' => Friendica\Console\Storage::class,
102 'test' => Friendica\Console\Test::class,
103 'typo' => Friendica\Console\Typo::class,
104 'user' => Friendica\Console\User::class,
108 * CliInput Friendica constructor.
110 * @param Dice $dice The DI library
113 public function __construct(Dice $dice, array $argv = null)
115 parent::__construct($argv);
120 protected function doExecute()
122 if ($this->getOption('v')) {
123 $this->out('Executable: ' . $this->executable);
124 $this->out('Arguments: ' . var_export($this->args, true));
125 $this->out('Options: ' . var_export($this->options, true));
131 if ($this->getOption('version')) {
132 $this->out('Friendica Console version ' . FRIENDICA_VERSION);
135 } elseif ((count($this->options) === 0 || $this->getOption($this->customHelpOptions) === true || $this->getOption($this->customHelpOptions) === 1) && count($this->args) === 0
137 } elseif (count($this->args) >= 2 && $this->getArgument(0) == 'help') {
138 $command = $this->getArgument(1);
140 array_shift($this->args);
141 array_shift($this->args);
142 } elseif (count($this->args) >= 1) {
143 $command = $this->getArgument(0);
144 array_shift($this->args);
147 if (is_null($command)) {
148 $this->out($this->getHelp());
152 $console = $this->getSubConsole($command);
155 $console->setOption($this->customHelpOptions, true);
158 return $console->execute();
161 private function getSubConsole($command)
163 if ($this->getOption('v')) {
164 $this->out('Command: ' . $command);
167 if (!isset($this->subConsoles[$command])) {
168 throw new \Asika\SimpleConsole\CommandArgsException('Command ' . $command . ' doesn\'t exist');
171 $subargs = $this->args;
172 array_unshift($subargs, $this->executable);
174 $className = $this->subConsoles[$command];
176 Friendica\DI::init($this->dice);
178 Renderer::registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine');
180 /** @var Console $subconsole */
181 $subconsole = $this->dice->create($className, [$subargs]);
183 foreach ($this->options as $name => $value) {
184 $subconsole->setOption($name, $value);