3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Console;
25 use Friendica\Core\Config\Capability\IManageConfigValues;
26 use Friendica\Core\L10n;
27 use Friendica\Core\Update;
30 * Performs database post updates
32 class PostUpdate extends \Asika\SimpleConsole\Console
34 protected $helpOptions = ['h', 'help', '?'];
41 * @var IManageConfigValues
49 protected function getHelp()
52 console postupdate - Performs database post updates
54 bin/console postupdate [-h|--help|-?] [--reset <version>]
57 -h|--help|-? Show help information
58 --reset <version> Reset the post update version
63 public function __construct(App\Mode $appMode, IManageConfigValues $config, L10n $l10n, array $argv = null)
65 parent::__construct($argv);
67 $this->appMode = $appMode;
68 $this->config = $config;
72 protected function doExecute(): int
74 $a = \Friendica\DI::app();
76 if ($this->getOption($this->helpOptions)) {
77 $this->out($this->getHelp());
81 $reset_version = $this->getOption('reset');
82 if (is_bool($reset_version)) {
83 $this->out($this->getHelp());
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";
91 if ($this->appMode->isInstall()) {
92 throw new \RuntimeException('Database isn\'t ready or populated yet');
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";
99 echo $this->l10n->t('Execute pending post updates.') . "\n";
101 while (!\Friendica\Database\PostUpdate::update()) {
105 echo "\n" . $this->l10n->t('All pending post updates are done.') . "\n";