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;
29 * Description of Console
31 class Console extends \Asika\SimpleConsole\Console
33 // Disables the default help handling
34 protected $helpOptions = [];
35 protected $customHelpOptions = ['h', 'help', '?'];
38 * @var Dice The DI library
42 protected function getHelp()
45 Usage: bin/console [--version] [-h|--help|-?] <command> [<args>] [-v]
48 addon Addon management
49 cache Manage node cache
50 config Edit site config
51 contact Contact management
52 createdoxygen Generate Doxygen headers
53 dbstructure Do database updates
54 docbloxerrorchecker Check the file tree for DocBlox errors
55 extract Generate translation string file for the Friendica project (deprecated)
56 globalcommunityblock Block remote profile from interacting with this node
57 globalcommunitysilence Silence a profile from the global community page
58 archivecontact Archive a contact when you know that it isn't existing anymore
59 help Show help about a command, e.g (bin/console help config)
60 autoinstall Starts automatic installation of friendica based on values from htconfig.php
62 maintenance Set maintenance mode for this node
63 movetoavatarcache Move cached avatars to the file based avatar cache
64 mergecontacts Merge duplicated contact entries
66 php2po Generate a messages.po file from a strings.php file
67 po2php Generate a strings.php file from a messages.po file
68 typo Checks for parse errors in Friendica files
69 postupdate Execute pending post update scripts (can last days)
70 relocate Update node base URL
71 serverblock Manage blocked servers
72 storage Manage storage backend
73 relay Manage ActivityPub relay servers
76 -h|--help|-? Show help information
77 -v Show more debug information.
82 protected $subConsoles = [
83 'addon' => Friendica\Console\Addon::class,
84 'archivecontact' => Friendica\Console\ArchiveContact::class,
85 'autoinstall' => Friendica\Console\AutomaticInstallation::class,
86 'cache' => Friendica\Console\Cache::class,
87 'config' => Friendica\Console\Config::class,
88 'contact' => Friendica\Console\Contact::class,
89 'createdoxygen' => Friendica\Console\CreateDoxygen::class,
90 'docbloxerrorchecker' => Friendica\Console\DocBloxErrorChecker::class,
91 'dbstructure' => Friendica\Console\DatabaseStructure::class,
92 'extract' => Friendica\Console\Extract::class,
93 'fixapdeliveryworkertaskparameters' => Friendica\Console\FixAPDeliveryWorkerTaskParameters::class,
94 'globalcommunityblock' => Friendica\Console\GlobalCommunityBlock::class,
95 'globalcommunitysilence' => Friendica\Console\GlobalCommunitySilence::class,
96 'lock' => Friendica\Console\Lock::class,
97 'maintenance' => Friendica\Console\Maintenance::class,
98 'mergecontacts' => Friendica\Console\MergeContacts::class,
99 'movetoavatarcache' => Friendica\Console\MoveToAvatarCache::class,
100 'php2po' => Friendica\Console\PhpToPo::class,
101 'postupdate' => Friendica\Console\PostUpdate::class,
102 'po2php' => Friendica\Console\PoToPhp::class,
103 'relay' => Friendica\Console\Relay::class,
104 'relocate' => Friendica\Console\Relocate::class,
105 'serverblock' => Friendica\Console\ServerBlock::class,
106 'storage' => Friendica\Console\Storage::class,
107 'test' => Friendica\Console\Test::class,
108 'typo' => Friendica\Console\Typo::class,
109 'user' => Friendica\Console\User::class,
113 * CliInput Friendica constructor.
115 * @param Dice $dice The DI library
118 public function __construct(Dice $dice, array $argv = null)
120 parent::__construct($argv);
125 protected function doExecute(): int
127 if ($this->getOption('v')) {
128 $this->out('Executable: ' . $this->executable);
129 $this->out('Arguments: ' . var_export($this->args, true));
130 $this->out('Options: ' . var_export($this->options, true));
136 if ($this->getOption('version')) {
137 $this->out('Friendica Console version ' . App::VERSION);
140 } elseif ((count($this->options) === 0 || $this->getOption($this->customHelpOptions) === true || $this->getOption($this->customHelpOptions) === 1) && count($this->args) === 0
142 } elseif (count($this->args) >= 2 && $this->getArgument(0) == 'help') {
143 $command = $this->getArgument(1);
145 array_shift($this->args);
146 array_shift($this->args);
147 } elseif (count($this->args) >= 1) {
148 $command = $this->getArgument(0);
149 array_shift($this->args);
152 if (is_null($command)) {
153 $this->out($this->getHelp());
157 $console = $this->getSubConsole($command);
160 $console->setOption($this->customHelpOptions, true);
163 return $console->execute();
166 private function getSubConsole($command)
168 if ($this->getOption('v')) {
169 $this->out('Command: ' . $command);
172 if (!isset($this->subConsoles[$command])) {
173 throw new \Asika\SimpleConsole\CommandArgsException('Command ' . $command . ' doesn\'t exist');
176 $subargs = $this->args;
177 array_unshift($subargs, $this->executable);
179 $className = $this->subConsoles[$command];
181 Friendica\DI::init($this->dice);
183 Renderer::registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine');
185 /** @var Console $subconsole */
186 $subconsole = $this->dice->create($className, [$subargs]);
188 foreach ($this->options as $name => $value) {
189 $subconsole->setOption($name, $value);