-
Notifications
You must be signed in to change notification settings - Fork 9.4k
magento/magento2#23847: Command "setup:db-declaration:generate-patch" does not add revert() method to patch #23848
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
magento/magento2#23847: Command "setup:db-declaration:generate-patch" does not add revert() method to patch #23848
Conversation
Hi @atwixfirster. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atwixfirster, nice catch!
Could you please check the minor CR notices?
Please also check the automated test failures.
Thank you!
@@ -105,6 +95,7 @@ protected function execute(InputInterface $input, OutputInterface $output) : int | |||
{ | |||
$moduleName = $input->getArgument(self::MODULE_NAME); | |||
$patchName = $input->getArgument(self::INPUT_KEY_PATCH_NAME); | |||
$includeRevertMethod = ($input->getOption(self::INPUT_KEY_IS_REVERTABLE) == "true"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use strict comparison operator ===
.
Please also use single-quotes 'true'
to keep the same style within the same class unless three is no specific need to use double-quotes.
I would also recommend avoiding the usage of redundant parenthesis.
As for the implementation itself, I think, it should be possible to use the following condition:
if ($input->getOption(self:: INPUT_KEY_IS_REVERTABLE)) {
...
}
Please check other examples of \Symfony\Component\Console\Input\InputInterface::getOption
method usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -15,7 +15,7 @@ use Magento\Framework\Setup\ModuleDataSetupInterface; | |||
* Patch is mechanism, that allows to do atomic upgrade data changes | |||
*/ | |||
class %class% implements | |||
%patchInterface% | |||
%patchInterface%%patchRevertableInterface% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the %patchRevertableInterface% should be on a new line.
Here's an example of what I mean:
/**
* Wrapper for GraphQl NonNull
*/
class NonNull extends \GraphQL\Type\Definition\NonNull implements
WrappedTypeInterface,
InputTypeInterface,
OutputTypeInterface
{
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the %patchRevertableInterface% should be on a new line.
Not really, @dmytro-ch :)
%patchRevertableInterface%
is the alias of , PatchRevertableInterface
.
So, with the --revertable=true
flag a result will be:
class TestPatch implements
DataPatchInterface, PatchRevertableInterface
{
Without it:
class TestPatch implements
DataPatchInterface
{
So, I would like to leave this part as it is.
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that the PatchRevertableInterface
should be added on a new line.
Please, check the example above, it shows how the interfaces should be arranged.
According to PSR-2 coding style guide:
Lists of implements MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one interface per line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that the PatchRevertableInterface should be added on a new line.
done
Command 1:
bin/magento setup:db-declaration:generate-patch --revertable=true Magento_Cms TestPatch
Bash output 1:
Patch app/code/Magento/Cms/Setup/Patch/Data/TestPatch.php has been successfully generated.
Result 1:
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Cms\Setup\Patch\Data;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
/**
* Patch is mechanism, that allows to do atomic upgrade data changes
*/
class TestPatch implements
DataPatchInterface,
PatchRevertableInterface
{
/**
* @var ModuleDataSetupInterface $moduleDataSetup
*/
private $moduleDataSetup;
/**
* @param ModuleDataSetupInterface $moduleDataSetup
*/
public function __construct(ModuleDataSetupInterface $moduleDataSetup)
{
$this->moduleDataSetup = $moduleDataSetup;
}
/**
* Do Upgrade
*
* @return void
*/
public function apply()
{
}
/**
* @inheritdoc
*/
public function revert()
{
}
/**
* {@inheritdoc}
*/
public function getAliases()
{
return [];
}
/**
* {@inheritdoc}
*/
public static function getDependencies()
{
return [
];
}
}
Command 2:
bin/magento setup:db-declaration:generate-patch --revertable=false Magento_Cms TestPatch
Bash output 2:
Patch app/code/Magento/Cms/Setup/Patch/Data/TestPatch.php has been successfully generated.
Result 2:
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Cms\Setup\Patch\Data;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
/**
* Patch is mechanism, that allows to do atomic upgrade data changes
*/
class TestPatch implements DataPatchInterface
{
/**
* @var ModuleDataSetupInterface $moduleDataSetup
*/
private $moduleDataSetup;
/**
* @param ModuleDataSetupInterface $moduleDataSetup
*/
public function __construct(ModuleDataSetupInterface $moduleDataSetup)
{
$this->moduleDataSetup = $moduleDataSetup;
}
/**
* Do Upgrade
*
* @return void
*/
public function apply()
{
}
/**
* {@inheritdoc}
*/
public function getAliases()
{
return [];
}
/**
* {@inheritdoc}
*/
public static function getDependencies()
{
return [
];
}
}
Command 3:
bin/magento setup:db-declaration:generate-patch --revertable=true --type=schema Magento_Cms TestPatch
Bash output 3:
Patch app/code/Magento/Cms/Setup/Patch/Schema/TestPatch.php has been successfully generated.
Result 3:
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Cms\Setup\Patch\Schema;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
/**
* Patch is mechanism, that allows to do atomic upgrade data changes
*/
class TestPatch implements
SchemaPatchInterface,
PatchRevertableInterface
{
/**
* @var ModuleDataSetupInterface $moduleDataSetup
*/
private $moduleDataSetup;
/**
* @param ModuleDataSetupInterface $moduleDataSetup
*/
public function __construct(ModuleDataSetupInterface $moduleDataSetup)
{
$this->moduleDataSetup = $moduleDataSetup;
}
/**
* Do Upgrade
*
* @return void
*/
public function apply()
{
}
/**
* @inheritdoc
*/
public function revert()
{
}
/**
* {@inheritdoc}
*/
public function getAliases()
{
return [];
}
/**
* {@inheritdoc}
*/
public static function getDependencies()
{
return [
];
}
}
Command 4:
bin/magento setup:db-declaration:generate-patch --revertable=false --type=schema Magento_Cms TestPatch
Bash output 4:
Patch app/code/Magento/Cms/Setup/Patch/Schema/TestPatch.php has been successfully generated.
Result 4:
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Cms\Setup\Patch\Schema;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
/**
* Patch is mechanism, that allows to do atomic upgrade data changes
*/
class TestPatch implements SchemaPatchInterface
{
/**
* @var ModuleDataSetupInterface $moduleDataSetup
*/
private $moduleDataSetup;
/**
* @param ModuleDataSetupInterface $moduleDataSetup
*/
public function __construct(ModuleDataSetupInterface $moduleDataSetup)
{
$this->moduleDataSetup = $moduleDataSetup;
}
/**
* Do Upgrade
*
* @return void
*/
public function apply()
{
}
/**
* {@inheritdoc}
*/
public function getAliases()
{
return [];
}
/**
* {@inheritdoc}
*/
public static function getDependencies()
{
return [
];
}
}
fixed |
@atwixfirster, thank you for the fixes! |
b84e3b7
to
2a62f1c
Compare
Hi @atwixfirster, thank you for your contribution! |
… add revert() method to patch
Hi @atwixfirster. Thank you for your contribution
In case you'd like to rerun tests use the following comments:
For more details, please, review the Magento Contributor Guide documentation. |
@atwixfirster unfortunately, only members of the maintainers team are allowed to assign developers to the pull request |
done Thank you, @dmytro-ch 👍 |
@atwixfirster unfortunately, only members of the maintainers team are allowed to assign developers to the pull request |
Hi @dmytro-ch, thank you for the review. |
During testing we faced the issue Problem: Steps to reproduce:
Actual Result: class TestPatch implements
@atwixfirster Could you take a look, please? Thanks! |
Let me please explain. If So, the key here is
Please let me know you you have any additional questions here. |
…es not add revert() method to patch #23848
Hi @atwixfirster, thank you for your contribution! |
Description (*)
Fixed Issues (if relevant)
Manual testing scenarios (*)
Example with
Magento_Cms
:Actual result:
app/code/Magento/Cms/Setup/Patch/Data/TestPatch.php
is created with content withoutrevert()
method:Expected result:
app/code/Magento/Cms/Setup/Patch/Data/TestPatch.php
is created withrevert()
method in the content:Questions or comments
Contribution checklist (*)