File tree 7 files changed +49
-20
lines changed
resources/fileTemplates/internal
src/com/magento/idea/magento2plugin
testData/actions/generation/generator/ModuleSetupDataPatchGenerator/generateModuleSetupDataPatchFile
tests/com/magento/idea/magento2plugin/actions/generation/generator
7 files changed +49
-20
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ use Magento\Framework\Setup\ModuleDataSetupInterface;
7
7
use Magento\Framework\Setup\Patch\DataPatchInterface;
8
8
9
9
/**
10
- * Patch is mechanism, that allows to do atomic upgrade data changes
10
+ * Patch is mechanism, that allows to do atomic upgrade data changes.
11
11
*/
12
12
class ${CLASS_NAME} implements DataPatchInterface
13
13
{
@@ -26,7 +26,7 @@ class ${CLASS_NAME} implements DataPatchInterface
26
26
}
27
27
28
28
/**
29
- * Do Upgrade
29
+ * Do Upgrade.
30
30
*
31
31
* @return void
32
32
*/
Original file line number Diff line number Diff line change 56
56
<grid id =" ad0b1" layout-manager =" GridLayoutManager" row-count =" 2" column-count =" 2" same-size-horizontally =" false" same-size-vertically =" false" hgap =" -1" vgap =" -1" >
57
57
<margin top =" 0" left =" 0" bottom =" 0" right =" 0" />
58
58
<constraints >
59
- <grid row =" 0" column =" 0" row-span =" 1" col-span =" 1" vsize-policy =" 3 " hsize-policy =" 3" anchor =" 0 " fill =" 3 " indent =" 0" use-parent-layout =" false" />
59
+ <grid row =" 0" column =" 0" row-span =" 1" col-span =" 1" vsize-policy =" 0 " hsize-policy =" 3" anchor =" 1 " fill =" 1 " indent =" 0" use-parent-layout =" false" />
60
60
</constraints >
61
61
<properties />
62
62
<border type =" none" />
71
71
</component >
72
72
<component id =" 662ad" class =" javax.swing.JLabel" binding =" classNameLabel" >
73
73
<constraints >
74
- <grid row =" 0" column =" 0" row-span =" 1" col-span =" 1" vsize-policy =" 0" hsize-policy =" 0" anchor =" 8" fill =" 0" indent =" 0" use-parent-layout =" false" >
75
- <preferred-size width =" 113" height =" 16" />
76
- </grid >
74
+ <grid row =" 0" column =" 0" row-span =" 1" col-span =" 1" vsize-policy =" 0" hsize-policy =" 0" anchor =" 8" fill =" 0" indent =" 0" use-parent-layout =" false" />
77
75
</constraints >
78
76
<properties >
79
77
<text value =" Class Name" />
80
78
</properties >
81
79
</component >
82
80
<component id =" 292c" class =" javax.swing.JTextField" binding =" className" >
83
81
<constraints >
84
- <grid row =" 0" column =" 1" row-span =" 1" col-span =" 1" vsize-policy =" 0" hsize-policy =" 6" anchor =" 8" fill =" 1" indent =" 0" use-parent-layout =" false" >
85
- <preferred-size width =" 150" height =" -1" />
86
- </grid >
82
+ <grid row =" 0" column =" 1" row-span =" 1" col-span =" 1" vsize-policy =" 0" hsize-policy =" 6" anchor =" 8" fill =" 1" indent =" 0" use-parent-layout =" false" />
87
83
</constraints >
88
84
<properties />
89
85
</component >
Original file line number Diff line number Diff line change @@ -142,7 +142,7 @@ private void generateFile() {
142
142
}
143
143
144
144
public String getClassName () {
145
- return className .getText ();
145
+ return className .getText (). trim () ;
146
146
}
147
147
148
148
private boolean validateFields () {
@@ -151,10 +151,14 @@ private boolean validateFields() {
151
151
if (NewSetupDataPatchAction .DATA_DIRECTORY .equals (targetDirectory .getName ())) {
152
152
final PsiFile [] files = targetDirectory .getFiles ();
153
153
for (final PsiFile file : files ) {
154
- if (file .getName ().equals (getClassName () + ModuleSetupDataPatchFile .FILE_NAME )) {
154
+ final String className = ModuleSetupDataPatchFile .resolveClassNameFromInput (
155
+ getClassName ()
156
+ );
157
+
158
+ if (file .getName ().equals (className + ".php" )) {
155
159
showErrorMessage (
156
160
fieldsValidationsList .get (0 ).getField (),
157
- "Class name " + getClassName () + " already exist."
161
+ "Class name ` " + className + "` already exist."
158
162
);
159
163
160
164
return false ;
Original file line number Diff line number Diff line change @@ -57,7 +57,9 @@ public PsiFile generate(final String actionName) {
57
57
*/
58
58
@ Override
59
59
protected void fillAttributes (final Properties attributes ) {
60
- attributes .setProperty ("CLASS_NAME" , moduleSetupPatchData .getClassName () + "Patch" );
60
+ attributes .setProperty ("CLASS_NAME" , ModuleSetupDataPatchFile .resolveClassNameFromInput (
61
+ moduleSetupPatchData .getClassName ()
62
+ ));
61
63
attributes .setProperty (
62
64
"MODULE_NAME" ,
63
65
moduleSetupPatchData .getPackageName () + "\\ " + moduleSetupPatchData .getModuleName ()
Original file line number Diff line number Diff line change 11
11
12
12
public class ModuleSetupDataPatchFile implements ModuleFileInterface {
13
13
14
- public static final String FILE_NAME = "Patch.php" ;
14
+ public static final String FILE_SUFFIX = "Patch" ;
15
+ public static final String EXTENSION = ".php" ;
15
16
public static final String TEMPLATE = "Magento Module Setup Patch File" ;
16
17
private final String className ;
17
18
19
+ /**
20
+ * Constructor.
21
+ *
22
+ * @param className String
23
+ */
18
24
public ModuleSetupDataPatchFile (
19
25
final @ NotNull String className
20
26
) {
21
- this .className = className ;
27
+ this .className = resolveClassNameFromInput (className );
28
+ }
29
+
30
+ /**
31
+ * Resolve class name from user input.
32
+ *
33
+ * @param input String
34
+ *
35
+ * @return String
36
+ */
37
+ public static String resolveClassNameFromInput (final String input ) {
38
+ if (input .length () <= FILE_SUFFIX .length ()) {
39
+ return input + FILE_SUFFIX ;
40
+ }
41
+ String suffix = input .substring (input .length () - FILE_SUFFIX .length ());
42
+
43
+ if (FILE_SUFFIX .equals (suffix )) {
44
+ return input ;
45
+ } else {
46
+ return input + FILE_SUFFIX ;
47
+ }
22
48
}
23
49
24
50
@ Override
25
51
public String getFileName () {
26
- return className + FILE_NAME ;
52
+ return className + EXTENSION ;
27
53
}
28
54
29
55
@ Override
Original file line number Diff line number Diff line change 6
6
use Magento \Framework \Setup \Patch \DataPatchInterface ;
7
7
8
8
/**
9
- * Patch is mechanism, that allows to do atomic upgrade data changes
9
+ * Patch is mechanism, that allows to do atomic upgrade data changes.
10
10
*/
11
11
class TestClassPatch implements DataPatchInterface
12
12
{
@@ -26,7 +26,7 @@ public function __construct(
26
26
}
27
27
28
28
/**
29
- * Do Upgrade
29
+ * Do Upgrade.
30
30
*
31
31
* @return void
32
32
*/
Original file line number Diff line number Diff line change 10
10
import com .magento .idea .magento2plugin .magento .files .ModuleSetupDataPatchFile ;
11
11
12
12
public final class ModuleSetupDataPatchGeneratorTest extends BaseGeneratorTestCase {
13
- private static final String CLASS_NAME = "TestClass" ;
13
+
14
+ private static final String CLASS_NAME = "TestClassPatch" ;
14
15
15
16
/**
16
17
* Test module README.md file generation.
17
18
*/
18
19
public void testGenerateModuleSetupDataPatchFile () {
19
20
final PsiFile expectedFile = myFixture .configureByFile (
20
- getFixturePath (CLASS_NAME + ModuleSetupDataPatchFile .FILE_NAME )
21
+ getFixturePath (CLASS_NAME + ModuleSetupDataPatchFile .EXTENSION )
21
22
);
22
23
final ModuleSetupDataPatchGenerator generator = new ModuleSetupDataPatchGenerator (
23
24
new ModuleSetupDataPatchData (
You can’t perform that action at this time.
0 commit comments