"Does" is now "perform"
[friendica.git/.git] / src / Core / Console / PostUpdate.php
1 <?php
2
3 namespace Friendica\Core\Console;
4
5 use Friendica\Core\L10n;
6 use Friendica\Core\Config;
7
8 /**
9  * @brief tool to block an account from the node
10  *
11  * With this tool, you can block an account in such a way, that no postings
12  * or comments this account writes are accepted to the node.
13  *
14  * License: AGPLv3 or later, same as Friendica
15  *
16  * @author Tobias Diekershoff <mrpetovan@gmail.com>
17  * @author Hypolite Petovan <mrpetovan@gmail.com>
18  */
19 class PostUpdate extends \Asika\SimpleConsole\Console
20 {
21         protected $helpOptions = ['h', 'help', '?'];
22
23         protected function getHelp()
24         {
25                 $help = <<<HELP
26 console postupdate - Performs database post updates
27 Usage
28         bin/console postupdate [-h|--help|-?] [--reset <version>]
29
30 Options
31     -h|--help|-?      Show help information
32     --reset <version> Reset the post update version
33 HELP;
34                 return $help;
35         }
36
37         protected function doExecute()
38         {
39                 $a = get_app();
40
41                 if ($this->getOption($this->helpOptions)) {
42                         $this->out($this->getHelp());
43                         return 0;
44                 }
45
46                 $reset_version = $this->getOption('reset');
47                 if (is_bool($reset_version)) {
48                         $this->out($this->getHelp());
49                         return 0;
50                 } elseif ($reset_version) {
51                         Config::set('system', 'post_update_version', $reset_version);
52                         echo L10n::t('Post update version number has been set to %s.', $reset_version) . "\n";
53                         return 0;
54                 }
55
56                 if ($a->isInstallMode()) {
57                         throw new \RuntimeException('Database isn\'t ready or populated yet');
58                 }
59
60                 echo L10n::t('Execute pending post updates.') . "\n";
61
62                 while (!\Friendica\Database\PostUpdate::update()) {
63                         echo '.';
64                 }
65
66                 echo "\n" . L10n::t('All pending post updates are done.') . "\n";
67
68                 return 0;
69         }
70 }