Skip to content

Commit 2fb20b3

Browse files
author
Mykola Silin
authored
Merge branch '5.0.0-develop' into 1239-string-index-out-of-bounds-exception
2 parents e99c026 + c8f351a commit 2fb20b3

25 files changed

+1785
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0).
66

7+
## 5.0.0
8+
79
## 4.4.0
810

911
### Added

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
1. Check out this repository
4444
1. Open a folder with the project in the IntelliJ Ultimate using the `open` action button.
45-
1. Make sure that you on the latest develop branch (e.g `4.4.0-develop`)
45+
1. Make sure that you on the latest develop branch (e.g `5.0.0-develop`)
4646
1. Right-click on the `build.gradle` file, choose "Import Gradle project" (if this is not exist look for "Build module '<root folder name>'") (you need to have Gradle plugin installed)
4747
1. Check if the right SDK version is used for the project.
4848
- Current Java version for the project is **java 11**, so you should additionally download **SDK 11** and choose it in the module settings: `Right click by the project root > Open Module Settings > Project Settings > Project > Project SDK`

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ repositories {
1515
}
1616

1717
group 'com.magento.idea'
18-
version '4.4.0'
18+
version '5.0.0'
1919

2020
apply plugin: 'org.jetbrains.intellij'
2121
apply plugin: 'java'

resources/META-INF/plugin.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<idea-plugin require-restart="true">
88
<id>com.magento.idea.magento2plugin</id>
99
<name>Magento PhpStorm</name>
10-
<version>4.4.0</version>
10+
<version>5.0.0</version>
1111
<vendor url="https://github.com/magento/magento2-phpstorm-plugin">Magento Inc.</vendor>
1212

