3 namespace Friendica\Core;
9 * Description of Console
11 * @author Hypolite Petovan <hypolite@mrpetovan.com>
13 class Console extends \Asika\SimpleConsole\Console
15 // Disables the default help handling
16 protected $helpOptions = [];
17 protected $customHelpOptions = ['h', 'help', '?'];
20 * @var Dice The DI library
24 protected function getHelp()
27 Usage: bin/console [--version] [-h|--help|-?] <command> [<args>] [-v]
30 cache Manage node cache
31 config Edit site config
32 createdoxygen Generate Doxygen headers
33 dbstructure Do database updates
34 docbloxerrorchecker Check the file tree for DocBlox errors
35 extract Generate translation string file for the Friendica project (deprecated)
36 globalcommunityblock Block remote profile from interacting with this node
37 globalcommunitysilence Silence remote profile from global community page
38 archivecontact Archive a contact when you know that it isn't existing anymore
39 help Show help about a command, e.g (bin/console help config)
40 autoinstall Starts automatic installation of friendica based on values from htconfig.php
41 maintenance Set maintenance mode for this node
42 newpassword Set a new password for a given user
43 php2po Generate a messages.po file from a strings.php file
44 po2php Generate a strings.php file from a messages.po file
45 typo Checks for parse errors in Friendica files
46 postupdate Execute pending post update scripts (can last days)
47 serverblock Manage blocked servers
48 storage Manage storage backend
51 -h|--help|-? Show help information
52 -v Show more debug information.
57 protected $subConsoles = [
58 'cache' => Friendica\Console\Cache::class,
59 'config' => Friendica\Console\Config::class,
60 'createdoxygen' => Friendica\Console\CreateDoxygen::class,
61 'docbloxerrorchecker' => Friendica\Console\DocBloxErrorChecker::class,
62 'dbstructure' => Friendica\Console\DatabaseStructure::class,
63 'extract' => Friendica\Console\Extract::class,
64 'globalcommunityblock' => Friendica\Console\GlobalCommunityBlock::class,
65 'globalcommunitysilence' => Friendica\Console\GlobalCommunitySilence::class,
66 'archivecontact' => Friendica\Console\ArchiveContact::class,
67 'autoinstall' => Friendica\Console\AutomaticInstallation::class,
68 'maintenance' => Friendica\Console\Maintenance::class,
69 'newpassword' => Friendica\Console\NewPassword::class,
70 'php2po' => Friendica\Console\PhpToPo::class,
71 'po2php' => Friendica\Console\PoToPhp::class,
72 'typo' => Friendica\Console\Typo::class,
73 'postupdate' => Friendica\Console\PostUpdate::class,
74 'serverblock' => Friendica\Console\ServerBlock::class,
75 'storage' => Friendica\Console\Storage::class,
79 * CliInput Friendica constructor.
81 * @param Dice $dice The DI library
84 public function __construct(Dice $dice, array $argv = null)
86 parent::__construct($argv);
91 protected function doExecute()
93 if ($this->getOption('v')) {
94 $this->out('Executable: ' . $this->executable);
95 $this->out('Arguments: ' . var_export($this->args, true));
96 $this->out('Options: ' . var_export($this->options, true));
102 if ($this->getOption('version')) {
103 $this->out('Friendica Console version ' . FRIENDICA_VERSION);
106 } elseif ((count($this->options) === 0 || $this->getOption($this->customHelpOptions) === true || $this->getOption($this->customHelpOptions) === 1) && count($this->args) === 0
108 } elseif (count($this->args) >= 2 && $this->getArgument(0) == 'help') {
109 $command = $this->getArgument(1);
111 array_shift($this->args);
112 array_shift($this->args);
113 } elseif (count($this->args) >= 1) {
114 $command = $this->getArgument(0);
115 array_shift($this->args);
118 if (is_null($command)) {
119 $this->out($this->getHelp());
123 $console = $this->getSubConsole($command);
126 $console->setOption($this->customHelpOptions, true);
129 return $console->execute();
132 private function getSubConsole($command)
134 if ($this->getOption('v')) {
135 $this->out('Command: ' . $command);
138 if (!isset($this->subConsoles[$command])) {
139 throw new \Asika\SimpleConsole\CommandArgsException('Command ' . $command . ' doesn\'t exist');
142 $subargs = $this->args;
143 array_unshift($subargs, $this->executable);
145 $className = $this->subConsoles[$command];
147 Friendica\BaseObject::setDependencyInjection($this->dice);
149 /** @var Console $subconsole */
150 $subconsole = $this->dice->create($className, [$subargs]);
152 foreach ($this->options as $name => $value) {
153 $subconsole->setOption($name, $value);