Skip to content

Commit be50c80

Browse files
committed
Merge branch 'mainline-eav-attr-code-genearators' into eav-generator-refactoring
2 parents 8e98626 + 4078a6b commit be50c80

File tree

9 files changed

+206
-210
lines changed

9 files changed

+206
-210
lines changed

resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ class ${CLASS_NAME} implements ${IMPLEMENTS} {
2323
private $eavSetupFactory;
2424

2525
/**
26-
* AddRecommendedAttribute constructor.
27-
*
2826
* @param ${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup
2927
* @param ${EAV_SETUP_FACTORY} $eavSetupFactory
3028
*/
@@ -36,6 +34,32 @@ class ${CLASS_NAME} implements ${IMPLEMENTS} {
3634
$this->eavSetupFactory = $eavSetupFactory;
3735
}
3836

37+
/**
38+
* Run code inside patch
39+
* If code fails, patch must be reverted, in case when we are speaking about schema - then under revert
40+
* means run PatchInterface::revert()
41+
*
42+
* If we speak about data, under revert means: $transaction->rollback()
43+
*
44+
* @return $this
45+
*/
46+
public function apply()
47+
{
48+
/** @var ${EAV_SETUP} $eavSetup */
49+
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
50+
51+
$eavSetup->addAttribute(
52+
${ENTITY_CLASS}::ENTITY,
53+
'${ATTRIBUTE_CODE}',
54+
[
55+
#set ($attributeSet = ${ATTRIBUTE_SET})
56+
#foreach ($attribute in $attributeSet.split("->"))
57+
$attribute
58+
#end
59+
]
60+
);
61+
}
62+
3963
/**
4064
* Get array of patches that have to be executed prior to this.
4165
*
@@ -62,30 +86,4 @@ class ${CLASS_NAME} implements ${IMPLEMENTS} {
6286
{
6387
return [];
6488
}
65-
66-
/**
67-
* Run code inside patch
68-
* If code fails, patch must be reverted, in case when we are speaking about schema - then under revert
69-
* means run PatchInterface::revert()
70-
*
71-
* If we speak about data, under revert means: $transaction->rollback()
72-
*
73-
* @return $this
74-
*/
75-
public function apply()
76-
{
77-
/** @var ${EAV_SETUP} $eavSetup */
78-
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
79-
80-
$eavSetup->addAttribute(
81-
${ENTITY_CLASS}::ENTITY,
82-
'${ATTRIBUTE_CODE}',
83-
[
84-
#set ($attributeSet = ${ATTRIBUTE_SET})
85-
#foreach ($attribute in $attributeSet.split("->"))
86-
$attribute
87-
#end
88-
]
89-
);
90-
}
9189
}

src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,14 @@ protected void fillAttributes(final Properties attributes) {
6868
"IMPLEMENTS",
6969
DataPatchDependency.DATA_PATCH_INTERFACE.getClassPatch()
7070
)
71+
.append(
72+
"ENTITY_CLASS",
73+
data.getEntityClass()
74+
)
7175
.append(
7276
"MODULE_DATA_SETUP_INTERFACE",
73-
DataPatchDependency.MODULE_DATA_SETUP_INTERFACE.getClassPatch())
77+
DataPatchDependency.MODULE_DATA_SETUP_INTERFACE.getClassPatch()
78+
)
7479
.append(
7580
"EAV_SETUP_FACTORY",
7681
DataPatchDependency.EAV_SETUP_FACTORY.getClassPatch()

src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
package com.magento.idea.magento2plugin.magento.packages.eav;
77

88
public enum EavEntity {
9-
PRODUCT("\\Magento\\Catalog\\Model\\Product"),
10-
CATEGORY("\\Magento\\Catalog\\Model\\Category");
9+
PRODUCT("Magento\\Catalog\\Model\\Product"),
10+
CATEGORY("Magento\\Catalog\\Model\\Category");
1111

1212
private String entityClass;
1313

testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFile/AddTestAttributeCategoryAttribute.php

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ class AddTestAttributeCategoryAttribute implements DataPatchInterface
2121
private $eavSetupFactory;
2222

2323
/**
24-
* AddRecommendedAttribute constructor.
25-
*
2624
* @param ModuleDataSetupInterface $moduleDataSetup
2725
* @param EavSetupFactory $eavSetupFactory
2826
*/
@@ -35,33 +33,6 @@ public function __construct(
3533
$this->eavSetupFactory = $eavSetupFactory;
3634
}
3735

38-
/**
39-
* Get array of patches that have to be executed prior to this.
40-
*
41-
* Example of implementation:
42-
*
43-
* [
44-
* \Vendor_Name\Module_Name\Setup\Patch\Patch1::class,
45-
* \Vendor_Name\Module_Name\Setup\Patch\Patch2::class
46-
* ]
47-
*
48-
* @return string[]
49-
*/
50-
public static function getDependencies()
51-
{
52-
return [];
53-
}
54-
55-
/**
56-
* Get aliases (previous names) for the patch.
57-
*
58-
* @return string[]
59-
*/
60-
public function getAliases()
61-
{
62-
return [];
63-
}
64-
6536
/**
6637
* Run code inside patch
6738
* If code fails, patch must be reverted, in case when we are speaking about schema - then under revert
@@ -92,4 +63,31 @@ public function apply()
9263
]
9364
);
9465
}
66+
67+
/**
68+
* Get array of patches that have to be executed prior to this.
69+
*
70+
* Example of implementation:
71+
*
72+
* [
73+
* \Vendor_Name\Module_Name\Setup\Patch\Patch1::class,
74+
* \Vendor_Name\Module_Name\Setup\Patch\Patch2::class
75+
* ]
76+
*
77+
* @return string[]
78+
*/
79+
public static function getDependencies()
80+
{
81+
return [];
82+
}
83+
84+
/**
85+
* Get aliases (previous names) for the patch.
86+
*
87+
* @return string[]
88+
*/
89+
public function getAliases()
90+
{
91+
return [];
92+
}
9593
}

testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFile/AddTestAttribute.php

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Foo\Bar\Setup\Patch\Data;
44

5+
use Magento\Catalog\Model\Product;
56
use Magento\Eav\Setup\EavSetup;
67
use Magento\Eav\Setup\EavSetupFactory;
78
use Magento\Framework\Setup\ModuleDataSetupInterface;
@@ -21,8 +22,6 @@ class AddTestAttribute implements DataPatchInterface
2122
private $eavSetupFactory;
2223

2324
/**
24-
* AddRecommendedAttribute constructor.
25-
*
2625
* @param ModuleDataSetupInterface $moduleDataSetup
2726
* @param EavSetupFactory $eavSetupFactory
2827
*/
@@ -35,33 +34,6 @@ public function __construct(
3534
$this->eavSetupFactory = $eavSetupFactory;
3635
}
3736

38-
/**
39-
* Get array of patches that have to be executed prior to this.
40-
*
41-
* Example of implementation:
42-
*
43-
* [
44-
* \Vendor_Name\Module_Name\Setup\Patch\Patch1::class,
45-
* \Vendor_Name\Module_Name\Setup\Patch\Patch2::class
46-
* ]
47-
*
48-
* @return string[]
49-
*/
50-
public static function getDependencies()
51-
{
52-
return [];
53-
}
54-
55-
/**
56-
* Get aliases (previous names) for the patch.
57-
*
58-
* @return string[]
59-
*/
60-
public function getAliases()
61-
{
62-
return [];
63-
}
64-
6537
/**
6638
* Run code inside patch
6739
* If code fails, patch must be reverted, in case when we are speaking about schema - then under revert
@@ -77,7 +49,7 @@ public function apply()
7749
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
7850

7951
$eavSetup->addAttribute(
80-
\Magento\Catalog\Model\Product::ENTITY,
52+
Product::ENTITY,
8153
'test',
8254
[
8355
'is_visible_in_grid' => false,
@@ -97,4 +69,31 @@ public function apply()
9769
]
9870
);
9971
}
72+
73+
/**
74+
* Get array of patches that have to be executed prior to this.
75+
*
76+
* Example of implementation:
77+
*
78+
* [
79+
* \Vendor_Name\Module_Name\Setup\Patch\Patch1::class,
80+
* \Vendor_Name\Module_Name\Setup\Patch\Patch2::class
81+
* ]
82+
*
83+
* @return string[]
84+
*/
85+
public static function getDependencies()
86+
{
87+
return [];
88+
}
89+
90+
/**
91+
* Get aliases (previous names) for the patch.
92+
*
93+
* @return string[]
94+
*/
95+
public function getAliases()
96+
{
97+
return [];
98+
}
10099
}

testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Foo\Bar\Setup\Patch\Data;
44

5+
use Magento\Catalog\Model\Product;
56
use Magento\Eav\Setup\EavSetup;
67
use Magento\Eav\Setup\EavSetupFactory;
78
use Magento\Framework\Setup\ModuleDataSetupInterface;
@@ -21,8 +22,6 @@ class AddAppliedToAttribute implements DataPatchInterface
2122
private $eavSetupFactory;
2223

2324
/**
24-
* AddRecommendedAttribute constructor.
25-
*
2625
* @param ModuleDataSetupInterface $moduleDataSetup
2726
* @param EavSetupFactory $eavSetupFactory
2827
*/
@@ -35,33 +34,6 @@ public function __construct(
3534
$this->eavSetupFactory = $eavSetupFactory;
3635
}
3736

38-
/**
39-
* Get array of patches that have to be executed prior to this.
40-
*
41-
* Example of implementation:
42-
*
43-
* [
44-
* \Vendor_Name\Module_Name\Setup\Patch\Patch1::class,
45-
* \Vendor_Name\Module_Name\Setup\Patch\Patch2::class
46-
* ]
47-
*
48-
* @return string[]
49-
*/
50-
public static function getDependencies()
51-
{
52-
return [];
53-
}
54-
55-
/**
56-
* Get aliases (previous names) for the patch.
57-
*
58-
* @return string[]
59-
*/
60-
public function getAliases()
61-
{
62-
return [];
63-
}
64-
6537
/**
6638
* Run code inside patch
6739
* If code fails, patch must be reverted, in case when we are speaking about schema - then under revert
@@ -77,7 +49,7 @@ public function apply()
7749
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
7850

7951
$eavSetup->addAttribute(
80-
\Magento\Catalog\Model\Product::ENTITY,
52+
Product::ENTITY,
8153
'applied_to_attribute',
8254
[
8355
'is_visible_in_grid' => false,
@@ -98,4 +70,31 @@ public function apply()
9870
]
9971
);
10072
}
73+
74+
/**
75+
* Get array of patches that have to be executed prior to this.
76+
*
77+
* Example of implementation:
78+
*
79+
* [
80+
* \Vendor_Name\Module_Name\Setup\Patch\Patch1::class,
81+
* \Vendor_Name\Module_Name\Setup\Patch\Patch2::class
82+
* ]
83+
*
84+
* @return string[]
85+
*/
86+
public static function getDependencies()
87+
{
88+
return [];
89+
}
90+
91+
/**
92+
* Get aliases (previous names) for the patch.
93+
*
94+
* @return string[]
95+
*/
96+
public function getAliases()
97+
{
98+
return [];
99+
}
101100
}

0 commit comments

Comments
 (0)