2018-08-10 23:20:25 +02:00
|
|
|
<?php
|
2020-02-09 15:45:36 +01:00
|
|
|
/**
|
2021-03-29 08:40:20 +02:00
|
|
|
* @copyright Copyright (C) 2010-2021, the Friendica project
|
2020-02-09 15:45:36 +01:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2018-08-10 23:20:25 +02:00
|
|
|
|
2019-05-02 23:17:35 +02:00
|
|
|
namespace Friendica\Console;
|
2018-08-10 23:20:25 +02:00
|
|
|
|
2019-07-28 22:06:33 +02:00
|
|
|
use Friendica\App;
|
2021-10-26 21:44:29 +02:00
|
|
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
2020-01-18 20:59:39 +01:00
|
|
|
use Friendica\Core\L10n;
|
2018-11-12 11:36:10 +01:00
|
|
|
use Friendica\Core\Update;
|
2018-08-10 23:20:25 +02:00
|
|
|
|
|
|
|
/**
|
2018-09-16 01:28:38 +02:00
|
|
|
* Performs database post updates
|
2018-08-10 23:20:25 +02:00
|
|
|
*/
|
|
|
|
class PostUpdate extends \Asika\SimpleConsole\Console
|
|
|
|
{
|
2019-07-28 22:06:33 +02:00
|
|
|
protected $helpOptions = ['h', 'help', '?'];
|
2018-08-29 13:48:40 +02:00
|
|
|
|
2019-07-28 22:06:33 +02:00
|
|
|
/**
|
|
|
|
* @var App\Mode
|
|
|
|
*/
|
|
|
|
private $appMode;
|
|
|
|
/**
|
2021-10-26 22:09:11 +02:00
|
|
|
* @var IManageConfigValues
|
2019-07-28 22:06:33 +02:00
|
|
|
*/
|
|
|
|
private $config;
|
|
|
|
/**
|
|
|
|
* @var L10n
|
|
|
|
*/
|
|
|
|
private $l10n;
|
|
|
|
|
|
|
|
protected function getHelp()
|
|
|
|
{
|
|
|
|
$help = <<<HELP
|
2018-08-29 15:06:56 +02:00
|
|
|
console postupdate - Performs database post updates
|
2018-08-29 13:48:40 +02:00
|
|
|
Usage
|
|
|
|
bin/console postupdate [-h|--help|-?] [--reset <version>]
|
|
|
|
|
|
|
|
Options
|
|
|
|
-h|--help|-? Show help information
|
|
|
|
--reset <version> Reset the post update version
|
|
|
|
HELP;
|
2019-07-28 22:06:33 +02:00
|
|
|
return $help;
|
|
|
|
}
|
|
|
|
|
2021-10-26 21:44:29 +02:00
|
|
|
public function __construct(App\Mode $appMode, IManageConfigValues $config, L10n $l10n, array $argv = null)
|
2019-07-28 22:06:33 +02:00
|
|
|
{
|
|
|
|
parent::__construct($argv);
|
|
|
|
|
|
|
|
$this->appMode = $appMode;
|
|
|
|
$this->config = $config;
|
|
|
|
$this->l10n = $l10n;
|
|
|
|
}
|
2018-08-29 13:48:40 +02:00
|
|
|
|
2018-08-10 23:20:25 +02:00
|
|
|
protected function doExecute()
|
|
|
|
{
|
2019-12-15 22:34:11 +01:00
|
|
|
$a = \Friendica\DI::app();
|
2018-08-10 23:20:25 +02:00
|
|
|
|
2018-08-29 13:48:40 +02:00
|
|
|
if ($this->getOption($this->helpOptions)) {
|
|
|
|
$this->out($this->getHelp());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$reset_version = $this->getOption('reset');
|
|
|
|
if (is_bool($reset_version)) {
|
|
|
|
$this->out($this->getHelp());
|
|
|
|
return 0;
|
|
|
|
} elseif ($reset_version) {
|
2019-07-28 22:06:33 +02:00
|
|
|
$this->config->set('system', 'post_update_version', $reset_version);
|
|
|
|
echo $this->l10n->t('Post update version number has been set to %s.', $reset_version) . "\n";
|
2018-08-29 13:48:40 +02:00
|
|
|
return 0;
|
2018-08-10 23:20:25 +02:00
|
|
|
}
|
|
|
|
|
2019-07-28 22:06:33 +02:00
|
|
|
if ($this->appMode->isInstall()) {
|
2018-08-10 23:20:25 +02:00
|
|
|
throw new \RuntimeException('Database isn\'t ready or populated yet');
|
|
|
|
}
|
|
|
|
|
2019-07-28 22:06:33 +02:00
|
|
|
echo $this->l10n->t('Check for pending update actions.') . "\n";
|
2019-02-24 12:51:46 +01:00
|
|
|
Update::run($a->getBasePath(), true, false, true, false);
|
2019-07-28 22:06:33 +02:00
|
|
|
echo $this->l10n->t('Done.') . "\n";
|
2018-11-12 11:36:10 +01:00
|
|
|
|
2019-07-28 22:06:33 +02:00
|
|
|
echo $this->l10n->t('Execute pending post updates.') . "\n";
|
2018-08-10 23:20:25 +02:00
|
|
|
|
|
|
|
while (!\Friendica\Database\PostUpdate::update()) {
|
|
|
|
echo '.';
|
|
|
|
}
|
|
|
|
|
2019-07-28 22:06:33 +02:00
|
|
|
echo "\n" . $this->l10n->t('All pending post updates are done.') . "\n";
|
2018-08-10 23:20:25 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|