Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

986: Added indexer.xml file in context generation. #988

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<action id="MagentoCreateExtensionAttributesFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewExtensionAttributesXmlAction"/>
<action id="MagentoCreateWidgetFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewWidgetXmlAction"/>
<action id="MagentoCreateMviewFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewMviewXmlAction"/>
<action id="MagentoCreateIndexerFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewIndexerXmlAction"/>
<!-- Context dependent actions -->
<separator/>
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewXml"/>
Expand Down Expand Up @@ -575,6 +576,7 @@
<internalFileTemplate name="Magento Extension Attributes XML"/>
<internalFileTemplate name="Magento Widget XML"/>
<internalFileTemplate name="Magento Mview XML"/>
<internalFileTemplate name="Magento Indexer XML"/>

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

Expand Down
5 changes: 5 additions & 0 deletions resources/fileTemplates/internal/Magento Indexer XML.xml.ft
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
#parse("XML File Header.xml")
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/indexer.xsd">
</config>
23 changes: 23 additions & 0 deletions resources/fileTemplates/internal/Magento Indexer XML.xml.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<html lang="en">
<body>
<font face="verdana" size="-1">
<p>
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.
</p>
<p>
Read more about indexer.xml in the
<a href="https://devdocs.magento.com/guides/v2.4/extension-dev-guide/indexing.html">DevDocs</a>.
</p>
</font>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}