From 7bd062d579969cc27db9b80c4b49d9517f7cdf12 Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Tue, 15 Feb 2022 13:45:27 +0200 Subject: [PATCH] 986: Added indexer.xml file in context generation. --- resources/META-INF/plugin.xml | 2 + .../internal/Magento Indexer XML.xml.ft | 5 ++ .../internal/Magento Indexer XML.xml.html | 23 ++++++++ .../context/xml/NewIndexerXmlAction.java | 57 +++++++++++++++++++ .../magento/files/ModuleIndexerXmlFile.java | 30 ++++++++++ 5 files changed, 117 insertions(+) create mode 100644 resources/fileTemplates/internal/Magento Indexer XML.xml.ft create mode 100644 resources/fileTemplates/internal/Magento Indexer XML.xml.html create mode 100644 src/com/magento/idea/magento2plugin/actions/context/xml/NewIndexerXmlAction.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/ModuleIndexerXmlFile.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 605b39ded..ecc57f6af 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -68,6 +68,7 @@ + @@ -575,6 +576,7 @@ + diff --git a/resources/fileTemplates/internal/Magento Indexer XML.xml.ft b/resources/fileTemplates/internal/Magento Indexer XML.xml.ft new file mode 100644 index 000000000..a9ec35c0e --- /dev/null +++ b/resources/fileTemplates/internal/Magento Indexer XML.xml.ft @@ -0,0 +1,5 @@ + +#parse("XML File Header.xml") + + diff --git a/resources/fileTemplates/internal/Magento Indexer XML.xml.html b/resources/fileTemplates/internal/Magento Indexer XML.xml.html new file mode 100644 index 000000000..443499f99 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Indexer XML.xml.html @@ -0,0 +1,23 @@ + + + + +

+ Indexing is how Magento transforms data such as products and categories, to improve the performance of + your storefront. As data changes, the transformed data must be updated or reindexed. Magento has a very + sophisticated architecture that stores lots of merchant data (including catalog data, prices, users, and stores) + in many database tables. To optimize storefront performance, Magento accumulates data into special tables + using indexers. +

+

+ Read more about indexer.xml in the + DevDocs. +

+
+ + diff --git a/src/com/magento/idea/magento2plugin/actions/context/xml/NewIndexerXmlAction.java b/src/com/magento/idea/magento2plugin/actions/context/xml/NewIndexerXmlAction.java new file mode 100644 index 000000000..52d47e258 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/context/xml/NewIndexerXmlAction.java @@ -0,0 +1,57 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.context.xml; + +import com.intellij.ide.fileTemplates.actions.AttributesDefaults; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.context.AbstractContextAction; +import com.magento.idea.magento2plugin.magento.files.ModuleIndexerXmlFile; +import com.magento.idea.magento2plugin.magento.packages.ComponentType; +import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; +import org.jetbrains.annotations.NotNull; + +public class NewIndexerXmlAction extends AbstractContextAction { + + public static final String ACTION_NAME = "Magento 2 Indexer File"; + public static final String ACTION_DESCRIPTION = "Create a new Magento 2 indexer.xml file"; + + /** + * New indexer.xml file generation action constructor. + */ + public NewIndexerXmlAction() { + super(ACTION_NAME, ACTION_DESCRIPTION, new ModuleIndexerXmlFile()); + } + + @Override + protected boolean isVisible( + final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData, + final @NotNull PsiDirectory targetDirectory, + final PsiFile targetFile + ) { + final PsiDirectory configDir = moduleData.getConfigDir(); + + if (configDir == null) { + return false; + } + + return targetDirectory.getName().equals(Package.moduleBaseAreaDir) + && targetDirectory.equals(configDir) + && moduleData.getType().equals(ComponentType.module); + } + + + @Override + protected AttributesDefaults getProperties( + final @NotNull AttributesDefaults defaults, + final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData, + final PsiDirectory targetDirectory, + final PsiFile targetFile + ) { + return defaults; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/ModuleIndexerXmlFile.java b/src/com/magento/idea/magento2plugin/magento/files/ModuleIndexerXmlFile.java new file mode 100644 index 000000000..1648e44db --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/ModuleIndexerXmlFile.java @@ -0,0 +1,30 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import com.intellij.lang.Language; +import com.intellij.lang.xml.XMLLanguage; + +public final class ModuleIndexerXmlFile implements ModuleFileInterface { + + public static final String FILE_NAME = "indexer.xml"; + public static final String TEMPLATE = "Magento Indexer XML"; + + @Override + public String getFileName() { + return FILE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return XMLLanguage.INSTANCE; + } +}