Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bin/ece-patches
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
define('IS_CLOUD', true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant since ApplicationEce already Cloud-aware

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but there is CloudCollector service that is used by both applications and we need to define what is the environment to set patch type optional or required https://github.com/magento-mpi/magento-cloud-patches/blob/65837e0a187dfa282e47be67c7dc1cd349643709/src/Patch/Collector/CloudCollector.php#L94

$container = require __DIR__ . '/../bootstrap.php';

$application = new Magento\CloudPatches\Application($container);
$application = new Magento\CloudPatches\ApplicationEce($container);
$application->run();
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "magento/magento-cloud-patches",
"description": "Provides critical fixes for Magento 2 Enterprise Edition",
"type": "magento2-component",
"version": "1.0.5",
"version": "1.0.6",
"license": "OSL-3.0",
"require": {
"php": "^7.0",
Expand All @@ -14,6 +14,7 @@
"symfony/dependency-injection": "^3.3||^4.3",
"symfony/process": "^2.1||^4.1",
"symfony/proxy-manager-bridge": "^3.3||^4.3",
"symfony/yaml": "^3.3||^4.0",
"monolog/monolog": "^1.16",
"magento/quality-patches": "^1.0.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes circular dependency and must be moved to another package

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The packages have a dependency on each other and the composer resolves them without issues. Why it should be moved?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having circular dependency is never good idea, in some cases, it lead to neverending dependency resolving and other problems. This may be either included in ECE-Tools or MCC

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And circular dependency consieded as "bad smell" from Architecture Design standpoint

Copy link
Contributor Author

@viktym viktym Jul 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having circular dependency is never good idea, in some cases, it lead to neverending dependency resolving and other problems. This may be either included in ECE-Tools or MCC

I agree with you, in case of recursive read it can lead to neverending resolving.
In the current case we A => B and B => A. Composer resolves it well.
Otherway, if we move dependency on quality-patches to ece-tools, it will be impossible to install magento-cloud-patches from the composer separately, as described in docs
P.S. It will be possible, but impossible to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"magento/quality-patches" dependency was moved to suggest section
@shiftedreality please review

},
Expand Down
26 changes: 13 additions & 13 deletions config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<service id="Psr\Log\LoggerInterface" alias="Magento\CloudPatches\App\Logger" />
<service id="Magento\CloudPatches\App\Container" autowire="false"/>
<service id="Magento\CloudPatches\Filesystem\DirectoryList" autowire="false"/>
<service id="Magento\QualityPatches\Info"/>
<service id="Symfony\Component\Console\Helper\QuestionHelper"/>
<service id="Composer\Composer"/>
<service id="Magento\CloudPatches\App\GenericException" autowire="false"/>
Expand All @@ -28,11 +27,6 @@
<service id="Magento\CloudPatches\Patch\Pool\RequiredPool" lazy="true"/>
<service id="Magento\CloudPatches\Patch\Pool\LocalPool" lazy="true"/>
<service id="Magento\CloudPatches\Patch\Status\StatusPool" autowire="false"/>
<service id="statusOptionalPool" class="Magento\CloudPatches\Patch\Status\StatusPool" lazy="true">
<argument key="$resolvers" type="collection">
<argument type="service" id="Magento\CloudPatches\Patch\Status\OptionalResolver"/>
</argument>
</service>
<service id="statusPool" class="Magento\CloudPatches\Patch\Status\StatusPool" lazy="true">
<argument key="$resolvers" type="collection">
<argument type="service" id="Magento\CloudPatches\Patch\Status\LocalResolver"/>
Expand All @@ -42,26 +36,29 @@
<service id="Magento\CloudPatches\Command\Process\ShowStatus">
<argument key="$statusPool" type="service" id="statusPool"/>
</service>
<service id="Magento\CloudPatches\Command\Process\Ece\Revert">
<argument key="$statusPool" type="service" id="statusPool"/>
</service>
<service id="Magento\CloudPatches\Command\Process\Action\ApplyOptionalAction">
<argument key="$statusPool" type="service" id="statusOptionalPool"/>
<argument key="$statusPool" type="service" id="statusPool"/>
</service>
<service id="Magento\CloudPatches\Command\Process\Action\RevertAction">
<argument key="$statusPool" type="service" id="statusOptionalPool"/>
<argument key="$statusPool" type="service" id="statusPool"/>
</service>
<service id="Magento\CloudPatches\Command\Process\Action\ConfirmRequiredAction">
<argument key="$statusPool" type="service" id="statusOptionalPool"/>
<argument key="$statusPool" type="service" id="statusPool"/>
</service>
<service id="Magento\CloudPatches\Command\Process\Action\ProcessDeprecatedAction">
<argument key="$statusPool" type="service" id="statusOptionalPool"/>
<argument key="$statusPool" type="service" id="statusPool"/>
</service>
<service id="Magento\CloudPatches\Command\Process\Action\ReviewAppliedAction">
<argument key="$statusPool" type="service" id="statusOptionalPool"/>
<argument key="$statusPool" type="service" id="statusPool"/>
</service>
<service id="Magento\CloudPatches\Patch\RevertValidator">
<argument key="$statusPool" type="service" id="statusOptionalPool"/>
<argument key="$statusPool" type="service" id="statusPool"/>
</service>
<service id="Magento\CloudPatches\Command\Process\Renderer">
<argument key="$statusPool" type="service" id="statusOptionalPool"/>
<argument key="$statusPool" type="service" id="statusPool"/>
</service>
<service id="Magento\CloudPatches\Command\Process\Action\ActionPool" autowire="false"/>
<service id="ApplyOptionalActionPool" class="Magento\CloudPatches\Command\Process\Action\ActionPool">
Expand All @@ -75,6 +72,9 @@
<service id="Magento\CloudPatches\Command\Process\ApplyOptional">
<argument key="$actionPool" type="service" id="ApplyOptionalActionPool"/>
</service>
<service id="Magento\CloudPatches\Command\Process\Ece\ApplyOptional">
<argument key="$actionPool" type="service" id="ApplyOptionalActionPool"/>
</service>
<service id="Magento\CloudPatches\Patch\PatchBuilder" shared="false"/>
</services>
</container>
48 changes: 48 additions & 0 deletions src/ApplicationEce.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CloudPatches;

use Composer\Composer;
use Magento\CloudPatches\Command;
use Psr\Container\ContainerInterface;

/**
* @inheritdoc
*/
class ApplicationEce extends \Symfony\Component\Console\Application
{
/**
* @var ContainerInterface
*/
private $container;

/**
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;

parent::__construct(
$container->get(Composer::class)->getPackage()->getPrettyName(),
$container->get(Composer::class)->getPackage()->getPrettyVersion()
);
}

/**
* @inheritdoc
*/
protected function getDefaultCommands()
{
return array_merge(parent::getDefaultCommands(), [
$this->container->get(Command\Ece\Apply::class),
$this->container->get(Command\Ece\Revert::class),
$this->container->get(Command\Status::class)
]);
}
}
68 changes: 8 additions & 60 deletions src/Command/Apply.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@
namespace Magento\CloudPatches\Command;

use Magento\CloudPatches\App\RuntimeException;
use Magento\CloudPatches\Command\Process\ApplyLocal;
use Magento\CloudPatches\Command\Process\ApplyOptional;
use Magento\CloudPatches\Command\Process\ApplyRequired;
use Magento\CloudPatches\Composer\MagentoVersion;
use Magento\CloudPatches\Patch\Environment;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Patch apply command.
* Patch apply command (OnPrem).
*/
class Apply extends AbstractCommand
{
Expand All @@ -30,35 +26,15 @@ class Apply extends AbstractCommand
const NAME = 'apply';

/**
* Defines whether Magento is installed from Git.
* List of patches to apply.
*/
const OPT_GIT_INSTALLATION = 'git-installation';

/**
* List of quality patches to apply.
*/
const ARG_QUALITY_PATCHES = 'quality-patches';
const ARG_LIST_OF_PATCHES = 'list-of-patches';

/**
* @var ApplyOptional
*/
private $applyOptional;

/**
* @var ApplyRequired
*/
private $applyRequired;

/**
* @var ApplyLocal
*/
private $applyLocal;

/**
* @var Environment
*/
private $environment;

/**
* @var LoggerInterface
*/
Expand All @@ -70,25 +46,16 @@ class Apply extends AbstractCommand
private $magentoVersion;

/**
* @param ApplyRequired $applyRequired
* @param ApplyOptional $applyOptional
* @param ApplyLocal $applyLocal
* @param Environment $environment
* @param LoggerInterface $logger
* @param MagentoVersion $magentoVersion
*/
public function __construct(
ApplyRequired $applyRequired,
ApplyOptional $applyOptional,
ApplyLocal $applyLocal,
Environment $environment,
LoggerInterface $logger,
MagentoVersion $magentoVersion
) {
$this->applyRequired = $applyRequired;
$this->applyOptional = $applyOptional;
$this->applyLocal = $applyLocal;
$this->environment = $environment;
$this->logger = $logger;
$this->magentoVersion = $magentoVersion;

Expand All @@ -101,17 +68,11 @@ public function __construct(
protected function configure()
{
$this->setName(self::NAME)
->setDescription('Apply patches')
->setDescription('Applies patches. The list of patches should pass as a command argument')
->addArgument(
self::ARG_QUALITY_PATCHES,
InputArgument::IS_ARRAY,
'List of quality patches to apply'
)->addOption(
self::OPT_GIT_INSTALLATION,
null,
InputOption::VALUE_OPTIONAL,
'Is git installation',
false
self::ARG_LIST_OF_PATCHES,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is BC change, it should not go into patch version release

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a new command - ./magento-patches apply,
./ece-patches apply remains without changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shiftedreality or you mean removing of --git-installation option?
Previously we discussed this with Bohdan and Olexandr, agreed that we can just not call ./ece-patch apply command from ece-tools in case of git installation

InputArgument::IS_ARRAY | InputArgument::REQUIRED,
'List of patches to apply'
);

parent::configure();
Expand All @@ -122,23 +83,10 @@ protected function configure()
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$deployedFromGit = $input->getOption(Apply::OPT_GIT_INSTALLATION);
if ($deployedFromGit) {
$output->writeln('<info>Git-based installation. Skipping patches applying.</info>');

return self::RETURN_SUCCESS;
}

$this->logger->notice($this->magentoVersion->get());

try {
if ($this->environment->isCloud()) {
$this->applyRequired->run($input, $output);
$this->applyOptional->run($input, $output);
$this->applyLocal->run($input, $output);
} else {
$this->applyOptional->run($input, $output);
}
$this->applyOptional->run($input, $output);
} catch (RuntimeException $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
$this->logger->error($e->getMessage());
Expand Down
113 changes: 113 additions & 0 deletions src/Command/Ece/Apply.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CloudPatches\Command\Ece;

use Magento\CloudPatches\App\RuntimeException;
use Magento\CloudPatches\Command\AbstractCommand;
use Magento\CloudPatches\Command\Process\ApplyLocal;
use Magento\CloudPatches\Command\Process\Ece\ApplyOptional;
use Magento\CloudPatches\Command\Process\ApplyRequired;
use Magento\CloudPatches\Composer\MagentoVersion;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Patch apply command (Cloud).
*/
class Apply extends AbstractCommand
{
/**
* Command name.
*/
const NAME = 'apply';

/**
* @var ApplyOptional
*/
private $applyOptional;

/**
* @var ApplyRequired
*/
private $applyRequired;

/**
* @var ApplyLocal
*/
private $applyLocal;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @var MagentoVersion
*/
private $magentoVersion;

/**
* @param ApplyRequired $applyRequired
* @param ApplyOptional $applyOptional
* @param ApplyLocal $applyLocal
* @param LoggerInterface $logger
* @param MagentoVersion $magentoVersion
*/
public function __construct(
ApplyRequired $applyRequired,
ApplyOptional $applyOptional,
ApplyLocal $applyLocal,
LoggerInterface $logger,
MagentoVersion $magentoVersion
) {
$this->applyRequired = $applyRequired;
$this->applyOptional = $applyOptional;
$this->applyLocal = $applyLocal;
$this->logger = $logger;
$this->magentoVersion = $magentoVersion;

parent::__construct(self::NAME);
}

/**
* @inheritDoc
*/
protected function configure()
{
$this->setName(self::NAME)
->setDescription('Applies patches (Magento Cloud only)');

parent::configure();
}

/**
* @inheritDoc
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$this->logger->notice($this->magentoVersion->get());

try {
$this->applyRequired->run($input, $output);
$this->applyOptional->run($input, $output);
$this->applyLocal->run($input, $output);
} catch (RuntimeException $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
$this->logger->error($e->getMessage());

return self::RETURN_FAILURE;
} catch (\Exception $e) {
$this->logger->critical($e);

throw $e;
}

return self::RETURN_SUCCESS;
}
}
Loading