Skip to content

Commit

Permalink
[TASK] Migrate UpdateCommandController to Symfony Commands
Browse files Browse the repository at this point in the history
The following commands are migrated from a CommandController structure to Symfony Commands:

- update:all
- update:checkextensioncompatibility
- update:checkextensionconstraints
- update:list
- update:subprocess
- update:wizard

Additional the removed parameter `messages` of method `executeInSubProcess` was removed from all calls.
  • Loading branch information
gilbertsoft authored and helhum committed Oct 7, 2019
1 parent c76c7be commit 3fd75bf
Show file tree
Hide file tree
Showing 11 changed files with 582 additions and 215 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace Helhum\Typo3Console\Command\Upgrade;

/*
* This file is part of the TYPO3 Console project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read
* LICENSE file that was distributed with this source code.
*
*/

trait EnsureExtensionCompatibilityTrait
{
private function ensureExtensionCompatibility()
{
$messages = $this->upgradeHandling->ensureExtensionCompatibility();
if (!empty($messages)) {
$this->output->writeln('<error>Incompatible extensions found, aborting.</error>');

foreach ($messages as $message) {
$this->output->writeln($message);
}

return false;
}

return true;
}
}
94 changes: 94 additions & 0 deletions Classes/Console/Command/Upgrade/UpgradeAllCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
declare(strict_types=1);
namespace Helhum\Typo3Console\Command\Upgrade;

/*
* This file is part of the TYPO3 Console project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read
* LICENSE file that was distributed with this source code.
*
*/

