Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Migrate UpgradeCommandController to Symfony Commands #845

Merged
merged 2 commits into from Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
87 changes: 87 additions & 0 deletions Classes/Console/Command/Upgrade/UpgradeAllCommand.php
@@ -0,0 +1,87 @@
<?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
{
protected function configure()
{
$this->setDescription('Execute all upgrade wizards that are scheduled for execution');
$this->addOption(
'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)
{
$upgradeHandling = new UpgradeHandling();
// @deprecated, should be changed to StyleInterface
$consoleOutput = new ConsoleOutput($output, $input);
if (!$this->ensureExtensionCompatibility($upgradeHandling, $output)) {
return 1;
}

$arguments = $input->getOption('arguments');
$verbose = $output->isVerbose();

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

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

$output->writeln(sprintf(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, $consoleOutput);
}

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

return 0;
}

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

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

return false;
}

return true;
}
}
@@ -0,0 +1,55 @@
<?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
{
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(
'extensionKeys',
InputArgument::REQUIRED,
'Extension key for extension to check'
);
$this->addOption(
'configOnly',
'c',
InputOption::VALUE_NONE,
''
);
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$extensionKey = $input->getArgument('extensionKeys');
$configOnly = $input->getOption('configOnly');

$output->writeln(\json_encode((new UpgradeHandling())->isCompatible($extensionKey, $configOnly)));
}
}
@@ -0,0 +1,88 @@
<?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
{
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(
'extensionKeys',
InputArgument::OPTIONAL,
'Extension keys to check. Separate multiple extension keys with comma',
''
);
$this->addOption(
'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('extensionKeys'));
$typo3Version = $input->getOption('typo3-version');
$upgradeHandling = new UpgradeHandling();
if (empty($extensionKeys)) {
$failedPackageMessages = $upgradeHandling->matchAllExtensionConstraints($typo3Version);
} else {
$failedPackageMessages = [];
foreach ($extensionKeys as $extensionKey) {
try {
if (!empty($result = $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
));

return 0;
}

return 1;
}
}
78 changes: 78 additions & 0 deletions Classes/Console/Command/Upgrade/UpgradeListCommand.php
@@ -0,0 +1,78 @@
<?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\UpgradeWizardListRenderer;
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 UpgradeListCommand extends Command
{
protected function configure()
{
$this->setDescription('List upgrade wizards');
$this->addOption(
'all',
'a',
InputOption::VALUE_NONE,
'If set, all wizards will be listed, even the once marked as ready or done'
);
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$upgradeHandling = new UpgradeHandling();
if (!$this->ensureExtensionCompatibility($upgradeHandling, $output)) {
return 1;
}

$all = $input->getOption('all');
$wizards = $upgradeHandling->executeInSubProcess('listWizards');

$listRenderer = new UpgradeWizardListRenderer();
// @deprecated usage of ConsoleOutput will be removed with 6.0
$consoleOutput = new ConsoleOutput($output, $input);

$output->writeln('<comment>Wizards scheduled for execution:</comment>');
$listRenderer->render($wizards['scheduled'], $consoleOutput, $output->isVerbose());

if ($all) {
$output->writeln(PHP_EOL . '<comment>Wizards marked as done:</comment>');
$listRenderer->render($wizards['done'], $consoleOutput, $output->isVerbose());
}

return 0;
}

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

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

return false;
}

return true;
}
}
56 changes: 56 additions & 0 deletions Classes/Console/Command/Upgrade/UpgradeSubProcessCommand.php
@@ -0,0 +1,56 @@
<?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\Output\OutputInterface;

/**
* This is where the hard work happens in a fully bootstrapped TYPO3
* It will be called as sub process
*
* @internal
*/
class UpgradeSubProcessCommand extends Command
{
protected function configure()
{
$this->setHidden(true);
$this->setDescription('This is where the hard work happens in a fully bootstrapped TYPO3');
$this->setHelp('It will be called as sub process');
$this->addArgument(
'upgradeCommand',
InputArgument::REQUIRED
);
$this->addArgument(
'arguments',
InputArgument::REQUIRED,
'Serialized arguments'
);
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$upgradeCommand = $input->getArgument('upgradeCommand');
$arguments = $input->getArgument('arguments');

$arguments = unserialize($arguments, ['allowed_classes' => false]);
$result = (new UpgradeHandling())->$upgradeCommand(...$arguments);
$output->write(serialize($result), false, OutputInterface::OUTPUT_RAW);
}
}