2018-08-10 23:20:25 +02:00
|
|
|
<?php
|
|
|
|
|
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;
|
2019-12-19 20:11:07 +01:00
|
|
|
use Friendica\Core\Config\IConfiguration;
|
2019-07-28 22:06:33 +02:00
|
|
|
use Friendica\Core\L10n\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
|
|
|
*
|
|
|
|
* License: AGPLv3 or later, same as Friendica
|
|
|
|
*
|
2018-09-16 01:28:38 +02:00
|
|
|
* @author Tobias Diekershoff <tobias.diekershoff@gmx.net>
|
|
|
|
* @author Hypolite Petovan <hypolite@mrpetovan.com>
|
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;
|
|
|
|
/**
|
2019-12-19 20:11:07 +01:00
|
|
|
* @var IConfiguration
|
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;
|
|
|
|
}
|
|
|
|
|
2019-12-19 20:11:07 +01:00
|
|
|
public function __construct(App\Mode $appMode, IConfiguration $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;
|
|
|
|
}
|
|
|
|
}
|