1313
<description><![CDATA[
@@ -64,6 +64,7 @@
6464
<action id="MagentoCreateCrontabFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewCrontabXmlAction"/>
6565
<action id="MagentoCreateDiFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewDiXmlAction"/>
6666
<action id="MagentoCreateEmailTemplatesFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewEmailTemplatesXmlAction"/>
67+
<action id="MagentoCreateEventsFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewEventsXmlAction"/>
6768
<action id="MagentoCreateExtensionAttributesFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewExtensionAttributesXmlAction"/>
6869
<action id="MagentoCreateFieldsetFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewFieldsetXmlAction"/>
6970
<action id="MagentoCreateIndexerFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewIndexerXmlAction"/>
@@ -77,6 +78,8 @@
7778
<action id="MagentoCreateWidgetFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewWidgetXmlAction"/>
7879
<action id="MagentoCreateLayoutFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewLayoutXmlAction"/>
7980
<action id="MagentoCreateReadmeFile" class="com.magento.idea.magento2plugin.actions.context.md.NewReadmeMdAction"/>
81+
<action id="MagentoNewObserverFile" class="com.magento.idea.magento2plugin.actions.context.php.NewObserverAction"/>
82+
<action id="MagentoNewSetupDataPatchFile" class="com.magento.idea.magento2plugin.actions.context.php.NewSetupDataPatchAction"/>
8083
<!-- Context dependent actions -->
8184
<separator/>
8285
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewXml"/>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
4+
namespace ${NAMESPACE};
5+
6+
use Magento\Framework\Event\ObserverInterface;
7+
use Magento\Framework\Event\Observer;
8+
9+
/**
10+
* Observes the `${EVENT_NAME}` event.
11+
*/
12+
class ${CLASS_NAME} implements ObserverInterface
13+
{
14+
/**
15+
* Observer for ${EVENT_NAME}.
16+
*
17+
* @param Observer $observer
18+
*
19+
* @return void
20+
*/
21+
public function execute(Observer $observer)
22+
{
23+
$event = $observer->getEvent();
24+
// TODO: Implement observer method.
25+
}
26+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!--
2+
/*
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html>
8+
<body>
9+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
10+
<tr>
11+
<td>
12+
<font face="verdana" size="-1">Observers are a certain type of Magento class that can influence
13+
general behavior, performance, or change business logic. Observers are executed whenever the
14+
event they are configured to watch is dispatched by the event manager.
15+
<a href="https://devdocs.magento.com/guides/v2.3/extension-dev-guide/events-and-observers.html">
16+
Read more</a> about observers.
17+
</font>
18+
</td>
19+
</tr>
20+
<tr>
21+
<td>
22+
<font face="verdana" size="-1">Check out the
23+
<a href="https://devdocs.magento.com/guides/v2.3/ext-best-practices/extension-coding/observers-bp.html">
24+
Observers best practices</a> to have a clean and professional implementation.</font>
25+
</td>
26+
</tr>
27+
</table>
28+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
29+
<tr>
30+
<td colspan="3"><font face="verdana" size="-1">Predefined variables explanation:</font></td>
31+
</tr>
32+
<tr>
33+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${NAMESPACE}</b></font></nobr></td>
34+
<td width="10">&nbsp;</td>
35+
<td width="100%" valign="top"><font face="verdana" size="-1">Namespace for the class.</font></td>
36+
</tr>
37+
<tr>
38+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${CLASS_NAME}</b></font></nobr></td>
39+
<td width="10">&nbsp;</td>
40+
<td width="100%" valign="top"><font face="verdana" size="-1">Class name.</font></td>
41+
</tr>
42+
<tr>
43+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${EVENT_NAME}</b></font></nobr></td>
44+
<td width="10">&nbsp;</td>
45+
<td width="100%" valign="top"><font face="verdana" size="-1">The name of the observer for the event definition.</font></td>
46+
</tr>
47+
</table>
48+
</body>
49+
</html>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
4+
namespace ${MODULE_NAME}\Setup\Patch\Data;
5+
6+
use Magento\Framework\Setup\ModuleDataSetupInterface;
7+
use Magento\Framework\Setup\Patch\DataPatchInterface;
8+
9+
/**
10+
* Patch is mechanism, that allows to do atomic upgrade data changes.
11+
*/
12+
class ${CLASS_NAME} implements DataPatchInterface
13+
{
14+
/**
15+
* @var ModuleDataSetupInterface
16+
*/
17+
private $moduleDataSetup;
18+
19+
/**
20+
* @param ModuleDataSetupInterface $moduleDataSetup
21+
*/
22+
public function __construct(
23+
ModuleDataSetupInterface $moduleDataSetup
24+
) {
25+
$this->moduleDataSetup = $moduleDataSetup;
26+
}
27+
28+
/**
29+
* Do Upgrade.
30+
*
31+
* @return void
32+
*/
33+
public function apply()
34+
{
35+
$this->moduleDataSetup->getConnection()->startSetup();
36+
37+
// TODO: The code that you want apply in the patch
38+
39+
$this->moduleDataSetup->getConnection()->endSetup();
40+
}
41+
42+
/**
43+
* Get aliases (previous names) for the patch.
44+
*
45+
* @return string[]
46+
*/
47+
public function getAliases()
48+
{
49+
return [];
50+
}
51+
52+
/**
53+
* Get array of patches that have to be executed prior to this.
54+
*
55+
* Example of implementation:
56+
*
57+
* [
58+
* \Vendor_Name\Module_Name\Setup\Patch\Patch1::class,
59+
* \Vendor_Name\Module_Name\Setup\Patch\Patch2::class
60+
* ]
61+
*
62+
* @return string[]
63+
*/
64+
public static function getDependencies()
65+
{
66+
return [];
67+
}
68+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!--
2+
/*
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html>
8+
<body>
9+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
10+
<tr>
11+
<td><font face="verdana" size="-1">
12+
A data patch is a class that contains data modification instructions.
13+
</font><br>
14+
</td>
15+
</tr>
16+
<tr>
17+
<td><font face="verdana" size="-1">
18+
Read more About the data and schema patches in the
19+
<a href="https://devdocs.magento.com/guides/v2.4/extension-dev-guide/declarative-schema/data-patches.html">
20+
DevDocs</a>.
21+
</font><br>
22+
</td>
23+
</tr>
24+
</table>
25+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
26+
<tr>
27+
<td colspan="3"><font face="verdana" size="-1">Predefined variables explanation:</font></td>
28+
</tr>
29+
<tr>
30+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${CLASS_NAME}</b></font></nobr></td>
31+
<td width="10">&nbsp;</td>
32+
<td width="100%" valign="top"><font face="verdana" size="-1">Specifies the name of your class
33+
</font>
34+
</td>
35+
</tr>
36+
</table>
37+
</body>
38+
</html>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.context.php;
7+
8+
import com.intellij.openapi.actionSystem.AnActionEvent;
9+
import com.intellij.psi.PsiDirectory;
10+
import com.intellij.psi.PsiFile;
11+
import com.magento.idea.magento2plugin.actions.context.CustomGeneratorContextAction;
12+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewObserverDialog;
13+
import com.magento.idea.magento2plugin.magento.packages.ComponentType;
14+
import com.magento.idea.magento2plugin.magento.packages.Package;
15+
import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil;
16+
import org.jetbrains.annotations.NotNull;
17+
18+
public class NewObserverAction extends CustomGeneratorContextAction {
19+
20+
public static final String ACTION_NAME = "Magento 2 Observer";
21+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Observer";
22+
public static final String ROOT_DIRECTORY = "Observer";
23+
24+
public NewObserverAction() {
25+
super(ACTION_NAME, ACTION_DESCRIPTION);
26+
}
27+
28+
@Override
29+
public void actionPerformed(final @NotNull AnActionEvent event) {
30+
final GetMagentoModuleUtil.MagentoModuleData moduleData = getModuleData();
31+
32+
if (event.getProject() == null || moduleData == null || getDirectory() == null) {
33+
return;
34+
}
35+
final String[] templateData = moduleData.getName().split(Package.vendorModuleNameSeparator);
36+
37+
if (templateData.length != 2) { //NOPMD
38+
return;
39+
}
40+
41+
NewObserverDialog.open(
42+
event.getProject(),
43+
getDirectory(),
44+
templateData[0],
45+
templateData[1]
46+
);
47+
}
48+
49+
@Override
50+
protected boolean isVisible(
51+
final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData,
52+
final PsiDirectory targetDirectory,
53+
final PsiFile targetFile
54+
) {
55+
if (!moduleData.getType().equals(ComponentType.module)
56+
|| !moduleData.getModuleDir().equals(targetDirectory.getParentDirectory())) {
57+
return false;
58+
}
59+
60+
return ROOT_DIRECTORY.equals(targetDirectory.getName());
61+
}
62+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.context.php;
7+
8+
import com.intellij.openapi.actionSystem.AnActionEvent;
9+
import com.intellij.psi.PsiDirectory;
10+
import com.intellij.psi.PsiFile;
11+
import com.magento.idea.magento2plugin.actions.context.CustomGeneratorContextAction;
12+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewSetupDataPatchDialog;
13+
import com.magento.idea.magento2plugin.magento.packages.ComponentType;
14+
import com.magento.idea.magento2plugin.magento.packages.Package;
15+
import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil;
16+
import org.jetbrains.annotations.NotNull;
17+
18+
public class NewSetupDataPatchAction extends CustomGeneratorContextAction {
19+
20+
public static final String ACTION_NAME = "Magento 2 Setup Data Patch";
21+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Setup Data Patch";
22+
public static final String SETUP_DIRECTORY = "Setup";
23+
public static final String PATCH_DIRECTORY = "Patch";
24+
public static final String DATA_DIRECTORY = "Data";
25+
26+
public NewSetupDataPatchAction() {
27+
super(ACTION_NAME, ACTION_DESCRIPTION);
28+
}
29+
30+
@Override
31+
public void actionPerformed(final @NotNull AnActionEvent event) {
32+
final GetMagentoModuleUtil.MagentoModuleData moduleData = getModuleData();
33+
34+
if (event.getProject() == null || moduleData == null || getDirectory() == null) {
35+
return;
36+
}
37+
final String[] module = moduleData.getName().split(Package.vendorModuleNameSeparator);
38+
39+
if (module.length != 2) { //NOPMD
40+
return;
41+
}
42+
final PsiDirectory rootDirectory = moduleData.getModuleDir().findSubdirectory(
43+
SETUP_DIRECTORY
44+
);
45+
46+
if (rootDirectory == null) {
47+
return;
48+
}
49+
NewSetupDataPatchDialog.open(event.getProject(), rootDirectory, module[0], module[1]);
50+
}
51+
52+
@Override
53+
protected boolean isVisible(
54+
final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData,
55+
final PsiDirectory targetDirectory,
56+
final PsiFile targetFile
57+
) {
58+
if (!moduleData.getType().equals(ComponentType.module)) {
59+
return false;
60+
}
61+
62+
if (SETUP_DIRECTORY.equals(targetDirectory.getName())) {
63+
return moduleData.getModuleDir().equals(targetDirectory.getParentDirectory());
64+
}
65+
66+
if (PATCH_DIRECTORY.equals(targetDirectory.getName())) {
67+
final PsiDirectory setupDirCandidate = targetDirectory.getParentDirectory();
68+
69+
return setupDirCandidate != null
70+
&& SETUP_DIRECTORY.equals(setupDirCandidate.getName())
71+
&& moduleData.getModuleDir().equals(setupDirCandidate.getParentDirectory());
72+
}
73+
74+
if (DATA_DIRECTORY.equals(targetDirectory.getName())) {
75+
final PsiDirectory patchDirCandidate = targetDirectory.getParentDirectory();
76+
77+
if (patchDirCandidate == null) {
78+
return false;
79+
}
80+
final PsiDirectory setupDirCandidate = patchDirCandidate.getParentDirectory();
81+
82+
return setupDirCandidate != null
83+
&& PATCH_DIRECTORY.equals(patchDirCandidate.getName())
84+
&& SETUP_DIRECTORY.equals(setupDirCandidate.getName())
85+
&& moduleData.getModuleDir().equals(setupDirCandidate.getParentDirectory());
86+
}
87+
88+
return false;
89+
}
90+
}

0 commit comments

Comments
 (0)