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
42 maintenance Set maintenance mode for this node
43 newpassword Set a new password for a given user
44 php2po Generate a messages.po file from a strings.php file
45 po2php Generate a strings.php file from a messages.po file
46 typo Checks for parse errors in Friendica files
47 postupdate Execute pending post update scripts (can last days)
48 serverblock Manage blocked servers
49 storage Manage storage backend
52 -h|--help|-? Show help information
53 -v Show more debug information.
58 protected $subConsoles = [
59 'cache' => Friendica\Console\Cache::class,
60 'config' => Friendica\Console\Config::class,
61 'createdoxygen' => Friendica\Console\CreateDoxygen::class,
62 'docbloxerrorchecker' => Friendica\Console\DocBloxErrorChecker::class,
63 'dbstructure' => Friendica\Console\DatabaseStructure::class,
64 'extract' => Friendica\Console\Extract::class,
65 'globalcommunityblock' => Friendica\Console\GlobalCommunityBlock::class,
66 'globalcommunitysilence' => Friendica\Console\GlobalCommunitySilence::class,
67 'archivecontact' => Friendica\Console\ArchiveContact::class,
68 'autoinstall' => Friendica\Console\AutomaticInstallation::class,
69 'lock' => Friendica\Console\Lock::class,
70 'maintenance' => Friendica\Console\Maintenance::class,
71 'newpassword' => Friendica\Console\NewPassword::class,
72 'php2po' => Friendica\Console\PhpToPo::class,
73 'po2php' => Friendica\Console\PoToPhp::class,
74 'typo' => Friendica\Console\Typo::class,
75 'postupdate' => Friendica\Console\PostUpdate::class,
76 'serverblock' => Friendica\Console\ServerBlock::class,
77 'storage' => Friendica\Console\Storage::class,
81 * CliInput Friendica constructor.
83 * @param Dice $dice The DI library
86 public function __construct(Dice $dice, array $argv = null)
88 parent::__construct($argv);
93 protected function doExecute()
95 if ($this->getOption('v')) {
96 $this->out('Executable: ' . $this->executable);
97 $this->out('Arguments: ' . var_export($this->args, true));
98 $this->out('Options: ' . var_export($this->options, true));
104 if ($this->getOption('version')) {
105 $this->out('Friendica Console version ' . FRIENDICA_VERSION);
108 } elseif ((count($this->options) === 0 || $this->getOption($this->customHelpOptions) === true || $this->getOption($this->customHelpOptions) === 1) && count($this->args) === 0
110 } elseif (count($this->args) >= 2 && $this->getArgument(0) == 'help') {
111 $command = $this->getArgument(1);
113 array_shift($this->args);
114 array_shift($this->args);
115 } elseif (count($this->args) >= 1) {
116 $command = $this->getArgument(0);
117 array_shift($this->args);
120 if (is_null($command)) {
121 $this->out($this->getHelp());
125 $console = $this->getSubConsole($command);
128 $console->setOption($this->customHelpOptions, true);
131 return $console->execute();
134 private function getSubConsole($command)
136 if ($this->getOption('v')) {
137 $this->out('Command: ' . $command);
140 if (!isset($this->subConsoles[$command])) {
141 throw new \Asika\SimpleConsole\CommandArgsException('Command ' . $command . ' doesn\'t exist');
144 $subargs = $this->args;
145 array_unshift($subargs, $this->executable);
147 $className = $this->subConsoles[$command];
149 Friendica\BaseObject::setDependencyInjection($this->dice);
151 /** @var Console $subconsole */
152 $subconsole = $this->dice->create($className, [$subargs]);
154 foreach ($this->options as $name => $value) {
155 $subconsole->setOption($name, $value);