Skip to content

Commit 13b7b34

Browse files
author
Sergiy Zhovnir
committed
#issue-178 Add CRON Group Generation action
1 parent 52b0e59 commit 13b7b34

File tree

18 files changed

+1671
-0
lines changed

18 files changed

+1671
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<action id="MagentoCreateABlock" class="com.magento.idea.magento2plugin.actions.generation.NewBlockAction" />
6060
<action id="MagentoCreateAController" class="com.magento.idea.magento2plugin.actions.generation.NewControllerAction" />
6161
<action id="MagentoCreateACronjob" class="com.magento.idea.magento2plugin.actions.generation.NewCronjobAction" />
62+
<action id="MagentoCreateACronGroup" class="com.magento.idea.magento2plugin.actions.generation.NewCronGroupAction" />
6263
<action id="MagentoCreateAViewModel" class="com.magento.idea.magento2plugin.actions.generation.NewViewModelAction" />
6364
<action id="MagentoCreateAGraphQlResolver" class="com.magento.idea.magento2plugin.actions.generation.NewGraphQlResolverAction" />
6465
<action id="MagentoCreateCLICommand" class="com.magento.idea.magento2plugin.actions.generation.NewCLICommandAction" />
@@ -166,6 +167,7 @@
166167
<internalFileTemplate name="Magento CLI Command"/>
167168
<internalFileTemplate name="Magento Module Controller Backend Class"/>
168169
<internalFileTemplate name="Magento Module Controller Frontend Class"/>
170+
<internalFileTemplate name="Magento Module Cron Groups Xml"/>
169171
</extensions>
170172

171173
<extensions defaultExtensionNs="com.jetbrains.php">
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<group id="${GROUP_NAME}">
2+
#if (${SCHEDULE_GENERATE_EVERY})<schedule_generate_every>${SCHEDULE_GENERATE_EVERY}</schedule_generate_every>#end
3+
#if (${SCHEDULE_AHEAD_FOR})<schedule_ahead_for>${SCHEDULE_AHEAD_FOR}</schedule_ahead_for>#end
4+
#if (${SCHEDULE_LIFETIME})<schedule_lifetime>${SCHEDULE_LIFETIME}</schedule_lifetime>#end
5+
#if (${HISTORY_CLEANUP_EVERY})<history_cleanup_every>${HISTORY_CLEANUP_EVERY}</history_cleanup_every>#end
6+
#if (${HISTORY_SUCCESS_LIFETIME})<history_success_lifetime>${HISTORY_SUCCESS_LIFETIME}</history_success_lifetime>#end
7+
#if (${HISTORY_FAILURE_LIFETIME})<history_failure_lifetime>${HISTORY_FAILURE_LIFETIME}</history_failure_lifetime>#end
8+
#if (${USE_SEPARATE_PROCESS})<use_separate_process>${USE_SEPARATE_PROCESS}</use_separate_process>#end
9+
</group>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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">Each CRON group should be registered in cron_groups.xml in order to group CRON jobs with specific CRON group properties.</font>
13+
</td>
14+
</tr>
15+
<tr>
16+
<td>
17+
<font face="verdana" size="-1">
18+
<a href="https://devdocs.magento.com/guides/v2.3/config-guide/cron/custom-cron-tut.html">Configure a custom cron job and cron group (tutorial)</a>
19+
</font>
20+
</td>
21+
</tr>
22+
<tr>
23+
<td>
24+
<font face="verdana" size="-1">
25+
<a href="https://devdocs.magento.com/guides/v2.3/config-guide/cron/custom-cron-ref.html#specify-cron-group-options">Specifying Cron group options</a>
26+
</font>
27+
</td>
28+
</tr>
29+
</table>
30+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
31+
<tr>
32+
<td colspan="3"><font face="verdana" size="-1">Predefined variables explanation:</font></td>
33+
</tr>
34+
<tr>
35+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${GROUP_NAME}</b></font></nobr></td>
36+
<td width="10">&nbsp;</td>
37+
<td width="100%" valign="top"><font face="verdana" size="-1">A cron group name.</font></td>
38+
</tr>
39+
<tr>
40+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${SCHEDULE_GENERATE_EVERY}</b></font></nobr></td>
41+
<td width="10">&nbsp;</td>
42+
<td width="100%" valign="top"><font face="verdana" size="-1">Frequency (in minutes) that schedules are written to the cron_schedule table.</font></td>
43+
</tr>
44+
<tr>
45+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${SCHEDULE_AHEAD_FOR}</b></font></nobr></td>
46+
<td width="10">&nbsp;</td>
47+
<td width="100%" valign="top"><font face="verdana" size="-1">Time (in minutes) in advance that schedules are written to the cron_schedule table.</font></td>
48+
</tr>
49+
<tr>
50+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${SCHEDULE_LIFETIME}</b></font></nobr></td>
51+
<td width="10">&nbsp;</td>
52+
<td width="100%" valign="top"><font face="verdana" size="-1">Window of time (in minutes) that cron job must start or will be considered missed (“too late” to run).</font></td>
53+
</tr>
54+
<tr>
55+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${HISTORY_CLEANUP_EVERY}</b></font></nobr></td>
56+
<td width="10">&nbsp;</td>
57+
<td width="100%" valign="top"><font face="verdana" size="-1">Time (in minutes) that cron history is kept in the database.</font></td>
58+
</tr>
59+
<tr>
60+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${HISTORY_SUCCESS_LIFETIME}</b></font></nobr></td>
61+
<td width="10">&nbsp;</td>
62+
<td width="100%" valign="top"><font face="verdana" size="-1">Time (in minutes) that the record of successfully completed cron jobs are kept in the database.</font></td>
63+
</tr>
64+
<tr>
65+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${HISTORY_FAILURE_LIFETIME}</b></font></nobr></td>
66+
<td width="10">&nbsp;</td>
67+
<td width="100%" valign="top"><font face="verdana" size="-1">Time (in minutes) that the record of failed cron jobs are kept in the database.</font></td>
68+
</tr>
69+
<tr>
70+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${USE_SEPARATE_PROCESS}</b></font></nobr></td>
71+
<td width="10">&nbsp;</td>
72+
<td width="100%" valign="top"><font face="verdana" size="-1">Run this crongroup’s jobs in a separate php process</font></td>
73+
</tr>
74+
</table>
75+
</body>
76+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/cron_groups.xsd">
3+
</config>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
cron_groups.xml file is the place where cron groups are declared.
12+
</p>
13+
<p>
14+
Read more about <a href="https://devdocs.magento.com/guides/v2.3/config-guide/cron/custom-cron-ref.html">Custom cron job and cron group reference</a>.
15+
</p>
16+
</font>
17+
18+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
19+
<tr>
20+
<td colspan="3"><font face="verdana" size="-1">cron_groups.xml should be defined in the global area</font></td>
21+
</tr>
22+
</table>
23+
</body>
24+
</html>