use Helhum\Typo3Console\Install\Upgrade\UpgradeHandling;
use Helhum\Typo3Console\Install\Upgrade\UpgradeWizardResultRenderer;
use Helhum\Typo3Console\Mvc\Cli\ConsoleOutput;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class UpgradeAllCommand extends Command
{
use EnsureExtensionCompatibilityTrait;

const OPT_ARGUMENTS = 'arguments';

/**
* @var UpgradeHandling
*/
private $upgradeHandling;

/**
* @var OutputInterface
*/
private $output;

/**
* @param UpgradeHandling|null $upgradeHandling
*/
public function __construct(
string $name = null,
UpgradeHandling $upgradeHandling = null
) {
parent::__construct($name);

$this->upgradeHandling = $upgradeHandling ?? new UpgradeHandling();
}

protected function configure()
{
$this->setDescription('Execute all upgrade wizards that are scheduled for execution');
$this->addOption(
self::OPT_ARGUMENTS,
'a',
InputOption::VALUE_REQUIRED,
'Arguments for the wizard prefixed with the identifier, e.g. <code>compatibility7Extension[install]=0</code>; multiple arguments separated with comma',
[]
);
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$this->output = $output;

if (!$this->ensureExtensionCompatibility()) {
return 1;
}

$arguments = $input->getArgument(self::ARG_ARGUMENTS);
$verbose = $output->isVerbose();

$output->writeln(PHP_EOL . '<i>Initiating TYPO3 upgrade</i>' . PHP_EOL);

$messages = [];
$results = $this->upgradeHandling->executeAll($arguments, $this->output, $messages);

$output->outputLine(PHP_EOL . PHP_EOL . '<i>Successfully upgraded TYPO3 to version %s</i>', [TYPO3_version]);

if ($verbose) {
$output->writeln('');
$output->writeln('<comment>Upgrade report:</comment>');
(new UpgradeWizardResultRenderer())->render($results, new ConsoleOutput($output, $input));
}

$output->writeln('');
foreach ($messages as $message) {
$output->writeln($message);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
namespace Helhum\Typo3Console\Command\Upgrade;

/*
* This file is part of the TYPO3 Console project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read
* LICENSE file that was distributed with this source code.
*
*/

use Helhum\Typo3Console\Install\Upgrade\UpgradeHandling;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class UpgradeCheckExtensionCompatibilityCommand extends Command
{
const ARG_EXTENSION_KEY = 'extensionKeys';
const OPT_CONFIG_ONLY = 'configOnly';

/**
* @var UpgradeHandling
*/
private $upgradeHandling;

/**
* @param UpgradeHandling|null $upgradeHandling
*/
public function __construct(
string $name = null,
UpgradeHandling $upgradeHandling = null
) {
parent::__construct($name);

$this->upgradeHandling = $upgradeHandling ?? new UpgradeHandling();
}

protected function configure()
{
$this->setDescription('Checks for broken extensions');
$this->setHelp(
<<<'EOH'
This command in meant to be executed as sub process as it is is subject to cause fatal errors
when extensions have broken (incompatible) code
EOH
);
$this->addArgument(
self::ARG_EXTENSION_KEY,
InputArgument::REQUIRED,
'Extension key for extension to check'
);
$this->addOption(
self::OPT_CONFIG_ONLY,
'c',
InputOption::VALUE_NONE,
''
);
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$extensionKey = $input->getArgument(self::ARG_EXTENSION_KEY);
$configOnly = $input->getOption(self::OPT_CONFIG_ONLY);

$output->writeln(\json_encode($this->upgradeHandling->isCompatible($extensionKey, $configOnly)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
declare(strict_types=1);
namespace Helhum\Typo3Console\Command\Upgrade;

/*
* This file is part of the TYPO3 Console project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read
* LICENSE file that was distributed with this source code.
*
*/

use Helhum\Typo3Console\Install\Upgrade\UpgradeHandling;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Package\Exception\UnknownPackageException;

class UpgradeCheckExtensionConstraintsCommand extends Command
{
const ARG_EXTENSION_KEYS = 'extensionKeys';
const OPT_TYPO3_VERSION = 'typo3-version';

/**
* @var UpgradeHandling
*/
private $upgradeHandling;

/**
* @param UpgradeHandling|null $upgradeHandling
*/
public function __construct(
string $name = null,
UpgradeHandling $upgradeHandling = null
) {
parent::__construct($name);

$this->upgradeHandling = $upgradeHandling ?? new UpgradeHandling();
}

protected function configure()
{
$this->setDescription('Check TYPO3 version constraints of extensions');
$this->setHelp(
<<<'EOH'
This command is especially useful **before** switching sources to a new TYPO3 version.
It checks the version constraints of all third party extensions against a given TYPO3 version.
It therefore relies on the constraints to be correct.
EOH
);
$this->addArgument(
self::ARG_EXTENSION_KEYS,
InputArgument::OPTIONAL,
'Extension keys to check. Separate multiple extension keys with comma',
''
);
$this->addOption(
self::OPT_TYPO3_VERSION,
null,
InputOption::VALUE_REQUIRED,
'TYPO3 version to check against. Defaults to current TYPO3 version',
TYPO3_version
);
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$extensionKeys = explode(',', $input->getArgument(self::ARG_EXTENSION_KEYS));
$typo3Version = $input->getOption(self::OPT_TYPO3_VERSION);

if (empty($extensionKeys)) {
$failedPackageMessages = $this->upgradeHandling->matchAllExtensionConstraints($typo3Version);
} else {
$failedPackageMessages = [];
foreach ($extensionKeys as $extensionKey) {
try {
if (!empty($result = $this->upgradeHandling->matchExtensionConstraints($extensionKey, $typo3Version))) {
$failedPackageMessages[$extensionKey] = $result;
}
} catch (UnknownPackageException $e) {
$output->writeln(sprintf(
'<warning>Extension "%s" is not found in the system</warning>',
$extensionKey
));
}
}
}
foreach ($failedPackageMessages as $constraintMessage) {
$output->writeln(sprintf('<error>%s</error>', $constraintMessage));
}
if (empty($failedPackageMessages)) {
$output->writeln(sprintf(
'<info>All third party extensions claim to be compatible with TYPO3 version %s</info>',
$typo3Version
));
} else {
return 1;
}
}
}

0 comments on commit 3fd75bf

Please sign in to comment.