Skip to content

Commit 749faf3

Browse files
author
Vitaliy Boyko
committed
Merge branch '3.0.3-develop' of github.com:magento/magento2-phpstorm-plugin into 3.0.3-develop->3.1.0-develop-forwardport
� Conflicts: � .github/workflows/gradle.yml � CHANGELOG.md � build.gradle � resources/META-INF/plugin.xml
2 parents a1a4d30 + fee9468 commit 749faf3

File tree

4 files changed

+47
-9
lines changed

4 files changed

+47
-9
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0).
66

77
## 3.1.0
88

9+
## 3.0.3
10+
11+
### Fixed
12+
13+
- Fixed model generation with same names
14+
- Fixed NPTR exception in theme directory view model action
15+
- Fixed observer name validator
16+
- Fixed plugin name validator
17+
918
## 3.0.2
1019

1120
### Fixed

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

+35-6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public class NewModelsDialog extends AbstractDialog {
5353
private static final String ENTITY_ID_COLUMN_NAME = "Entity ID Column Name";
5454
private static final String COLLECTION_NAME = "Collection Name";
5555
private static final String COLLECTION_DIRECTORY = "Collection Directory";
56+
public static final String RESOURCE_MODEL = "ResourceModel";
57+
public static final String MODEL = "Model";
58+
public static final String FQN_ALIAS_KEYWORD = " as ";
5659

5760
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
5861
message = {NotEmptyRule.MESSAGE, MODEL_NAME})
@@ -223,14 +226,24 @@ private void onOK() {
223226
private PsiFile generateModelFile() {
224227
final NamespaceBuilder modelNamespace = getModelNamespace();
225228
final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace();
229+
final StringBuilder resourceModelFqn
230+
= new StringBuilder(resourceModelNamespace.getClassFqn());
231+
String resourceModelName = getResourceModelName();
232+
233+
if (getModelName().equals(getResourceModelName())) {
234+
resourceModelFqn.append(FQN_ALIAS_KEYWORD);
235+
resourceModelFqn.append(RESOURCE_MODEL);
236+
resourceModelName = RESOURCE_MODEL;
237+
}
238+
226239
return new ModuleModelGenerator(new ModelData(
227240
getModuleName(),
228241
getDbTableName(),
229242
getModelName(),
230-
getResourceModelName(),
243+
resourceModelName,
231244
modelNamespace.getClassFqn(),
232245
modelNamespace.getNamespace(),
233-
resourceModelNamespace.getClassFqn()
246+
resourceModelFqn.toString()
234247
), project).generate(NewModelsDialog.ACTION_NAME, true);
235248
}
236249

@@ -250,17 +263,33 @@ private PsiFile generateCollectionFile() {
250263
final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace();
251264
final NamespaceBuilder modelNamespace = getModelNamespace();
252265
final NamespaceBuilder collectionNamespace = getCollectionNamespace();
266+
final StringBuilder modelFqn = new StringBuilder(modelNamespace.getClassFqn());
267+
String modelName = getModelName();
268+
final StringBuilder resourceModelFqn
269+
= new StringBuilder(resourceModelNamespace.getClassFqn());
270+
String resourceModelName = getResourceModelName();
271+
272+
273+
if (getModelName().equals(getResourceModelName())) {
274+
modelFqn.append(FQN_ALIAS_KEYWORD);
275+
modelFqn.append(MODEL);
276+
modelName = MODEL;
277+
resourceModelFqn.append(FQN_ALIAS_KEYWORD);
278+
resourceModelFqn.append(RESOURCE_MODEL);
279+
resourceModelName = RESOURCE_MODEL;
280+
}
281+
253282
return new ModuleCollectionGenerator(new CollectionData(
254283
getModuleName(),
255284
getDbTableName(),
256-
getModelName(),
285+
modelName,
257286
getCollectionName(),
258287
collectionNamespace.getClassFqn(),
259288
getCollectionDirectory(),
260289
collectionNamespace.getNamespace(),
261-
getResourceModelName(),
262-
resourceModelNamespace.getClassFqn(),
263-
modelNamespace.getClassFqn()
290+
resourceModelName,
291+
resourceModelFqn.toString(),
292+
modelFqn.toString()
264293
), project).generate(NewModelsDialog.ACTION_NAME, true);
265294
}
266295

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ protected void fillAttributes(final Properties attributes) {
150150
attributes.setProperty("NAMESPACE", modelData.getNamespace());
151151

152152
attributes.setProperty("DB_NAME", modelData.getDbTableName());
153-
attributes.setProperty("RESOURCE_MODEL", PhpClassGeneratorUtil.getNameFromFqn(
154-
modelData.getResourceModelFqn())
155-
);
153+
attributes.setProperty("RESOURCE_MODEL", modelData.getResourceName());
156154
final List<String> uses = getUses();
157155

158156
attributes.setProperty(

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

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.jetbrains.annotations.Nullable;
1818

1919
public final class GetModuleNameByDirectoryUtil {
20+
public static final int THEME_SPLIT_COUNT = 1;
21+
public static final String THEME_DIRECTORY_REGEX = "app\\/design\\/(adminhtml|frontend)\\/";
2022

2123
public static final int THEME_SPLIT_COUNT = 1;
2224
public static final String THEME_DIRECTORY_REGEX = "app\\/design\\/(adminhtml|frontend)\\/";

0 commit comments

Comments
 (0)