Skip to content

Commit ae866bc

Browse files
Merge pull request #988 from doninAtwix/986-new-context-indexer-xml-file-action
986: Added indexer.xml file in context generation.
2 parents 3347dff + 7bd062d commit ae866bc

File tree

5 files changed

+117
-0
lines changed

5 files changed

+117
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<action id="MagentoCreateExtensionAttributesFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewExtensionAttributesXmlAction"/>
6969
<action id="MagentoCreateWidgetFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewWidgetXmlAction"/>
7070
<action id="MagentoCreateMviewFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewMviewXmlAction"/>
71+
<action id="MagentoCreateIndexerFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewIndexerXmlAction"/>
7172
<!-- Context dependent actions -->
7273
<separator/>
7374
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewXml"/>
@@ -575,6 +576,7 @@
575576
<internalFileTemplate name="Magento Extension Attributes XML"/>
576577
<internalFileTemplate name="Magento Widget XML"/>
577578
<internalFileTemplate name="Magento Mview XML"/>
579+
<internalFileTemplate name="Magento Indexer XML"/>
578580

579581
<defaultLiveTemplates file="/liveTemplates/MagentoPWA.xml"/>
580582

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
#parse("XML File Header.xml")
3+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/indexer.xsd">
5+
</config>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html lang="en">
8+
<body>
9+
<font face="verdana" size="-1">
10+
<p>
11+
Indexing is how Magento transforms data such as products and categories, to improve the performance of
12+
your storefront. As data changes, the transformed data must be updated or reindexed. Magento has a very
13+
sophisticated architecture that stores lots of merchant data (including catalog data, prices, users, and stores)
14+
in many database tables. To optimize storefront performance, Magento accumulates data into special tables
15+
using indexers.
16+
</p>
17+
<p>
18+
Read more about indexer.xml in the
19+
<a href="https://devdocs.magento.com/guides/v2.4/extension-dev-guide/indexing.html">DevDocs</a>.
20+
</p>
21+
</font>
22+
</body>
23+
</html>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.xml;
7+
8+
import com.intellij.ide.fileTemplates.actions.AttributesDefaults;
9+
import com.intellij.psi.PsiDirectory;
10+
import com.intellij.psi.PsiFile;
11+
import com.magento.idea.magento2plugin.actions.context.AbstractContextAction;
12+
import com.magento.idea.magento2plugin.magento.files.ModuleIndexerXmlFile;
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 NewIndexerXmlAction extends AbstractContextAction {
19+
20+
public static final String ACTION_NAME = "Magento 2 Indexer File";
21+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 indexer.xml file";
22+
23+
/**
24+
* New indexer.xml file generation action constructor.
25+
*/
26+
public NewIndexerXmlAction() {
27+
super(ACTION_NAME, ACTION_DESCRIPTION, new ModuleIndexerXmlFile());
28+
}
29+
30+
@Override
31+
protected boolean isVisible(
32+
final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData,
33+
final @NotNull PsiDirectory targetDirectory,
34+
final PsiFile targetFile
35+
) {
36+
final PsiDirectory configDir = moduleData.getConfigDir();
37+
38+
if (configDir == null) {
39+
return false;
40+
}
41+
42+
return targetDirectory.getName().equals(Package.moduleBaseAreaDir)
43+
&& targetDirectory.equals(configDir)
44+
&& moduleData.getType().equals(ComponentType.module);
45+
}
46+
47+
48+
@Override
49+
protected AttributesDefaults getProperties(
50+
final @NotNull AttributesDefaults defaults,
51+
final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData,
52+
final PsiDirectory targetDirectory,
53+
final PsiFile targetFile
54+
) {
55+
return defaults;
56+
}
57+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.magento.files;
7+
8+
import com.intellij.lang.Language;
9+
import com.intellij.lang.xml.XMLLanguage;
10+
11+
public final class ModuleIndexerXmlFile implements ModuleFileInterface {
12+
13+
public static final String FILE_NAME = "indexer.xml";
14+
public static final String TEMPLATE = "Magento Indexer XML";
15+
16+
@Override
17+
public String getFileName() {
18+
return FILE_NAME;
19+
}
20+
21+
@Override
22+
public String getTemplate() {
23+
return TEMPLATE;
24+
}
25+
26+
@Override
27+
public Language getLanguage() {
28+
return XMLLanguage.INSTANCE;
29+
}
30+
}

0 commit comments

Comments
 (0)