]> git.mxchange.org Git - friendica.git/blob - src/Console/PostUpdate.php
Merge pull request #7943 from MrPetovan/bug/7920-api-fix-followers-friends-ids
[friendica.git] / src / Console / PostUpdate.php
1 <?php
2
3 namespace Friendica\Console;
4
5 use Friendica\App;
6 use Friendica\Core\Config\Configuration;
7 use Friendica\Core\L10n\L10n;
8 use Friendica\Core\Update;
9
10 /**
11  * Performs database post updates
12  *
13  * License: AGPLv3 or later, same as Friendica
14  *
15  * @author Tobias Diekershoff <tobias.diekershoff@gmx.net>
16  * @author Hypolite Petovan <hypolite@mrpetovan.com>
17  */
18 class PostUpdate extends \Asika\SimpleConsole\Console
19 {
20         protected $helpOptions = ['h', 'help', '?'];
21
22         /**
23          * @var App\Mode
24          */
25         private $appMode;
26         /**
27          * @var Configuration
28          */
29         private $config;
30         /**
31          * @var L10n
32          */
33         private $l10n;
34
35         protected function getHelp()
36         {
37                 $help = <<<HELP
38 console postupdate - Performs database post updates
39 Usage
40         bin/console postupdate [-h|--help|-?] [--reset <version>]
41
42 Options
43     -h|--help|-?      Show help information
44     --reset <version> Reset the post update version
45 HELP;
46                 return $help;
47         }
48
49         public function __construct(App\Mode $appMode, Configuration $config, L10n $l10n, array $argv = null)
50         {
51                 parent::__construct($argv);
52
53                 $this->appMode = $appMode;
54                 $this->config = $config;
55                 $this->l10n = $l10n;
56         }
57
58         protected function doExecute()
59         {
60                 $a = \Friendica\BaseObject::getApp();
61
62                 if ($this->getOption($this->helpOptions)) {
63                         $this->out($this->getHelp());
64                         return 0;
65                 }
66
67                 $reset_version = $this->getOption('reset');
68                 if (is_bool($reset_version)) {
69                         $this->out($this->getHelp());
70                         return 0;
71                 } elseif ($reset_version) {
72                         $this->config->set('system', 'post_update_version', $reset_version);
73                         echo $this->l10n->t('Post update version number has been set to %s.', $reset_version) . "\n";
74                         return 0;
75                 }
76
77                 if ($this->appMode->isInstall()) {
78                         throw new \RuntimeException('Database isn\'t ready or populated yet');
79                 }
80
81                 echo $this->l10n->t('Check for pending update actions.') . "\n";
82                 Update::run($a->getBasePath(), true, false, true, false);
83                 echo $this->l10n->t('Done.') . "\n";
84
85                 echo $this->l10n->t('Execute pending post updates.') . "\n";
86
87                 while (!\Friendica\Database\PostUpdate::update()) {
88                         echo '.';
89                 }
90
91                 echo "\n" . $this->l10n->t('All pending post updates are done.') . "\n";
92
93                 return 0;
94         }
95 }