Skip to content

Commit 4384348

Browse files
MC-5465: Refactoring module operations to use abstract class
1 parent bc23f61 commit 4384348

File tree

16 files changed

+78
-93
lines changed

16 files changed

+78
-93
lines changed

docs/class_descriptions.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,16 @@ Classes in this namespace deal with installing the plugin inside the project's `
109109

110110
When the Web Setup Wizard runs an upgrade operation, it first tries to validate the upgrade by copying the `composer.json` file into the `var` directory and attempting a dry-run upgrade. However, because it only copies the `composer.json` file and not any of the other code in the installation (including the plugin's root installation in `vendor`), the plugin will not function for this dry run. In order to enable the plugin, it needs to already be present in `var/vendor`, where the Wizard's `composer require` for the validation will find it.
111111

112+
#### [**AbstractModuleOperation**](../src/Magento/ComposerRootUpdatePlugin/Setup/AbstractModuleOperation.php)
113+
114+
This abstract class allows extending Magento module operation classes to trigger [WebSetupWizardPluginInstaller::doVarInstall()](#websetupwizardplugininstaller).
115+
116+
- **`doVarInstall()`**
117+
- Helper method for extending classes to setup and call `WebSetupWizardPluginInstaller::doVarInstall()`
118+
112119
#### **[InstallData](../src/Magento/ComposerRootUpdatePlugin/Setup/InstallData.php)/[RecurringData](../src/Magento/ComposerRootUpdatePlugin/Setup/RecurringData.php)/[UpgradeData](../src/Magento/ComposerRootUpdatePlugin/Setup/UpgradeData.php)**
113120

114-
These are Magento module setup classes to trigger [WebSetupWizardPluginInstaller::doVarInstall()](#websetupwizardplugininstaller) on `bin/magento setup` commands. Specifically, this is necessary when the `bin/magento setup:uninstall` and `bin/magento setup:install` commands are run, which would otherwise remove the plugin from the `var` directory without triggering the Composer package events that would normally install the plugin there.
121+
These are Magento module setup classes to trigger `AbstractModuleOperation::doVarInstall()` on `bin/magento setup` commands. Specifically, this is necessary when the `bin/magento setup:uninstall` and `bin/magento setup:install` commands are run, which would otherwise remove the plugin from the `var` directory without triggering the Composer package events that would normally install the plugin there.
115122

116123
#### [**WebSetupWizardPluginInstaller**](../src/Magento/ComposerRootUpdatePlugin/Setup/WebSetupWizardPluginInstaller.php)
117124

docs/process_flows.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ There are four paths through the plugin code that cover two main pieces of funct
7373
1. The `"autoload"->"files": "registration.php"` value in the plugin's [composer.json](../src/Magento/ComposerRootUpdatePlugin/composer.json) file causes [registration.php](../src/Magento/ComposerRootUpdatePlugin/registration.php) to be loaded by Magento
7474
2. `registration.php` registers the plugin as the `Magento_ComposerRootUpdatePlugin` module so it can tie into the `bin/magento setup` module operations
7575
3. Magento searches registered modules for any `Setup\InstallData`, `Setup\RecurringData`, or `Setup\UpgradeData` classes
76-
4. Magento calls [InstallData::install()](class_descriptions.md#installdatarecurringdataupgradedata), [RecurringData::install()](class_descriptions.md#installdatarecurringdataupgradedata), or [UpgradeData::upgrade()](class_descriptions.md#installdatarecurringdataupgradedata) as appropriate (which one depends on the specific `bin/magento setup` command and installed Magento version), which then calls [WebSetupWizardPluginInstaller::doVarInstall()](class_descriptions.md#websetupwizardplugininstaller)
76+
4. Magento calls [InstallData::install()](class_descriptions.md#installdatarecurringdataupgradedata), [RecurringData::install()](class_descriptions.md#installdatarecurringdataupgradedata), or [UpgradeData::upgrade()](class_descriptions.md#installdatarecurringdataupgradedata) as appropriate (which one depends on the specific `bin/magento setup` command and installed Magento version), which then calls [WebSetupWizardPluginInstaller::doVarInstall()](class_descriptions.md#websetupwizardplugininstaller) through [AbstractModuleOperation::doVarInstall()](class_descriptions.md#abstractmoduleoperation)
7777
5. `WebSetupWizardPluginInstaller::doVarInstall()` finds the `magento/composer-root-update-plugin` version in the `composer.lock` file in the root Magento directory and calls `WebSetupWizardPluginInstaller::updateSetupWizardPlugin()`
7878
6. `WebSetupWizardPluginInstaller::updateSetupWizardPlugin()` checks the `<Magento>/var/vendor` directory for the `magento/composer-root-update-plugin` version installed there (if any) to see if it matches the version in the root `composer.lock` file
7979
7. If the version does not match or `magento/composer-root-update-plugin` is absent in `<Magento>/var/vendor`, `WebSetupWizardPluginInstaller::updateSetupWizardPlugin()` installs the root project's `magento/composer-root-update-plugin` version in a temporary directory, then replaces `<Magento>/var/vendor` with the `vendor` directory from the temporary installation

src/Magento/ComposerRootUpdatePlugin/ComposerReimplementation/ExtendableRequireCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ abstract class ExtendableRequireCommand extends RequireCommand
3535
protected $jsonFile;
3636

3737
/**
38-
* @var boolean $mageNewlyCreated
38+
* @var bool $mageNewlyCreated
3939
*/
4040
protected $mageNewlyCreated;
4141

4242
/**
43-
* @var boolean|string $mageComposerBackup
43+
* @var bool|string $mageComposerBackup
4444
*/
4545
protected $mageComposerBackup;
4646

src/Magento/ComposerRootUpdatePlugin/Plugin/Commands/MageRootRequireCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public function execute(InputInterface $input, OutputInterface $output)
234234
* @param InputInterface $input
235235
* @param string $targetEdition
236236
* @param string $targetConstraint
237-
* @return boolean Returns true if updates were necessary and prepared successfully
237+
* @return bool Returns true if updates were necessary and prepared successfully
238238
*/
239239
protected function runUpdate($updater, $input, $targetEdition, $targetConstraint)
240240
{

src/Magento/ComposerRootUpdatePlugin/Plugin/PluginDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Composer\IO\IOInterface;
1414
use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability;
1515
use Composer\Plugin\Capable;
16-
use Composer\Plugin\PluginInterface;;
16+
use Composer\Plugin\PluginInterface;
1717
use Magento\ComposerRootUpdatePlugin\Setup\WebSetupWizardPluginInstaller;
1818
use Magento\ComposerRootUpdatePlugin\Utils\Console;
1919

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\ComposerRootUpdatePlugin\Setup;
8+
9+
use Composer\IO\ConsoleIO;
10+
use Magento\ComposerRootUpdatePlugin\Utils\Console;
11+
use Magento\Framework\Setup\ModuleContextInterface;
12+
use Magento\Framework\Setup\ModuleDataSetupInterface;
13+
use Symfony\Component\Console\Helper\DebugFormatterHelper;
14+
use Symfony\Component\Console\Helper\FormatterHelper;
15+
use Symfony\Component\Console\Helper\HelperSet;
16+
use Symfony\Component\Console\Helper\ProcessHelper;
17+
use Symfony\Component\Console\Helper\QuestionHelper;
18+
use Symfony\Component\Console\Input\ArrayInput;
19+
use Symfony\Component\Console\Output\ConsoleOutput;
20+
use Symfony\Component\Console\Output\OutputInterface;
21+
22+
abstract class AbstractModuleOperation
23+
{
24+
public function doVarInstall(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
25+
{
26+
$io = new ConsoleIO(new ArrayInput([]),
27+
new ConsoleOutput(OutputInterface::VERBOSITY_DEBUG),
28+
new HelperSet([
29+
new FormatterHelper(),
30+
new DebugFormatterHelper(),
31+
new ProcessHelper(),
32+
new QuestionHelper()
33+
])
34+
);
35+
$setupWizardInstaller = new WebSetupWizardPluginInstaller(new Console($io));
36+
$setupWizardInstaller->doVarInstall();
37+
}
38+
}

src/Magento/ComposerRootUpdatePlugin/Setup/InstallData.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,14 @@
66

77
namespace Magento\ComposerRootUpdatePlugin\Setup;
88

9-
use Composer\IO\ConsoleIO;
10-
use Magento\ComposerRootUpdatePlugin\Utils\Console;
119
use Magento\Framework\Setup\InstallDataInterface;
1210
use Magento\Framework\Setup\ModuleContextInterface;
1311
use Magento\Framework\Setup\ModuleDataSetupInterface;
14-
use Symfony\Component\Console\Helper\DebugFormatterHelper;
15-
use Symfony\Component\Console\Helper\FormatterHelper;
16-
use Symfony\Component\Console\Helper\HelperSet;
17-
use Symfony\Component\Console\Helper\ProcessHelper;
18-
use Symfony\Component\Console\Helper\QuestionHelper;
19-
use Symfony\Component\Console\Input\ArrayInput;
20-
use Symfony\Component\Console\Output\ConsoleOutput;
21-
use Symfony\Component\Console\Output\OutputInterface;
2212

2313
/**
2414
* Magento module hook to attach plugin installation functionality to `magento setup` operations
2515
*/
26-
class InstallData implements InstallDataInterface
16+
class InstallData extends AbstractModuleOperation implements InstallDataInterface
2717
{
2818
/**
2919
* Passthrough Magento setup command to check the plugin installation in the var directory
@@ -34,16 +24,6 @@ class InstallData implements InstallDataInterface
3424
*/
3525
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
3626
{
37-
$io = new ConsoleIO(new ArrayInput([]),
38-
new ConsoleOutput(OutputInterface::VERBOSITY_DEBUG),
39-
new HelperSet([
40-
new FormatterHelper(),
41-
new DebugFormatterHelper(),
42-
new ProcessHelper(),
43-
new QuestionHelper()
44-
])
45-
);
46-
$setupWizardInstaller = new WebSetupWizardPluginInstaller(new Console($io));
47-
$setupWizardInstaller->doVarInstall();
27+
$this->doVarInstall($setup, $context);
4828
}
4929
}

src/Magento/ComposerRootUpdatePlugin/Setup/RecurringData.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,14 @@
66

77
namespace Magento\ComposerRootUpdatePlugin\Setup;
88

9-
use Composer\IO\ConsoleIO;
10-
use Magento\ComposerRootUpdatePlugin\Utils\Console;
119
use Magento\Framework\Setup\InstallDataInterface;
1210
use Magento\Framework\Setup\ModuleContextInterface;
1311
use Magento\Framework\Setup\ModuleDataSetupInterface;
14-
use Symfony\Component\Console\Helper\DebugFormatterHelper;
15-
use Symfony\Component\Console\Helper\FormatterHelper;
16-
use Symfony\Component\Console\Helper\HelperSet;
17-
use Symfony\Component\Console\Helper\ProcessHelper;
18-
use Symfony\Component\Console\Helper\QuestionHelper;
19-
use Symfony\Component\Console\Input\ArrayInput;
20-
use Symfony\Component\Console\Output\ConsoleOutput;
21-
use Symfony\Component\Console\Output\OutputInterface;
2212

2313
/**
2414
* Magento module hook to attach plugin installation functionality to `magento setup` operations
2515
*/
26-
class RecurringData implements InstallDataInterface
16+
class RecurringData extends AbstractModuleOperation implements InstallDataInterface
2717
{
2818
/**
2919
* Passthrough Magento setup command to check the plugin installation in the var directory
@@ -34,16 +24,6 @@ class RecurringData implements InstallDataInterface
3424
*/
3525
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
3626
{
37-
$io = new ConsoleIO(new ArrayInput([]),
38-
new ConsoleOutput(OutputInterface::VERBOSITY_DEBUG),
39-
new HelperSet([
40-
new FormatterHelper(),
41-
new DebugFormatterHelper(),
42-
new ProcessHelper(),
43-
new QuestionHelper()
44-
])
45-
);
46-
$setupWizardInstaller = new WebSetupWizardPluginInstaller(new Console($io));
47-
$setupWizardInstaller->doVarInstall();
27+
$this->doVarInstall($setup, $context);
4828
}
4929
}

src/Magento/ComposerRootUpdatePlugin/Setup/UpgradeData.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,14 @@
66

77
namespace Magento\ComposerRootUpdatePlugin\Setup;
88

9-
use Composer\IO\ConsoleIO;
10-
use Magento\ComposerRootUpdatePlugin\Utils\Console;
119
use Magento\Framework\Setup\ModuleContextInterface;
1210
use Magento\Framework\Setup\ModuleDataSetupInterface;
1311
use Magento\Framework\Setup\UpgradeDataInterface;
14-
use Symfony\Component\Console\Helper\DebugFormatterHelper;
15-
use Symfony\Component\Console\Helper\FormatterHelper;
16-
use Symfony\Component\Console\Helper\HelperSet;
17-
use Symfony\Component\Console\Helper\ProcessHelper;
18-
use Symfony\Component\Console\Helper\QuestionHelper;
19-
use Symfony\Component\Console\Input\ArrayInput;
20-
use Symfony\Component\Console\Output\ConsoleOutput;
21-
use Symfony\Component\Console\Output\OutputInterface;
2212

2313
/**
2414
* Magento module hook to attach plugin installation functionality to `magento setup` operations
2515
*/
26-
class UpgradeData implements UpgradeDataInterface
16+
class UpgradeData extends AbstractModuleOperation implements UpgradeDataInterface
2717
{
2818
/**
2919
* Passthrough Magento setup command to check the plugin installation in the var directory
@@ -34,16 +24,6 @@ class UpgradeData implements UpgradeDataInterface
3424
*/
3525
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
3626
{
37-
$io = new ConsoleIO(new ArrayInput([]),
38-
new ConsoleOutput(OutputInterface::VERBOSITY_DEBUG),
39-
new HelperSet([
40-
new FormatterHelper(),
41-
new DebugFormatterHelper(),
42-
new ProcessHelper(),
43-
new QuestionHelper()
44-
])
45-
);
46-
$setupWizardInstaller = new WebSetupWizardPluginInstaller(new Console($io));
47-
$setupWizardInstaller->doVarInstall();
27+
$this->doVarInstall($setup, $context);
4828
}
4929
}

src/Magento/ComposerRootUpdatePlugin/Setup/WebSetupWizardPluginInstaller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function doVarInstall()
123123
* @param Composer $composer
124124
* @param string $filePath
125125
* @param string $pluginVersion
126-
* @return boolean
126+
* @return bool
127127
* @throws Exception
128128
*/
129129
public function updateSetupWizardPlugin($composer, $filePath, $pluginVersion)

0 commit comments

Comments
 (0)