]> git.mxchange.org Git - friendica.git/blob - src/Console/PostUpdate.php
Merge pull request #11524 from annando/cache-endpoints
[friendica.git] / src / Console / PostUpdate.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Console;
23
24 use Friendica\App;
25 use Friendica\Core\Config\Capability\IManageConfigValues;
26 use Friendica\Core\L10n;
27 use Friendica\Core\Update;
28
29 /**
30  * Performs database post updates
31  */
32 class PostUpdate extends \Asika\SimpleConsole\Console
33 {
34         protected $helpOptions = ['h', 'help', '?'];
35
36         /**
37          * @var App\Mode
38          */
39         private $appMode;
40         /**
41          * @var IManageConfigValues
42          */
43         private $config;
44         /**
45          * @var L10n
46          */
47         private $l10n;
48
49         protected function getHelp()
50         {
51                 $help = <<<HELP
52 console postupdate - Performs database post updates
53 Usage
54         bin/console postupdate [-h|--help|-?] [--reset <version>]
55
56 Options
57     -h|--help|-?      Show help information
58     --reset <version> Reset the post update version
59 HELP;
60                 return $help;
61         }
62
63         public function __construct(App\Mode $appMode, IManageConfigValues $config, L10n $l10n, array $argv = null)
64         {
65                 parent::__construct($argv);
66
67                 $this->appMode = $appMode;
68                 $this->config = $config;
69                 $this->l10n = $l10n;
70         }
71
72         protected function doExecute()
73         {
74                 $a = \Friendica\DI::app();
75
76                 if ($this->getOption($this->helpOptions)) {
77                         $this->out($this->getHelp());
78                         return 0;
79                 }
80
81                 $reset_version = $this->getOption('reset');
82                 if (is_bool($reset_version)) {
83                         $this->out($this->getHelp());
84                         return 0;
85                 } elseif ($reset_version) {
86                         $this->config->set('system', 'post_update_version', $reset_version);
87                         echo $this->l10n->t('Post update version number has been set to %s.', $reset_version) . "\n";
88                         return 0;
89                 }
90
91                 if ($this->appMode->isInstall()) {
92                         throw new \RuntimeException('Database isn\'t ready or populated yet');
93                 }
94
95                 echo $this->l10n->t('Check for pending update actions.') . "\n";
96                 Update::run($a->getBasePath(), true, false, true, false);
97                 echo $this->l10n->t('Done.') . "\n";
98
99                 echo $this->l10n->t('Execute pending post updates.') . "\n";
100
101                 while (!\Friendica\Database\PostUpdate::update()) {
102                         echo '.';
103                 }
104
105                 echo "\n" . $this->l10n->t('All pending post updates are done.') . "\n";
106
107                 return 0;
108         }
109 }