Skip to content

Commit 0f0fd3b

Browse files
committed
[#267]_fix setup_version
1 parent 7752099 commit 0f0fd3b

File tree

5 files changed

+93
-14
lines changed

5 files changed

+93
-14
lines changed
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
33
#if (${SEQUENCES})
4-
<module name="${PACKAGE}_${MODULE_NAME}" setup_version="${SETUP_VERSION}">
5-
<sequence>
6-
${SEQUENCES}
7-
</sequence>
8-
</module>
4+
#if (${SETUP_VERSION})
5+
<module name="${PACKAGE}_${MODULE_NAME}" setup_version="${SETUP_VERSION}">
6+
<sequence>
7+
${SEQUENCES}
8+
</sequence>
9+
</module>
10+
#else
11+
<module name="${PACKAGE}_${MODULE_NAME}">
12+
<sequence>
13+
${SEQUENCES}
14+
</sequence>
15+
</module>
16+
#end
917
#else
10-
<module name="${PACKAGE}_${MODULE_NAME}" setup_version="${SETUP_VERSION}"/>
18+
#if (${SETUP_VERSION})
19+
<module name="${PACKAGE}_${MODULE_NAME}" setup_version="${SETUP_VERSION}"/>
20+
#else
21+
<module name="${PACKAGE}_${MODULE_NAME}"/>
22+
#end
1123
#end
1224
</config>

src/com/magento/idea/magento2plugin/actions/generation/data/ModuleXmlData.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public class ModuleXmlData {
1111
private final String packageName;
1212
private final String moduleName;
13-
private final String moduleVersion;
13+
private final String setupVersion;
1414
private final PsiDirectory baseDir;
1515
private final boolean createModuleDirs;
1616

@@ -19,20 +19,20 @@ public class ModuleXmlData {
1919
*
2020
* @param packageName Package name
2121
* @param moduleName Module name
22-
* @param moduleVersion Module version
22+
* @param setupVersion Setup version
2323
* @param baseDir Base directory
2424
* @param createModuleDirs Create module Dirs
2525
*/
2626
public ModuleXmlData(
2727
final String packageName,
2828
final String moduleName,
29-
final String moduleVersion,
29+
final String setupVersion,
3030
final PsiDirectory baseDir,
3131
final boolean createModuleDirs
3232
) {
3333
this.packageName = packageName;
3434
this.moduleName = moduleName;
35-
this.moduleVersion = moduleVersion;
35+
this.setupVersion = setupVersion;
3636
this.baseDir = baseDir;
3737
this.createModuleDirs = createModuleDirs;
3838
}
@@ -49,8 +49,8 @@ public PsiDirectory getBaseDir() {
4949
return this.baseDir;
5050
}
5151

52-
public String getModuleVersion() {
53-
return this.moduleVersion;
52+
public String getSetupVersion() {
53+
return this.setupVersion;
5454
}
5555

5656
public boolean getCreateModuleDirs() {

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.magento.idea.magento2plugin.magento.packages.Package;
2323
import com.magento.idea.magento2plugin.project.Settings;
2424
import com.magento.idea.magento2plugin.util.CamelCaseToHyphen;
25+
import com.magento.idea.magento2plugin.util.magento.MagentoVersion;
2526
import java.awt.event.ActionEvent;
2627
import java.awt.event.ActionListener;
2728
import java.awt.event.KeyEvent;
@@ -72,6 +73,8 @@ public class NewModuleDialog extends AbstractDialog implements ListSelectionList
7273
private JLabel moduleDescriptionLabel;//NOPMD
7374
private JLabel moduleNameLabel;//NOPMD
7475

76+
private static final String MAGENTO_OLD_VERSION = "2.2.11";
77+
7578
/**
7679
* Constructor.
7780
*
@@ -187,7 +190,7 @@ private void generateModuleXml() {
187190
new ModuleXmlGenerator(new ModuleXmlData(
188191
getPackageName(),
189192
getModuleName(),
190-
getModuleVersion(),
193+
getSetupVersion(),
191194
getBaseDir(),
192195
true
193196
), project).generate(NewModuleAction.actionName, true);
@@ -225,10 +228,39 @@ public String getModuleDescription() {
225228
return this.moduleDescription.getText().trim();
226229
}
227230

231+
/**
232+
* get Module Version.
233+
*
234+
* @return string
235+
*/
228236
public String getModuleVersion() {
229237
return this.moduleVersion.getText().trim();
230238
}
231239

240+
/**
241+
* get Module Version.
242+
*
243+
* @return string|null
244+
*/
245+
public String getSetupVersion() {
246+
String setupVersion = null;
247+
final String magentoVersion = getMagentoVersion();
248+
249+
if (!MagentoVersion.compareMagentoVersion(magentoVersion, MAGENTO_OLD_VERSION)) {
250+
setupVersion = this.moduleVersion.getText().trim();
251+
}
252+
return setupVersion;
253+
}
254+
255+
/**
256+
* get Magento Version.
257+
*
258+
* @return string
259+
*/
260+
public String getMagentoVersion() {
261+
return this.getSettings().magentoVersion;
262+
}
263+
232264
/**
233265
* Getter for module license.
234266
*
@@ -328,4 +360,14 @@ public void valueChanged(final ListSelectionEvent listSelectionEvent) {
328360
handleModuleCustomLicenseInputVisibility();
329361
handleModuleSelectedDependencies();
330362
}
363+
364+
/**
365+
* get setting.
366+
*
367+
* @return Settings
368+
*/
369+
public Settings getSettings() {
370+
return Settings.getInstance(project);
371+
}
372+
331373
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,12 @@ public PsiFile generate(final String actionName) {
6767
);
6868
}
6969

70+
@Override
7071
protected void fillAttributes(final Properties attributes) {
7172
attributes.setProperty("PACKAGE", moduleXmlData.getPackageName());
7273
attributes.setProperty("MODULE_NAME", moduleXmlData.getModuleName());
73-
attributes.setProperty("SETUP_VERSION", moduleXmlData.getModuleVersion());
74+
if (moduleXmlData.getSetupVersion() != null) {
75+
attributes.setProperty("SETUP_VERSION", moduleXmlData.getSetupVersion());
76+
}
7477
}
7578
}

src/com/magento/idea/magento2plugin/util/magento/MagentoVersion.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,26 @@ public static String get(final Project project, final String magentoPath) {
7070
private static String getFilePath(final String magentoPath) {
7171
return magentoPath + File.separator + ComposerJson.FILE_NAME;
7272
}
73+
74+
/**
75+
* compare Magento Version.
76+
*
77+
* @param str1 String
78+
* @param str2 String
79+
* @return boolean
80+
*/
81+
public static boolean compareMagentoVersion(final String str1, final String str2) {
82+
if (str1.equals(str2)) return true;
83+
84+
final String[] str1s = str1.split("\\.");
85+
final String[] str2s = str2.split("\\.");
86+
for (int i = 0; i < 2; i++) {
87+
final Integer value1 = Integer.parseInt(str1s[i]);
88+
final Integer value2 = Integer.parseInt(str2s[i]);
89+
if (value1 > value2) {
90+
return true;
91+
}
92+
}
93+
return false;
94+
}
7395
}

0 commit comments

Comments
 (0)