resources/magento2/validation.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
validator.notEmpty={0} must not be empty
22
validator.package.validPath=Please specify a valid Magento 2 installation path
33
validator.alphaNumericCharacters={0} must contain letters and numbers only
4+
validator.alreadyDeclared={0} is already declared in the {1} module.
45
validator.startWithNumberOrCapitalLetter={0} must start from a number or a capital letter
56
validator.onlyNumbers={0} must contain numbers only
7+
validator.mustNotBeNegative={0} must not be negative
68
validator.identifier={0} must contain letters, numbers, dashes, and underscores only
79
validator.class.isNotValid={0} is not valid class name
810
validator.namespace.isNotValid={0} is not valid namespace name
911
validator.directory.isNotValid={0} is not valid
1012
validator.module.noSuchModule=No such module {0}
1113
validator.file.alreadyExists={0} already exists
1214
validator.file.cantBeCreated={0} can't be created
15+
validator.file.isNotWritable=%s file is binary or has no document associations
16+
validator.file.noDocumentAssociations={0} file is binary or has no document associations
1317
validator.class.alreadyDeclared={0} already declared in the target module
1418
validator.magentoVersionInvalid=Please specify valid Magento version or use 'any' keyword as default
1519
validator.class.targetClassNotFound=Target class is not found. Check the di.xml file
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation;
7+
8+
import com.intellij.ide.IdeView;
9+
import com.intellij.openapi.actionSystem.AnActionEvent;
10+
import com.intellij.openapi.actionSystem.CommonDataKeys;
11+
import com.intellij.openapi.actionSystem.DataContext;
12+
import com.intellij.openapi.actionSystem.LangDataKeys;
13+
import com.intellij.openapi.project.Project;
14+
import com.intellij.psi.PsiDirectory;
15+
import com.magento.idea.magento2plugin.MagentoIcons;
16+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewCronGroupDialog;
17+
18+
@SuppressWarnings({"PMD.OnlyOneReturn"})
19+
public class NewCronGroupAction extends com.intellij.openapi.actionSystem.AnAction {
20+
public static final String ACTION_NAME = "Magento 2 Cron Group";
21+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 cron group";
22+
23+
/**
24+
* New CRON group action constructor.
25+
*/
26+
public NewCronGroupAction() {
27+
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
28+
}
29+
30+
@Override
31+
public void actionPerformed(final AnActionEvent event) {
32+
DataContext dataContext = event.getDataContext();
33+
IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
34+
35+
if (view == null) {
36+
return;
37+
}
38+
39+
Project project = CommonDataKeys.PROJECT.getData(dataContext);
40+
if (project == null) {
41+
return;
42+
}
43+
44+
PsiDirectory directory = view.getOrChooseDirectory();
45+
if (directory == null) {
46+
return;
47+
}
48+
49+
NewCronGroupDialog.open(project, directory);
50+
}
51+
52+
@Override
53+
public boolean isDumbAware() {
54+
return false;
55+
}
56+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.data;
7+
8+
public class CronGroupXmlData {
9+
private final String module;
10+
private final String groupName;
11+
private final Integer scheduleGenerateEvery;
12+
private final Integer scheduleAheadFor;
13+
private final Integer scheduleLifetime;
14+
private final Integer historyCleanupEvery;
15+
private final Integer historySuccessLifetime;
16+
private final Integer historyFailureLifetime;
17+
private final Integer useSeparateProcess;
18+
19+
/**
20+
* Cron group XML data constructor.
21+
*
22+
* @param module Module name
23+
* @param groupName CRON group name
24+
* @param scheduleGenerateEvery Schedule generate every
25+
* @param scheduleAheadFor Schedule ahead for
26+
* @param scheduleLifetime Schedule lifetime
27+
* @param historyCleanupEvery History cleanup every
28+
* @param historySuccessLifetime History success lifetime
29+
* @param historyFailureLifetime History failure lifetime
30+
* @param useSeparateProcess Use separate process
31+
*/
32+
public CronGroupXmlData(
33+
String module,
34+
String groupName,
35+
Integer scheduleGenerateEvery,
36+
Integer scheduleAheadFor,
37+
Integer scheduleLifetime,
38+
Integer historyCleanupEvery,
39+
Integer historySuccessLifetime,
40+
Integer historyFailureLifetime,
41+
Integer useSeparateProcess
42+
) {
43+
this.module = module;
44+
this.groupName = groupName;
45+
this.scheduleGenerateEvery = scheduleGenerateEvery;
46+
this.scheduleAheadFor = scheduleAheadFor;
47+
this.scheduleLifetime = scheduleLifetime;
48+
this.historyCleanupEvery = historyCleanupEvery;
49+
this.historySuccessLifetime = historySuccessLifetime;
50+
this.historyFailureLifetime = historyFailureLifetime;
51+
this.useSeparateProcess = useSeparateProcess;
52+
}
53+
54+
/**
55+
* Get module name.
56+
*
57+
* @return String
58+
*/
59+
public String getModule() {
60+
return module;
61+
}
62+
63+
/**
64+
* Get CRON group name.
65+
*
66+
* @return String
67+
*/
68+
public String getGroupName() {
69+
return groupName;
70+
}
71+
72+
/**
73+
* Get schedule ahead for.
74+
*
75+
* @return Integer
76+
*/
77+
public Integer getScheduleAheadFor() {
78+
return scheduleAheadFor;
79+
}
80+
81+
/**
82+
* Get schedule generate every.
83+
*
84+
* @return Integer
85+
*/
86+
public Integer getScheduleGenerateEvery() {
87+
return scheduleGenerateEvery;
88+
}
89+
90+
/**
91+
* Get schedule lifetime.
92+
*
93+
* @return Integer
94+
*/
95+
public Integer getScheduleLifetime() {
96+
return scheduleLifetime;
97+
}
98+
99+
/**
100+
* Get history cleanup every.
101+
*
102+
* @return Integer
103+
*/
104+
public Integer getHistoryCleanupEvery() {
105+
return historyCleanupEvery;
106+
}
107+
108+
/**
109+
* Get history success lifetime.
110+
*
111+
* @return Integer
112+
*/
113+
public Integer getHistorySuccessLifetime() {
114+
return historySuccessLifetime;
115+
}
116+
117+
/**
118+
* Get history failure lifetime.
119+
*
120+
* @return Integer
121+
*/
122+
public Integer getHistoryFailureLifetime() {
123+
return historyFailureLifetime;
124+
}
125+
126+
/**
127+
* Get use separate process.
128+
*
129+
* @return Integer
130+
*/
131+
public Integer getUseSeparateProcess() {
132+
return useSeparateProcess;
133+
}
134+
}

0 commit comments

Comments
 (0)