Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract class ExtendableRequireCommand extends RequireCommand
protected $jsonFile;

/**
* @var boolean $mageNewlyCreated
* @var bool $mageNewlyCreated
*/
protected $mageNewlyCreated;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
use Magento\ComposerRootUpdatePlugin\Plugin\Commands\MageRootRequireCommand;
use Magento\ComposerRootUpdatePlugin\Plugin\Commands\UpdatePluginNamespaceCommands;

/**
* Class CommandProvider
*/
class CommandProvider implements CommandProviderCapability
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Class RootUpdateCommand
*/
class MageRootRequireCommand extends ExtendableRequireCommand
{
/**
Expand All @@ -42,7 +39,12 @@ class MageRootRequireCommand extends ExtendableRequireCommand
/**
* @var RootPackageRetriever $retriever
*/
private $retriever;
protected $retriever;

/**
* @var Console $console
*/
protected $console;

/**
* Call the parent setApplication method but also change the command's name to update
Expand All @@ -57,7 +59,6 @@ public function setApplication(Application $application = null)
// added to the command registry
$this->setName($this->commandName);
parent::setApplication($application);
Console::setIO($this->getIO());
}

/**
Expand Down Expand Up @@ -132,7 +133,7 @@ public function configure()
public function execute(InputInterface $input, OutputInterface $output)
{
$updater = null;
Console::setIO($this->getIO());
$this->console = new Console($this->getIO(), $input->getOption(static::INTERACTIVE_OPT));
$fileParsed = $this->parseComposerJsonFile($input);
if ($fileParsed !== 0) {
return $fileParsed;
Expand Down Expand Up @@ -162,12 +163,12 @@ public function execute(InputInterface $input, OutputInterface $output)

// Found a Magento product in the command arguments; try to run the updater
try {
$updater = new MagentoRootUpdater($this->getComposer());
$updater = new MagentoRootUpdater($this->console, $this->getComposer());
$didUpdate = $this->runUpdate($updater, $input, $edition, $constraint);
} catch (\Exception $e) {
$label = 'Magento ' . ucfirst($edition) . " Edition $constraint";
$this->revertMageComposerFile("Update of composer.json with $label changes failed");
Console::log($e->getMessage());
$this->console->log($e->getMessage());
$didUpdate = false;
}

Expand All @@ -178,12 +179,12 @@ public function execute(InputInterface $input, OutputInterface $output)
if ($didUpdate) {
// Update composer.json before the native execute(), as it reads the file instead of an in-memory object
$label = $this->retriever->getTargetLabel();
Console::info("Updating composer.json for $label ...");
$this->console->info("Updating composer.json for $label ...");
try {
$updater->writeUpdatedComposerJson();
} catch (\Exception $e) {
$this->revertMageComposerFile("Update of composer.json with $label changes failed");
Console::log($e->getMessage());
$this->console->log($e->getMessage());
$didUpdate = false;
}
}
Expand All @@ -202,7 +203,7 @@ public function execute(InputInterface $input, OutputInterface $output)
// If the native execute() didn't succeed, revert the Magento changes to the composer.json file
$this->revertMageComposerFile('The native \'composer ' . $this->commandName . '\' command failed');
if ($constraint && !PackageUtils::isConstraintStrict($constraint)) {
Console::comment(
$this->console->comment(
"Recommended: Use a specific Magento version constraint instead of \"$package: $constraint\""
);
}
Expand All @@ -224,7 +225,7 @@ public function execute(InputInterface $input, OutputInterface $output)
* @param InputInterface $input
* @param string $targetEdition
* @param string $targetConstraint
* @return boolean Returns true if updates were necessary and prepared successfully
* @return bool Returns true if updates were necessary and prepared successfully
*/
protected function runUpdate($updater, $input, $targetEdition, $targetConstraint)
{
Expand Down Expand Up @@ -252,8 +253,8 @@ protected function runUpdate($updater, $input, $targetEdition, $targetConstraint
}
}

Console::setInteractive($input->getOption(static::INTERACTIVE_OPT));
$this->retriever = new RootPackageRetriever(
$this->console,
$this->getComposer(),
$targetEdition,
$targetConstraint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ class UpdatePluginNamespaceCommands extends BaseCommand
{
const NAME = 'magento-update-plugin';

/**
* @var Console $console
*/
protected $console;

/**
* Map of operation command to description
*
* @var array $operations
*/
private static $operations = [
protected static $operations = [
'list' =>
"List all operations available in the <comment>%command.name%</comment> namespace. This is equivalent\n".
'to running <comment>%command.full_name%</comment> without an operation.',
Expand Down Expand Up @@ -63,16 +68,17 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->console = new Console($this->getIO());
$operation = $input->getArgument('operation');
Console::setIO($this->getIO());
if (empty($operation) || $operation == 'list') {
Console::log(static::describeOperations() . "\n");
$this->console->log(static::describeOperations() . "\n");
return 0;
}
if ($operation == 'install') {
return WebSetupWizardPluginInstaller::doVarInstall();
$setupWizardInstaller = new WebSetupWizardPluginInstaller($this->console);
return $setupWizardInstaller->doVarInstall();
} else {
Console::error("'$operation' is not a supported operation for ".static::NAME);
$this->console->error("'$operation' is not a supported operation for ".static::NAME);
return 1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
use Composer\IO\IOInterface;
use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability;
use Composer\Plugin\Capable;
use Composer\Plugin\PluginInterface;;
use Composer\Plugin\PluginInterface;
use Magento\ComposerRootUpdatePlugin\Setup\WebSetupWizardPluginInstaller;
use Magento\ComposerRootUpdatePlugin\Utils\Console;

/**
* Class PluginDefinition
Expand Down Expand Up @@ -62,7 +63,8 @@ public function packageUpdate(PackageEvent $event)
{
// Safeguard against the source file being removed before the event is triggered
if (class_exists('\Magento\ComposerRootUpdatePlugin\Setup\WebSetupWizardPluginInstaller')) {
WebSetupWizardPluginInstaller::packageEvent($event);
$setupWizardInstaller = new WebSetupWizardPluginInstaller(new Console($event->getIO()));
$setupWizardInstaller->packageEvent($event);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\ComposerRootUpdatePlugin\Setup;

use Composer\IO\ConsoleIO;
use Magento\ComposerRootUpdatePlugin\Utils\Console;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Symfony\Component\Console\Helper\DebugFormatterHelper;
use Symfony\Component\Console\Helper\FormatterHelper;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\ProcessHelper;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;

abstract class AbstractModuleOperation
{
public function doWizardInstall(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$io = new ConsoleIO(new ArrayInput([]),
new ConsoleOutput(OutputInterface::VERBOSITY_DEBUG),
new HelperSet([
new FormatterHelper(),
new DebugFormatterHelper(),
new ProcessHelper(),
new QuestionHelper()
])
);
$setupWizardInstaller = new WebSetupWizardPluginInstaller(new Console($io));
$setupWizardInstaller->doVarInstall();
}
}
7 changes: 2 additions & 5 deletions src/Magento/ComposerRootUpdatePlugin/Setup/InstallData.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

/**
* Class InstallData
*/
class InstallData implements InstallDataInterface
class InstallData extends AbstractModuleOperation implements InstallDataInterface
{
/**
* Passthrough Magento setup command to check the plugin installation in the var directory
Expand All @@ -24,6 +21,6 @@ class InstallData implements InstallDataInterface
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
WebSetupWizardPluginInstaller::doVarInstall();
$this->doWizardInstall($setup, $context);
}
}
7 changes: 2 additions & 5 deletions src/Magento/ComposerRootUpdatePlugin/Setup/RecurringData.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

/**
* Class RecurringData
*/
class RecurringData implements InstallDataInterface
class RecurringData extends AbstractModuleOperation implements InstallDataInterface
{
/**
* Passthrough Magento setup command to check the plugin installation in the var directory
Expand All @@ -24,6 +21,6 @@ class RecurringData implements InstallDataInterface
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
WebSetupWizardPluginInstaller::doVarInstall();
$this->doWizardInstall($setup, $context);
}
}
7 changes: 2 additions & 5 deletions src/Magento/ComposerRootUpdatePlugin/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;

/**
* Class UpgradeData
*/
class UpgradeData implements UpgradeDataInterface
class UpgradeData extends AbstractModuleOperation implements UpgradeDataInterface
{
/**
* Passthrough Magento setup command to check the plugin installation in the var directory
Expand All @@ -24,6 +21,6 @@ class UpgradeData implements UpgradeDataInterface
*/
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
WebSetupWizardPluginInstaller::doVarInstall();
$this->doWizardInstall($setup, $context);
}
}
Loading