Attached Files |
Capture d’écran 2011-06-13 à 08.37.21.png [^] (129,973 bytes) 2012-07-09 11:11

schedule_tasks_cron_interface_core.patch [^] (60,578 bytes) 2012-07-12 09:47
[Show Content]
Index: admin/system_presets/simple/scheduled_tasks_scheduled-task.php
===================================================================
--- admin/system_presets/simple/scheduled_tasks_scheduled-task.php (revision 15331)
+++ admin/system_presets/simple/scheduled_tasks_scheduled-task.php (working copy)
@@ -23,7 +23,7 @@
// fields to hide
$hidden_fields = Array (
- /* 'ScheduledTaskId', 'Name', 'Type', 'Status', 'Event', 'RunInterval', 'LastRunOn',
+ /* 'ScheduledTaskId', 'Name', 'Type', 'Status', 'Event', 'RunSchedule', 'LastRunOn',
'LastRunStatus', 'NextRunOn', 'RunTime', */
);
@@ -33,7 +33,7 @@
// fields to make required
$required_fields = Array (
- /* 'ScheduledTaskId', 'Name', 'Type', 'Status', 'Event', 'RunInterval', 'LastRunOn',
+ /* 'ScheduledTaskId', 'Name', 'Type', 'Status', 'Event', 'RunSchedule', 'LastRunOn',
'LastRunStatus', 'NextRunOn', 'RunTime', */
);
@@ -47,5 +47,5 @@
// hide columns in grids
$hide_columns = Array (
// currently not in user
-// 'Default' => Array ( 'ScheduledTaskId', 'Name', 'Type', 'Status', 'Event', 'RunInterval', 'LastRunOn', 'LastRunStatus', 'NextRunOn', ),
+// 'Default' => Array ( 'ScheduledTaskId', 'Name', 'Type', 'Status', 'Event', 'RunSchedule', 'LastRunOn', 'LastRunStatus', 'NextRunOn', ),
);
\ No newline at end of file
Index: core/admin_templates/incs/form_blocks.tpl
===================================================================
--- core/admin_templates/incs/form_blocks.tpl (revision 15429)
+++ core/admin_templates/incs/form_blocks.tpl (working copy)
@@ -1044,6 +1044,18 @@
</inp2:m_RenderElement>
</inp2:m_DefineElement>
+<inp2:m_DefineElement name="inp_edit_cron_box">
+ <inp2:m_RenderElement design="form_row" pass_params="1">
+ <td class="control-cell">
+ <input style="width: 150px;" type="text" name="<inp2:{$prefix}_InputName field='$field'/>" id="<inp2:{$prefix}_InputName field='$field'/>" value="<inp2:{$prefix}_Field field='$field'/>" tabindex="<inp2:m_Get name='tab_index'/>"/>
+
+ <select tabindex="<inp2:m_Get name='tab_index'/>" name="<inp2:{$prefix}_InputName field='{$field}Hints'/>" id="<inp2:{$prefix}_InputName field='{$field}Hints'/>" style="width: 175px;">
+ <inp2:{$prefix}_PredefinedOptions field="{$field}Hints" block="inp_option_item" selected="selected" has_empty="1" empty_value="" empty_label="la_opt_CronCommonSettings"/>
+ </select>
+ </td>
+ </inp2:m_RenderElement>
+</inp2:m_DefineElement>
+
<inp2:m_DefineElement name="inp_edit_filler" control_options="false">
<tr class="<inp2:m_odd_even odd='edit-form-odd' even='edit-form-even'/>" style="height: auto">
<td class="label-cell-filler" ></td>
Index: core/admin_templates/js/cron.js
===================================================================
--- core/admin_templates/js/cron.js (revision 0)
+++ core/admin_templates/js/cron.js (revision 0)
@@ -0,0 +1,86 @@
+function CronManager ($field_mask, $field_prefix) {
+ this.fieldMask = $field_mask;
+ this.fieldPrefix = $field_prefix;
+ this.fields = ['Minute', 'Hour', 'Day', 'Month', 'Weekday'];
+}
+
+CronManager.prototype.init = function () {
+ var $manager = this;
+
+ // populate all controls when common hint control changes
+ this.getHintControl('Common').change(function($e) {
+ var $values = $(this).val().split(' ');
+
+ $manager.fields.each(function ($i) {
+ var $field = this;
+
+ $manager.getInputControl($field).val($values[$i]).change();
+ });
+ });
+
+ this.fields.each(function () {
+ var $field = this;
+
+ // put selected hint value into the input
+ $manager.getHintControl($field).change(function ($e) {
+ $manager.getInputControl($field).val($(this).val()).change();
+ });
+
+ // put select field hint + common hint based on input value
+ $manager.getInputControl($field).change(function ($e) {
+ $manager.syncHintControl($field);
+ $manager.syncHintControl('Common', $manager.getCombinedValue());
+ }).change();
+
+ });
+}
+
+CronManager.prototype.getCombinedValue = function () {
+ var $ret = [],
+ $manager = this;
+
+ this.fields.each(function ($i) {
+ $ret.push($manager.getInputControl(this).val());
+ });
+
+ return $ret.join(' ');
+}
+
+CronManager.prototype.getHintControl = function ($field) {
+ return this.getInputControl($field, 'Hints');
+}
+
+CronManager.prototype.getInputControl = function ($field, $suffix) {
+ if ( $suffix == undefined ) {
+ $suffix = '';
+ }
+
+ return $(get_control(this.fieldMask, this.fieldPrefix + $field + $suffix));
+}
+
+CronManager.prototype.syncHintControl = function ($field, $input_value) {
+ var $hint_control = this.getHintControl($field);
+
+ if ( $input_value === undefined ) {
+ $input_value = this.getInputControl($field).val();
+ }
+
+ if ( $('option[value="' + jq($input_value) + '"]', $hint_control).length == 1 ) {
+ $hint_control.val($input_value);
+ }
+ else {
+ $hint_control.val('');
+ }
+
+ if ( $field == 'Common' ) {
+ var $old_value = $hint_control.data('old_value');
+
+ if ( $old_value !== undefined && $old_value !== $input_value ) {
+ // reset next run time to be regenerated according to new schedule on save
+ $(get_control(this.fieldMask, 'NextRunOn_date')).val('');
+ $(get_control(this.fieldMask, 'NextRunOn_time')).val('');
+ }
+
+ $hint_control.data('old_value', $input_value);
+ }
+}
Index: core/admin_templates/scheduled_tasks/scheduled_task_edit.tpl
===================================================================
--- core/admin_templates/scheduled_tasks/scheduled_task_edit.tpl (revision 15359)
+++ core/admin_templates/scheduled_tasks/scheduled_task_edit.tpl (working copy)
@@ -76,11 +76,6 @@
<inp2:m_RenderElement name="inp_label" prefix="scheduled-task" field="Event"/>
</inp2:m_if>
- <inp2:m_RenderElement name="inp_edit_box" prefix="scheduled-task" field="RunInterval"/>
- <inp2:m_RenderElement name="inp_label" prefix="scheduled-task" field="LastRunOn"/>
- <inp2:m_RenderElement name="inp_label" prefix="scheduled-task" field="LastRunStatus"/>
- <inp2:m_RenderElement name="inp_edit_date_time" prefix="scheduled-task" field="NextRunOn"/>
- <inp2:m_RenderElement name="inp_label" prefix="scheduled-task" field="RunTime"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="scheduled-task" field="Timeout" style="width: 50px"/>
<inp2:m_if check="scheduled-task_Field" name="LastTimeoutOn" db="db">
@@ -89,8 +84,31 @@
<inp2:m_RenderElement name="inp_edit_checkboxes" prefix="scheduled-task" field="SiteDomainLimitation"/>
+ <inp2:m_RenderElement name="subsection" title="la_title_RunSchedule"/>
+ <inp2:m_RenderElement name="inp_edit_options" prefix="scheduled-task" field="RunScheduleCommonHints" title="la_fld_CronCommonHints" has_empty="1" empty_label="la_opt_CronCommonSettings" style="width: 175px;"/>
+ <inp2:m_RenderElement name="inp_edit_cron_box" prefix="scheduled-task" field="RunScheduleMinute" title="la_fld_CronMinute"/>
+ <inp2:m_RenderElement name="inp_edit_cron_box" prefix="scheduled-task" field="RunScheduleHour" title="la_fld_CronHour"/>
+ <inp2:m_RenderElement name="inp_edit_cron_box" prefix="scheduled-task" field="RunScheduleDay" title="la_fld_CronDay"/>
+ <inp2:m_RenderElement name="inp_edit_cron_box" prefix="scheduled-task" field="RunScheduleMonth" title="la_fld_CronMonth"/>
+ <inp2:m_RenderElement name="inp_edit_cron_box" prefix="scheduled-task" field="RunScheduleWeekday" title="la_fld_CronWeekday"/>
+
+ <inp2:m_RenderElement name="inp_edit_date_time" prefix="scheduled-task" field="NextRunOn"/>
+
+ <inp2:m_RenderElement name="subsection" title="la_title_RunSettings"/>
+ <inp2:m_RenderElement name="inp_label" prefix="scheduled-task" field="LastRunOn"/>
+ <inp2:m_RenderElement name="inp_label" prefix="scheduled-task" field="LastRunStatus"/>
+ <inp2:m_RenderElement name="inp_label" prefix="scheduled-task" field="RunTime"/>
+
<inp2:m_RenderElement name="inp_edit_filler"/>
</table>
</div>
+<script type="text/javascript" src="<inp2:m_Compress files='js/cron.js'/>"></script>
+
+<script type="text/javascript">
+ var $aCronManager = new CronManager('<inp2:scheduled-task_InputName name="#FIELD_NAME#" js_escape="1"/>', 'RunSchedule');
+
+ $aCronManager.init();
+</script>
+
<inp2:m_include t="incs/footer"/>
\ No newline at end of file
Index: core/install/english.lang
===================================================================
--- core/install/english.lang (revision 15421)
+++ core/install/english.lang (working copy)
@@ -367,6 +367,12 @@
<PHRASE Label="la_fld_Country" Module="Core" Type="1" Column="Q291bnRyeQ==">Q291bnRyeQ==</PHRASE>
<PHRASE Label="la_fld_CreatedById" Module="Core" Type="1">Q3JlYXRlZCBCeQ==</PHRASE>
<PHRASE Label="la_fld_CreatedOn" Module="Core" Type="1" Column="Q3JlYXRlZCBPbg==">Q3JlYXRlZCBPbg==</PHRASE>
+ <PHRASE Label="la_fld_CronCommonHints" Module="Core" Type="1">Q29tbW9uIFNldHRpbmdz</PHRASE>
+ <PHRASE Label="la_fld_CronDay" Module="Core" Type="1" Column="RGF5">RGF5</PHRASE>
+ <PHRASE Label="la_fld_CronHour" Module="Core" Type="1" Column="SG91cg==">SG91cg==</PHRASE>
+ <PHRASE Label="la_fld_CronMinute" Module="Core" Type="1" Column="TWludXRl">TWludXRl</PHRASE>
+ <PHRASE Label="la_fld_CronMonth" Module="Core" Type="1" Column="TW9udGg=">TW9udGg=</PHRASE>
+ <PHRASE Label="la_fld_CronWeekday" Module="Core" Type="1" Column="V2Vla2RheQ==">V2Vla2RheQ==</PHRASE>
<PHRASE Label="la_fld_CSS" Module="Core" Type="1">Q1NTIFRlbXBsYXRl</PHRASE>
<PHRASE Label="la_fld_CSSClassName" Module="Core" Type="1" Column="Q1NTIENsYXNzIE5hbWU=">Q1NTIENsYXNzIE5hbWU=</PHRASE>
<PHRASE Label="la_fld_Cursor" Module="Core" Type="1">Q3Vyc29y</PHRASE>
@@ -607,7 +613,7 @@
<PHRASE Label="la_fld_ReviewText" Module="Core" Type="1" Column="Q29tbWVudA==">Q29tbWVudA==</PHRASE>
<PHRASE Label="la_fld_RotationDelay" Module="Core" Type="1" Column="UHJvbW8gUm90YXRpb24gRGVsYXkgKHNlY29uZHMp">UHJvbW8gUm90YXRpb24gRGVsYXkgKHNlY29uZHMp</PHRASE>
<PHRASE Label="la_fld_RuleType" Module="Core" Type="1" Column="UnVsZSBUeXBl">UnVsZSBUeXBl</PHRASE>
- <PHRASE Label="la_fld_RunInterval" Module="Core" Type="1" Column="UnVuIEludGVydmFs">UnVuIEludGVydmFs</PHRASE>
+ <PHRASE Label="la_fld_RunSchedule" Module="Core" Type="1" Column="UnVuIFNjaGVkdWxl">UnVuIFNjaGVkdWxl</PHRASE>
<PHRASE Label="la_fld_RunTime" Module="Core" Type="1" Column="UnVuIFRpbWU=">UnVuIFRpbWU=</PHRASE>
<PHRASE Label="la_fld_SameAsThumb" Module="Core" Type="1">U2FtZSBBcyBUaHVtYg==</PHRASE>
<PHRASE Label="la_fld_ScheduleDate" Module="Core" Type="1">U2NoZWR1bGUgRGF0ZQ==</PHRASE>
@@ -757,6 +763,10 @@
<PHRASE Label="la_No" Module="Core" Type="1">Tm8=</PHRASE>
<PHRASE Label="la_none" Module="Core" Type="1">Tm9uZQ==</PHRASE>
<PHRASE Label="la_no_permissions" Module="Core" Type="1">Tm8gUGVybWlzc2lvbnM=</PHRASE>
+ <PHRASE Label="la_NumberSuffixNd" Module="Core" Type="1">bmQ=</PHRASE>
+ <PHRASE Label="la_NumberSuffixRd" Module="Core" Type="1">cmQ=</PHRASE>
+ <PHRASE Label="la_NumberSuffixSt" Module="Core" Type="1">c3Q=</PHRASE>
+ <PHRASE Label="la_NumberSuffixTh" Module="Core" Type="1">dGg=</PHRASE>
<PHRASE Label="la_Off" Module="Core" Type="1">T2Zm</PHRASE>
<PHRASE Label="la_On" Module="Core" Type="1">T24=</PHRASE>
<PHRASE Label="la_OneWay" Module="Core" Type="1">T25lIFdheQ==</PHRASE>
@@ -770,6 +780,8 @@
<PHRASE Label="la_opt_AnimationCustom" Module="Core" Type="1">Q3VzdG9t</PHRASE>
<PHRASE Label="la_opt_AnimationFade" Module="Core" Type="1">RmFkZQ==</PHRASE>
<PHRASE Label="la_opt_AnimationSlide" Module="Core" Type="1">U2xpZGU=</PHRASE>
+ <PHRASE Label="la_opt_April" Module="Core" Type="1">QXByaWw=</PHRASE>
+ <PHRASE Label="la_opt_August" Module="Core" Type="1">QXVndXN0</PHRASE>
<PHRASE Label="la_opt_AutoDetect" Module="Core" Type="1">QXV0by1EZXRlY3Q=</PHRASE>
<PHRASE Label="la_opt_Automatic" Module="Core" Type="1">QXV0b21hdGlj</PHRASE>
<PHRASE Label="la_opt_Before" Module="Core" Type="1">QmVmb3Jl</PHRASE>
@@ -783,10 +795,48 @@
<PHRASE Label="la_opt_Countries" Module="Core" Type="1">Q291bnRyaWVz</PHRASE>
<PHRASE Label="la_opt_Country" Module="Core" Type="1">Q291bnRyeQ==</PHRASE>
<PHRASE Label="la_opt_CreatedOn" Module="Core" Type="1">Q3JlYXRlZCBPbg==</PHRASE>
+ <PHRASE Label="la_opt_CronCommonSettings" Module="Core" Type="1">LS0gQ29tbW9uIFNldHRpbmdzIC0t</PHRASE>
+ <PHRASE Label="la_opt_CronDays" Module="Core" Type="1">LS0gRGF5cyAtLQ==</PHRASE>
+ <PHRASE Label="la_opt_CronEveryDay" Module="Core" Type="1">RXZlcnkgZGF5</PHRASE>
+ <PHRASE Label="la_opt_CronEveryFifteenMinutes" Module="Core" Type="1">RXZlcnkgMTUgbWludXRlcw==</PHRASE>
+ <PHRASE Label="la_opt_CronEveryFiveMinutes" Module="Core" Type="1">RXZlcnkgNSBtaW51dGVz</PHRASE>
+ <PHRASE Label="la_opt_CronEveryFourHours" Module="Core" Type="1">RXZlcnkgNCBob3Vycw==</PHRASE>
+ <PHRASE Label="la_opt_CronEveryHour" Module="Core" Type="1">RXZlcnkgaG91cg==</PHRASE>
+ <PHRASE Label="la_opt_CronEveryMinute" Module="Core" Type="1">RXZlcnkgbWludXRl</PHRASE>
+ <PHRASE Label="la_opt_CronEveryMonth" Module="Core" Type="1">RXZlcnkgbW9udGg=</PHRASE>
+ <PHRASE Label="la_opt_CronEveryOtherDay" Module="Core" Type="1">RXZlcnkgb3RoZXIgZGF5</PHRASE>
+ <PHRASE Label="la_opt_CronEveryOtherHour" Module="Core" Type="1">RXZlcnkgb3RoZXIgaG91cg==</PHRASE>
+ <PHRASE Label="la_opt_CronEveryOtherMinute" Module="Core" Type="1">RXZlcnkgb3RoZXIgbWludXRl</PHRASE>
+ <PHRASE Label="la_opt_CronEveryOtherMonth" Module="Core" Type="1">RXZlcnkgb3RoZXIgbW9udGg=</PHRASE>
+ <PHRASE Label="la_opt_CronEverySixHours" Module="Core" Type="1">RXZlcnkgNiBob3Vycw==</PHRASE>
+ <PHRASE Label="la_opt_CronEverySixMonths" Module="Core" Type="1">RXZlcnkgNiBtb250aHM=</PHRASE>
+ <PHRASE Label="la_opt_CronEveryTenMinutes" Module="Core" Type="1">RXZlcnkgMTAgbWludXRlcw==</PHRASE>
+ <PHRASE Label="la_opt_CronEveryThirtyMinutes" Module="Core" Type="1">RXZlcnkgMzAgbWludXRlcw==</PHRASE>
+ <PHRASE Label="la_opt_CronEveryThreeHours" Module="Core" Type="1">RXZlcnkgMyBob3Vycw==</PHRASE>
+ <PHRASE Label="la_opt_CronEveryThreeMonths" Module="Core" Type="1">RXZlcnkgMyBtb250aHM=</PHRASE>
+ <PHRASE Label="la_opt_CronEveryTwelveHours" Module="Core" Type="1">RXZlcnkgMTIgaG91cnM=</PHRASE>
+ <PHRASE Label="la_opt_CronEveryWeekday" Module="Core" Type="1">RXZlcnkgd2Vla2RheQ==</PHRASE>
+ <PHRASE Label="la_opt_CronHours" Module="Core" Type="1">LS0gSG91cnMgLS0=</PHRASE>
+ <PHRASE Label="la_opt_CronMinutes" Module="Core" Type="1">LS0gTWludXRlcyAtLQ==</PHRASE>
+ <PHRASE Label="la_opt_CronMondayThroughFriday" Module="Core" Type="1">TW9uIHRocnUgRnJp</PHRASE>
+ <PHRASE Label="la_opt_CronMondayWednesdayAndFriday" Module="Core" Type="1">TW9uLCBXZWQsIEZyaQ==</PHRASE>
+ <PHRASE Label="la_opt_CronMonths" Module="Core" Type="1">LS0gTW9udGhzIC0t</PHRASE>
+ <PHRASE Label="la_opt_CronOnceADay" Module="Core" Type="1">T25jZSBhIGRheQ==</PHRASE>
+ <PHRASE Label="la_opt_CronOnceAMonth" Module="Core" Type="1">T25jZSBhIG1vbnRo</PHRASE>
+ <PHRASE Label="la_opt_CronOnceAnHour" Module="Core" Type="1">T25jZSBhbiBob3Vy</PHRASE>
+ <PHRASE Label="la_opt_CronOnceAWeek" Module="Core" Type="1">T25jZSBhIHdlZWs=</PHRASE>
+ <PHRASE Label="la_opt_CronOnceAYear" Module="Core" Type="1">T25jZSBhIHllYXI=</PHRASE>
+ <PHRASE Label="la_opt_CronSaturdayAndSunday" Module="Core" Type="1">U2F0IGFuZCBTdW4=</PHRASE>
+ <PHRASE Label="la_opt_CronTuesdayAndThursday" Module="Core" Type="1">VHVlcywgVGh1cnM=</PHRASE>
+ <PHRASE Label="la_opt_CronTwiceADay" Module="Core" Type="1">VHdpY2UgYSBkYXk=</PHRASE>
+ <PHRASE Label="la_opt_CronTwiceAMonth" Module="Core" Type="1">MXN0IGFuZCAxNXRo</PHRASE>
+ <PHRASE Label="la_opt_CronTwiceAnHour" Module="Core" Type="1">VHdpY2UgYW4gaG91cg==</PHRASE>
+ <PHRASE Label="la_opt_CronWeekdays" Module="Core" Type="1">LS0gV2Vla2RheXMgLS0=</PHRASE>
<PHRASE Label="la_opt_CurrentDomain" Module="Core" Type="1">Q3VycmVudCBEb21haW4=</PHRASE>
<PHRASE Label="la_opt_CustomRecipients" Module="Core" Type="1">Q3VzdG9tICJUbyIgUmVjaXBpZW50KC1zKQ==</PHRASE>
<PHRASE Label="la_opt_CustomSender" Module="Core" Type="1">Q3VzdG9tIFNlbmRlcg==</PHRASE>
<PHRASE Label="la_opt_day" Module="Core" Type="1">ZGF5KHMp</PHRASE>
+ <PHRASE Label="la_opt_December" Module="Core" Type="1">RGVjZW1iZXI=</PHRASE>
<PHRASE Label="la_opt_Declined" Module="Core" Type="1">RGVjbGluZWQ=</PHRASE>
<PHRASE Label="la_opt_DefaultAddress" Module="Core" Type="1">RGVmYXVsdCBXZWJzaXRlIGFkZHJlc3M=</PHRASE>
<PHRASE Label="la_opt_Deny" Module="Core" Type="1">RGVueQ==</PHRASE>
@@ -806,7 +856,9 @@
<PHRASE Label="la_opt_External" Module="Core" Type="1">RXh0ZXJuYWw=</PHRASE>
<PHRASE Label="la_opt_ExternalUrl" Module="Core" Type="1">RXh0ZXJuYWwgVXJs</PHRASE>
<PHRASE Label="la_opt_Failed" Module="Core" Type="1">RmFpbGVk</PHRASE>
+ <PHRASE Label="la_opt_February" Module="Core" Type="1">RmVicnVhcnk=</PHRASE>
<PHRASE Label="la_opt_FirstName" Module="Core" Type="1">Rmlyc3QgTmFtZQ==</PHRASE>
+ <PHRASE Label="la_opt_Friday" Module="Core" Type="1">RnJpZGF5</PHRASE>
<PHRASE Label="la_opt_Group" Module="Core" Type="1">R3JvdXA=</PHRASE>
<PHRASE Label="la_opt_GuestsOnly" Module="Core" Type="1">R3Vlc3RzIE9ubHk=</PHRASE>
<PHRASE Label="la_opt_hour" Module="Core" Type="1">aG91cihzKQ==</PHRASE>
@@ -815,17 +867,25 @@
<PHRASE Label="la_opt_Invalid" Module="Core" Type="1">SW52YWxpZA==</PHRASE>
<PHRASE Label="la_opt_IP_Address" Module="Core" Type="1">SVAgQWRkcmVzcw==</PHRASE>
<PHRASE Label="la_opt_IsUnique" Module="Core" Type="1">SXMgdW5pcXVl</PHRASE>
+ <PHRASE Label="la_opt_January" Module="Core" Type="1">SmFudWFyeQ==</PHRASE>
+ <PHRASE Label="la_opt_July" Module="Core" Type="1">SnVseQ==</PHRASE>
+ <PHRASE Label="la_opt_June" Module="Core" Type="1">SnVuZQ==</PHRASE>
<PHRASE Label="la_opt_LastName" Module="Core" Type="1">TGFzdCBOYW1l</PHRASE>
<PHRASE Label="la_opt_LoggedOut" Module="Core" Type="1">TG9nZ2VkIE91dA==</PHRASE>
<PHRASE Label="la_opt_Manual" Module="Core" Type="1">TWFudWFs</PHRASE>
+ <PHRASE Label="la_opt_March" Module="Core" Type="1">TWFyY2g=</PHRASE>
+ <PHRASE Label="la_opt_May" Module="Core" Type="1">TWF5</PHRASE>
<PHRASE Label="la_opt_min" Module="Core" Type="1">bWludXRlKHMp</PHRASE>
<PHRASE Label="la_opt_ModalWindow" Module="Core" Type="1">TW9kYWwgV2luZG93</PHRASE>
+ <PHRASE Label="la_opt_Monday" Module="Core" Type="1">TW9uZGF5</PHRASE>
<PHRASE Label="la_opt_month" Module="Core" Type="1">bW9udGgocyk=</PHRASE>
<PHRASE Label="la_opt_NewEmail" Module="Core" Type="1">TmV3IEUtbWFpbA==</PHRASE>
<PHRASE Label="la_opt_NotEmpty" Module="Core" Type="1">Tm90IGVtcHR5</PHRASE>
<PHRASE Label="la_opt_NotLike" Module="Core" Type="1">Tm90IGxpa2U=</PHRASE>
<PHRASE Label="la_opt_NotProcessed" Module="Core" Type="1">Tm90IFByb2Nlc3NlZA==</PHRASE>
<PHRASE Label="la_opt_NotReplied" Module="Core" Type="1">Tm90IFJlcGxpZWQ=</PHRASE>
+ <PHRASE Label="la_opt_November" Module="Core" Type="1">Tm92ZW1iZXI=</PHRASE>
+ <PHRASE Label="la_opt_October" Module="Core" Type="1">T2N0b2Jlcg==</PHRASE>
<PHRASE Label="la_opt_OneDay" Module="Core" Type="1">MSBkYXk=</PHRASE>
<PHRASE Label="la_opt_OneMonth" Module="Core" Type="1">MSBtb250aA==</PHRASE>
<PHRASE Label="la_opt_OneWeek" Module="Core" Type="1">MSB3ZWVr</PHRASE>
@@ -844,20 +904,25 @@
<PHRASE Label="la_opt_Replied" Module="Core" Type="1">UmVwbGllZA==</PHRASE>
<PHRASE Label="la_opt_Running" Module="Core" Type="1">UnVubmluZw==</PHRASE>
<PHRASE Label="la_opt_SameWindow" Module="Core" Type="1">U2FtZSBXaW5kb3c=</PHRASE>
+ <PHRASE Label="la_opt_Saturday" Module="Core" Type="1">U2F0dXJkYXk=</PHRASE>
<PHRASE Label="la_opt_sec" Module="Core" Type="1">c2Vjb25kKHMp</PHRASE>
<PHRASE Label="la_opt_Semicolon" Module="Core" Type="1">U2VtaS1jb2xvbg==</PHRASE>
+ <PHRASE Label="la_opt_September" Module="Core" Type="1">U2VwdGVtYmVy</PHRASE>
<PHRASE Label="la_opt_Silent" Module="Core" Type="1">U2lsZW50</PHRASE>
<PHRASE Label="la_opt_Space" Module="Core" Type="1">U3BhY2U=</PHRASE>
<PHRASE Label="la_opt_State" Module="Core" Type="1">U3RhdGU=</PHRASE>
<PHRASE Label="la_opt_Sub-match" Module="Core" Type="1">U3ViLW1hdGNo</PHRASE>
<PHRASE Label="la_opt_Success" Module="Core" Type="1">U3VjY2Vzcw==</PHRASE>
+ <PHRASE Label="la_opt_Sunday" Module="Core" Type="1">U3VuZGF5</PHRASE>
<PHRASE Label="la_opt_SynchronizeFromOthers" Module="Core" Type="1">RnJvbSBvdGhlcnM=</PHRASE>
<PHRASE Label="la_opt_SynchronizeToOthers" Module="Core" Type="1">VG8gb3RoZXJz</PHRASE>
<PHRASE Label="la_opt_System" Module="Core" Type="1">U3lzdGVt</PHRASE>
<PHRASE Label="la_opt_Tab" Module="Core" Type="1">VGFi</PHRASE>
<PHRASE Label="la_opt_Template" Module="Core" Type="1">VGVtcGxhdGU=</PHRASE>
<PHRASE Label="la_opt_ThreeMonths" Module="Core" Type="1">MyBtb250aHM=</PHRASE>
+ <PHRASE Label="la_opt_Thursday" Module="Core" Type="1">VGh1cnNkYXk=</PHRASE>
<PHRASE Label="la_opt_Title" Module="Core" Type="1">VGl0bGU=</PHRASE>
+ <PHRASE Label="la_opt_Tuesday" Module="Core" Type="1">VHVlc2RheQ==</PHRASE>
<PHRASE Label="la_opt_TwoWeeks" Module="Core" Type="1">MiB3ZWVrcw==</PHRASE>
<PHRASE Label="la_opt_User" Module="Core" Type="1">VXNlcg==</PHRASE>
<PHRASE Label="la_opt_UserEmailActivation" Module="Core" Type="1">RW1haWwgQWN0aXZhdGlvbg==</PHRASE>
@@ -866,6 +931,7 @@
<PHRASE Label="la_opt_UserNotAllowedRegistration" Module="Core" Type="1">Tm90IEFsbG93ZWQ=</PHRASE>
<PHRASE Label="la_opt_UserUponApprovalRegistration" Module="Core" Type="1">VXBvbiBBcHByb3ZhbA==</PHRASE>
<PHRASE Label="la_opt_Virtual" Module="Core" Type="1">VmlydHVhbA==</PHRASE>
+ <PHRASE Label="la_opt_Wednesday" Module="Core" Type="1">V2VkbmVzZGF5</PHRASE>
<PHRASE Label="la_opt_week" Module="Core" Type="1">d2VlayhzKQ==</PHRASE>
<PHRASE Label="la_opt_year" Module="Core" Type="1">eWVhcihzKQ==</PHRASE>
<PHRASE Label="la_opt_Zip" Module="Core" Type="1">Wmlw</PHRASE>
@@ -1396,6 +1462,8 @@
<PHRASE Label="la_title_Relations" Module="Core" Type="1">UmVsYXRpb25z</PHRASE>
<PHRASE Label="la_title_ReplySettings" Module="Core" Type="1">UmVwbHkgUE9QMyBTZXJ2ZXIgU2V0dGluZ3M=</PHRASE>
<PHRASE Label="la_title_Reviews" Module="Core" Type="1">Q29tbWVudHM=</PHRASE>
+ <PHRASE Label="la_title_RunSchedule" Module="Core" Type="1">UnVuIFNjaGVkdWxl</PHRASE>
+ <PHRASE Label="la_title_RunSettings" Module="Core" Type="1">UnVuIFNldHRpbmdz</PHRASE>
<PHRASE Label="la_title_ScheduledTasks" Module="Core" Type="1">U2NoZWR1bGVkIFRhc2tz</PHRASE>
<PHRASE Label="la_title_SelectGroup" Module="Core" Type="1">U2VsZWN0IEdyb3VwKHMp</PHRASE>
<PHRASE Label="la_title_SelectUser" Module="Core" Type="1">U2VsZWN0IFVzZXI=</PHRASE>
Index: core/install/install_schema.sql
===================================================================
--- core/install/install_schema.sql (revision 15390)
+++ core/install/install_schema.sql (working copy)
@@ -719,7 +719,7 @@
`Type` tinyint(3) unsigned NOT NULL DEFAULT '1',
`Status` tinyint(3) unsigned NOT NULL DEFAULT '1',
`Event` varchar(255) NOT NULL DEFAULT '',
- RunInterval int(10) unsigned NOT NULL DEFAULT '0',
+ RunSchedule varchar(255) NOT NULL DEFAULT '* * * * *',
LastRunOn int(10) unsigned DEFAULT NULL,
LastRunStatus tinyint(3) unsigned NOT NULL DEFAULT '1',
NextRunOn int(11) DEFAULT NULL,
@@ -729,7 +729,6 @@
SiteDomainLimitation varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (ScheduledTaskId),
KEY `Status` (`Status`),
- KEY RunInterval (RunInterval),
KEY LastRunOn (LastRunOn),
KEY LastRunStatus (LastRunStatus),
KEY RunTime (RunTime),
Index: core/install/upgrades.sql
===================================================================
--- core/install/upgrades.sql (revision 15421)
+++ core/install/upgrades.sql (working copy)
@@ -2760,3 +2760,6 @@
# ===== v 5.2.0 =====
INSERT INTO SystemSettings VALUES(DEFAULT, 'CategoryPermissionRebuildMode', '3', 'In-Portal', 'in-portal:configure_categories', 'la_title_General', 'la_config_CategoryPermissionRebuildMode', 'select', NULL, '1=la_opt_Manual||2=la_opt_Silent||3=la_opt_Automatic', 10.11, 0, 0, 'hint:la_config_CategoryPermissionRebuildMode');
DELETE FROM LanguageLabels WHERE PhraseKey = 'LA_CONFIG_QUICKCATEGORYPERMISSIONREBUILD';
+ALTER TABLE ScheduledTasks ADD RunSchedule VARCHAR(255) NOT NULL DEFAULT '* * * * *' AFTER Event;
+DELETE FROM UserPersistentSessionData WHERE VariableName = 'scheduled-task[Default]columns_.';
+DELETE FROM LanguageLabels WHERE PhraseKey = 'LA_FLD_RUNINTERVAL';
Index: core/kernel/application.php
===================================================================
--- core/kernel/application.php (revision 15374)
+++ core/kernel/application.php (working copy)
@@ -2105,13 +2105,13 @@
*
* @param string $short_name name to be used to store last maintenance run info
* @param string $event_string
- * @param int $run_interval run interval in seconds
+ * @param int $run_schedule run schedule like for Cron
* @param int $status
* @access public
*/
- public function registerScheduledTask($short_name, $event_string, $run_interval, $status = STATUS_ACTIVE)
+ public function registerScheduledTask($short_name, $event_string, $run_schedule, $status = STATUS_ACTIVE)
{
- $this->EventManager->registerScheduledTask($short_name, $event_string, $run_interval, $status);
+ $this->EventManager->registerScheduledTask($short_name, $event_string, $run_schedule, $status);
}
/**
Index: core/kernel/event_manager.php
===================================================================
--- core/kernel/event_manager.php (revision 15359)
+++ core/kernel/event_manager.php (working copy)
@@ -118,13 +118,13 @@
*
* @param string $short_name name to be used to store last maintenance run info
* @param string $event_string
- * @param int $run_interval run interval in seconds
+ * @param int $run_schedule run schedule like for Cron
* @param int $status
* @access public
*/
- public function registerScheduledTask($short_name, $event_string, $run_interval, $status = STATUS_ACTIVE)
+ public function registerScheduledTask($short_name, $event_string, $run_schedule, $status = STATUS_ACTIVE)
{
- $this->ScheduledTasks->add($short_name, $event_string, $run_interval, $status);
+ $this->ScheduledTasks->add($short_name, $event_string, $run_schedule, $status);
}
/**
Index: core/kernel/languages/phrases_cache.php
===================================================================
--- core/kernel/languages/phrases_cache.php (revision 15359)
+++ core/kernel/languages/phrases_cache.php (working copy)
@@ -207,7 +207,7 @@
return 'impossible case';
}
- // cut exclamation marks - depricated form of passing phrase name from templates
+ // cut exclamation marks - deprecated form of passing phrase name from templates
$label = preg_replace('/^!(.*)!$/', '\\1', $label);
if ( strlen($label) == 0 ) {
Index: core/kernel/managers/scheduled_task_manager.php
===================================================================
--- core/kernel/managers/scheduled_task_manager.php (revision 15359)
+++ core/kernel/managers/scheduled_task_manager.php (working copy)
@@ -80,14 +80,14 @@
*
* @param string $short_name name to be used to store last maintenance run info
* @param string $event_string
- * @param int $run_interval run interval in seconds
+ * @param int $run_schedule run schedule like for Cron
* @param int $status
* @access public
*/
- public function add($short_name, $event_string, $run_interval, $status = STATUS_ACTIVE)
+ public function add($short_name, $event_string, $run_schedule, $status = STATUS_ACTIVE)
{
$this->tasks[$short_name] = Array (
- 'Event' => $event_string, 'RunInterval' => $run_interval, 'Status' => $status
+ 'Event' => $event_string, 'RunSchedule' => $run_schedule, 'Status' => $status
);
}
@@ -162,13 +162,16 @@
return false;
}
+ $cron_helper = $this->Application->recallObject('kCronHelper');
+ /* @var $cron_helper kCronHelper */
+
$start_time = adodb_mktime();
// remember, when scheduled task execution started
$fields_hash = Array (
'LastRunOn' => $start_time,
'LastRunStatus' => ScheduledTask::LAST_RUN_RUNNING,
- 'NextRunOn' => $start_time + $scheduled_task_data['RunInterval'],
+ 'NextRunOn' => $cron_helper->getMatch($scheduled_task_data['RunSchedule'], $start_time),
);
$this->update($scheduled_task_data['Name'], $fields_hash);
@@ -177,11 +180,11 @@
$this->Application->HandleEvent($event);
$now = adodb_mktime();
- $next_run = $scheduled_task_data['RunInterval'] ? $start_time + $scheduled_task_data['RunInterval'] : $now;
+ $next_run = $cron_helper->getMatch($scheduled_task_data['RunSchedule'], $start_time);
while ($next_run < $now) {
- // in case event execution took longer, then RunInterval (don't use <=, because RunInterval can be 0)
- $next_run += $scheduled_task_data['RunInterval'];
+ // in case event execution took longer, then RunSchedule (don't use <=, because RunSchedule can be 0)
+ $next_run = $cron_helper->getMatch($scheduled_task_data['RunSchedule'], $next_run);
}
// remember, when scheduled task execution ended
Index: core/kernel/utility/unit_config_reader.php
===================================================================
--- core/kernel/utility/unit_config_reader.php (revision 15359)
+++ core/kernel/utility/unit_config_reader.php (working copy)
@@ -442,7 +442,7 @@
foreach ($scheduled_tasks as $short_name => $scheduled_task_info) {
$event_status = array_key_exists('Status', $scheduled_task_info) ? $scheduled_task_info['Status'] : STATUS_ACTIVE;
- $this->Application->delayUnitProcessing('registerScheduledTask', Array ( $short_name, $config['Prefix'] . ':' . $scheduled_task_info['EventName'], $scheduled_task_info['RunInterval'], $event_status ));
+ $this->Application->delayUnitProcessing('registerScheduledTask', Array ( $short_name, $config['Prefix'] . ':' . $scheduled_task_info['EventName'], $scheduled_task_info['RunSchedule'], $event_status ));
}
}
Index: core/units/admin/admin_config.php
===================================================================
--- core/units/admin/admin_config.php (revision 15359)
+++ core/units/admin/admin_config.php (working copy)
@@ -25,7 +25,7 @@
),
'ScheduledTasks' => Array(
- 'optimize_performance' => Array('EventName' => 'OnOptimizePerformance', 'RunInterval' => 86400),
+ 'optimize_performance' => Array('EventName' => 'OnOptimizePerformance', 'RunSchedule' => '0 0 * * *'),
),
'TitlePresets' => Array (
Index: core/units/forms/forms/forms_config.php
===================================================================
--- core/units/forms/forms/forms_config.php (revision 15359)
+++ core/units/forms/forms/forms_config.php (working copy)
@@ -31,8 +31,8 @@
),
'ScheduledTasks' => Array (
- 'check_submission_repies' => Array('EventName' => 'OnProcessReplies', 'RunInterval' => 3600),
- 'check_bounced_submission_repies' => Array('EventName' => 'OnProcessBouncedReplies', 'RunInterval' => 18000),
+ 'check_submission_repies' => Array('EventName' => 'OnProcessReplies', 'RunSchedule' => '0 * * * *'),
+ 'check_bounced_submission_repies' => Array('EventName' => 'OnProcessBouncedReplies', 'RunSchedule' => '0 */5 * * *'),
),
'Hooks' => Array(
Index: core/units/helpers/cron_helper.php
===================================================================
--- core/units/helpers/cron_helper.php (revision 0)
+++ core/units/helpers/cron_helper.php (revision 0)
@@ -0,0 +1,680 @@
+<?php
+/**
+* @version $Id$
+* @package In-Portal
+* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
+* @license GNU/GPL
+* In-Portal is Open Source software.
+* This means that this software may have been modified pursuant
+* the GNU General Public License, and as distributed it includes
+* or is derivative of works licensed under the GNU General Public License
+* or other free or open source software licenses.
+* See http://www.in-portal.org/license for copyright notices and details.
+*/
+
+defined('FULL_PATH') or die('restricted access!');
+
+class kCronHelper extends kHelper {
+
+ const COMMON = 0;
+ const MINUTE = 1;
+ const HOUR = 2;
+ const DAY = 3;
+ const MONTH = 4;
+ const WEEKDAY = 5;
+
+ /**
+ * Defines possible cron fields and their matching priority
+ *
+ * @var Array
+ * @access protected
+ */
+ protected $fieldTypes = Array (self::MONTH, self::DAY, self::WEEKDAY, self::HOUR, self::MINUTE);
+
+ protected $commonSettings = Array (
+ '* * * * *' => 'la_opt_CronEveryMinute',
+ '*/5 * * * *' => 'la_opt_CronEveryFiveMinutes',
+ '0,30 * * * *' => 'la_opt_CronTwiceAnHour',
+ '0 * * * *' => 'la_opt_CronOnceAnHour',
+ '0 0,12 * * *' => 'la_opt_CronTwiceADay',
+ '0 0 * * *' => 'la_opt_CronOnceADay',
+ '0 0 * * 0' => 'la_opt_CronOnceAWeek',
+ '0 0 1,15 * *' => 'la_opt_CronTwiceAMonth',
+ '0 0 1 * *' => 'la_opt_CronOnceAMonth',
+ '0 0 1 1 *' => 'la_opt_CronOnceAYear',
+ );
+
+ protected $minuteSettings = Array (
+ '*' => 'la_opt_CronEveryMinute',
+ '*/2' => 'la_opt_CronEveryOtherMinute',
+ '*/5' => 'la_opt_CronEveryFiveMinutes',
+ '*/10' => 'la_opt_CronEveryTenMinutes',
+ '*/15' => 'la_opt_CronEveryFifteenMinutes',
+ '0,30' => 'la_opt_CronEveryThirtyMinutes',
+ '--' => 'la_opt_CronMinutes',
+ // minutes added dynamically later
+ );
+
+ protected $hourSettings = Array (
+ '*' => 'la_opt_CronEveryHour',
+ '*/2' => 'la_opt_CronEveryOtherHour',
+ '*/3' => 'la_opt_CronEveryThreeHours',
+ '*/4' => 'la_opt_CronEveryFourHours',
+ '*/6' => 'la_opt_CronEverySixHours',
+ '0,12' => 'la_opt_CronEveryTwelveHours',
+ '--' => 'la_opt_CronHours',
+ // hours added dynamically later
+ );
+
+ protected $daySettings = Array (
+ '*' => 'la_opt_CronEveryDay',
+ '*/2' => 'la_opt_CronEveryOtherDay',
+ '1,15' => 'la_opt_CronTwiceAMonth',
+ '--' => 'la_opt_CronDays',
+ // days added dynamically later
+ );
+
+ protected $monthSettings = Array (
+ '*' => 'la_opt_CronEveryMonth',
+ '*/2' => 'la_opt_CronEveryOtherMonth',
+ '*/4' => 'la_opt_CronEveryThreeMonths',
+ '1,7' => 'la_opt_CronEverySixMonths',
+ '--' => 'la_opt_CronMonths',
+ '1' => 'la_opt_January',
+ '2' => 'la_opt_February',
+ '3' => 'la_opt_March',
+ '4' => 'la_opt_April',
+ '5' => 'la_opt_May',
+ '6' => 'la_opt_June',
+ '7' => 'la_opt_July',
+ '8' => 'la_opt_August',
+ '9' => 'la_opt_September',
+ '10' => 'la_opt_October',
+ '11' => 'la_opt_November',
+ '12' => 'la_opt_December',
+ );
+
+ protected $weekdaySettings = Array (
+ '*' => 'la_opt_CronEveryWeekday',
+ '1-5' => 'la_opt_CronMondayThroughFriday',
+ '0,6' => 'la_opt_CronSaturdayAndSunday',
+ '1,3,5' => 'la_opt_CronMondayWednesdayAndFriday',
+ '2,4' => 'la_opt_CronTuesdayAndThursday',
+ '--' => 'la_opt_CronWeekdays',
+ '0' => 'la_opt_Sunday',
+ '1' => 'la_opt_Monday',
+ '2' => 'la_opt_Tuesday',
+ '3' => 'la_opt_Wednesday',
+ '4' => 'la_opt_Thursday',
+ '5' => 'la_opt_Friday',
+ '6' => 'la_opt_Saturday',
+ );
+
+ /**
+ * Returns possible field options by type
+ *
+ * @param int $field_type
+ * @return Array
+ */
+ public function getOptions($field_type)
+ {
+ $mapping = Array (
+ self::COMMON => $this->commonSettings,
+ self::MINUTE => $this->minuteSettings,
+ self::HOUR => $this->hourSettings,
+ self::DAY => $this->daySettings,
+ self::MONTH => $this->monthSettings,
+ self::WEEKDAY => $this->weekdaySettings,
+ );
+
+ $ret = $mapping[$field_type];
+ /* @var $ret Array */
+
+ foreach ($ret as $option_key => $option_title) {
+ $option_title = substr($option_title, 0, 1) == '+' ? substr($option_title, 1) : $this->Application->Phrase($option_title);
+ $ret[$option_key] = $option_title;
+
+ if ( "$option_key" !== '--' ) {
+ $ret[$option_key] .= ' (' . $option_key . ')';
+ }
+ }
+
+ if ( $field_type == self::MINUTE ) {
+ for ($i = 0; $i <= 59; $i++) {
+ $ret[$i] = ':' . str_pad($i, 2, '0', STR_PAD_LEFT) . ' (' . $i . ')';
+ }
+ }
+ elseif ( $field_type == self::HOUR ) {
+ $language = $this->Application->recallObject('lang.current');
+ /* @var $language LanguagesItem */
+
+ $short_time_format = str_replace(':s', '', $language->GetDBField('TimeFormat'));
+
+ for ($i = 0; $i <= 23; $i++) {
+ $ret[$i] = adodb_date($short_time_format, adodb_mktime($i, 0, 0)) . ' (' . $i . ')';
+ }
+ }
+ elseif ( $field_type == self::DAY ) {
+ $ml_helper = $this->Application->recallObject('kMultiLanguageHelper');
+ /* @var $ml_helper kMultiLanguageHelper */
+
+ $forms = Array (
+ 'phrase1' => 'la_NumberSuffixSt', 'phrase2' => 'la_NumberSuffixNd', 'phrase3' => 'la_NumberSuffixRd',
+ 'phrase4' => 'la_NumberSuffixTh', 'phrase5' => 'la_NumberSuffixTh'
+ );
+
+ for ($i = 1; $i <= 31; $i++) {
+ $ret[$i] = $i . $ml_helper->getPluralPhrase($i, $forms) . ' (' . $i . ')';
+ }
+ }
+
+ return $ret;
+ }
+
+ /**
+ * Returns field name by type
+ *
+ * @param int $field_type
+ * @param string $field_prefix
+ * @return string
+ * @access protected
+ */
+ protected function _getFieldNameByType($field_type, $field_prefix)
+ {
+ $field_mapping = Array (
+ self::MINUTE => 'Minute',
+ self::HOUR => 'Hour',
+ self::DAY => 'Day',
+ self::MONTH => 'Month',
+ self::WEEKDAY => 'Weekday',
+ );
+
+ return $field_prefix . $field_mapping[$field_type];
+ }
+
+ /**
+ * Creates virtual fields for given unit
+ *
+ * @param string $prefix
+ * @param string $field_prefix
+ * @return void
+ * @access public
+ */
+ public function initUnit($prefix, $field_prefix = '')
+ {
+ $virtual_fields = $this->Application->getUnitOption($prefix, 'VirtualFields', Array ());
+
+ $virtual_fields[$field_prefix . 'CommonHints'] = Array (
+ 'type' => 'string',
+ 'formatter' => 'kOptionsFormatter', 'options' => $this->getOptions(self::COMMON),
+ 'default' => ''
+ );
+
+ foreach ($this->fieldTypes as $field_type) {
+ $field_name = $this->_getFieldNameByType($field_type, $field_prefix);
+ $virtual_fields[$field_name] = Array ('type' => 'string', 'max_len' => 30, 'default' => '*');
+
+ $virtual_fields[$field_name . 'Hints'] = Array (
+ 'type' => 'string',
+ 'formatter' => 'kOptionsFormatter', 'options' => $this->getOptions($field_type),
+ 'default' => ''
+ );
+ }
+
+ $this->Application->setUnitOption($prefix, 'VirtualFields', $virtual_fields);
+ }
+
+ /**
+ * Loads schedule values from database into virtual fields
+ *
+ * @param kDBItem $object
+ * @param string $field_prefix
+ */
+ public function load(kDBItem $object, $field_prefix = '')
+ {
+ $combined_value = explode(' ', $object->GetDBField($field_prefix));
+
+ foreach ($this->fieldTypes as $field_type) {
+ $field_name = $this->_getFieldNameByType($field_type, $field_prefix);
+ $object->SetDBField($field_name, $combined_value[$field_type - 1]);
+ }
+ }
+
+ /**
+ * Validates schedule values and saves them to database
+ *
+ * @param kDBItem $object
+ * @param string $field_prefix
+ * @return bool
+ * @access public
+ */
+ public function validateAndSave(kDBItem $object, $field_prefix = '')
+ {
+ $validated = true;
+ $combined_value = Array ();
+ $cron_field = new kCronField();
+
+ foreach ($this->fieldTypes as $field_type) {
+ $field_name = $this->_getFieldNameByType($field_type, $field_prefix);
+ $value = preg_replace('/\s+/s', '', mb_strtoupper($object->GetDBField($field_name)));
+
+ if ( $cron_field->validate($field_type, $value) ) {
+ $object->SetDBField($field_name, $value);
+ }
+ else {
+ $validated = false;
+ $object->SetError($field_name, 'invalid_format');
+ }
+
+ $combined_value[$field_type] = $value;
+ }
+
+ ksort($combined_value);
+ $object->SetDBField($field_prefix, implode(' ', $combined_value));
+
+ return $validated;
+ }
+
+ /**
+ * Replaces aliases in the field
+ *
+ * @param int $field_type
+ * @param string $value
+ * @return string
+ * @access public
+ */
+ public static function replaceAliases($field_type, $value)
+ {
+ $replacements = Array ();
+ $value = mb_strtolower($value);
+
+ if ( $field_type == self::MONTH ) {
+ $replacements = Array (
+ 'jan' => 1, 'feb' => 2, 'mar' => 3, 'apr' => 4, 'may' => 5, 'jun' => 6,
+ 'jul' => 7, 'aug' => 8, 'sep' => 9, 'oct' => 10, 'nov' => 11, 'dec' => 12,
+ );
+ }
+ elseif ( $field_type == self::WEEKDAY ) {
+ $replacements = Array ('sun' => 0, 'mon' => 1, 'tue' => 2, 'wed' => 3, 'thu' => 4, 'fri' => 5, 'sat' => 6);
+ }
+
+ if ( $replacements ) {
+ $value = str_replace(array_keys($replacements), array_values($replacements), $value);
+ }
+
+ return $value;
+ }
+
+ /**
+ * Returns next (after given one or now) timestamp matching given cron expression
+ *
+ * @param string $expression
+ * @param int $date
+ * @param bool $inverse
+ * @param bool $allow_current_date
+ * @return int
+ * @access public
+ * @throws RuntimeException
+ */
+ public function getMatch($expression, $date = NULL, $inverse = false, $allow_current_date = false)
+ {
+ if ( !isset($date) ) {
+ $date = TIMENOW;
+ }
+
+ $next_run = strtotime('-' . (int)adodb_date('s', $date) . ' seconds', $date);
+ $expression_parts = explode(' ', $expression);
+
+ $cron_field = new kCronField();
+
+ // set a hard limit to bail on an impossible date
+ for ($i = 0; $i < 1000; $i++) {
+ foreach ($this->fieldTypes as $field_type) {
+ $matched = false;
+ $part = $expression_parts[$field_type - 1];
+
+ // check if this is singular or a list
+ if ( strpos($part, ',') === false ) {
+ $matched = $cron_field->match($field_type, $next_run, $part);
+ }
+ else {
+ $rules = explode(',', $part);
+
+ foreach ($rules as $rule) {
+ if ( $cron_field->match($field_type, $next_run, $rule) ) {
+ $matched = true;
+ break;
+ }
+ }
+ }
+
+ // if the field is not matched, then start over
+ if ( !$matched ) {
+ $next_run = $cron_field->increment($field_type, $next_run, $inverse);
+ continue 2;
+ }
+ }
+
+ // Skip this match if needed
+ if ( (!$allow_current_date && $next_run == $date) ) {
+ $next_run = $cron_field->increment(self::MINUTE, $next_run, $inverse);
+ continue;
+ }
+
+ return $next_run;
+ }
+
+ throw new RuntimeException('Impossible CRON expression');
+ }
+}
+
+
+class kCronField extends kBase {
+
+ /**
+ * Validates field value
+ *
+ * @param int $field_type
+ * @param string $value
+ * @param bool $asterisk_allowed
+ * @return bool
+ * @access public
+ */
+ public function validate($field_type, $value, $asterisk_allowed = true)
+ {
+ $rules = explode(',', kCronHelper::replaceAliases($field_type, $value));
+
+ foreach ($rules as $rule) {
+ if ( $this->_isIncrementRule($rule) ) {
+ if ( !$this->_validateIncrementRule($field_type, $rule) ) {
+ return false;
+ }
+ }
+ elseif ( $this->_isRangeRule($rule) ) {
+ if ( !$this->_validateRangeRule($field_type, $rule) ) {
+ return false;
+ }
+ }
+ elseif ( !$this->_validateNumberRule($field_type, $rule, $asterisk_allowed) ) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Determines if expression is range
+ *
+ * @param string $rule
+ * @return bool
+ * @access protected
+ */
+ protected function _isRangeRule($rule)
+ {
+ return strpos($rule, '-') !== false;
+ }
+
+ /**
+ * Validates range rule
+ *
+ * @param int $field_type
+ * @param string $rule
+ * @return bool
+ * @access protected
+ */
+ protected function _validateRangeRule($field_type, $rule)
+ {
+ $parts = explode('-', $rule);
+
+ if ( count($parts) != 2 ) {
+ return false;
+ }
+
+ $min_value = $parts[0];
+ $max_value = $parts[1];
+
+ if ( !$this->_validateNumberRule($field_type, $min_value) || !$this->_validateNumberRule($field_type, $max_value) || $min_value >= $max_value ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Determines if expression is increment
+ *
+ * @param string $rule
+ * @return bool
+ * @access protected
+ */
+ protected function _isIncrementRule($rule)
+ {
+ return strpos($rule, '/') !== false;
+ }
+
+ /**
+ * Validates increment rule
+ *
+ * @param int $field_type
+ * @param string $rule
+ * @return bool
+ * @access protected
+ */
+ protected function _validateIncrementRule($field_type, $rule)
+ {
+ $parts = explode('/', $rule);
+
+ if ( count($parts) != 2 ) {
+ return false;
+ }
+
+ $interval = $parts[0];
+ $increment = $parts[1];
+
+ if ( $this->_isRangeRule($interval) ) {
+ if ( !$this->_validateRangeRule($field_type, $interval) ) {
+ return false;
+ }
+ }
+ elseif ( !$this->_validateNumberRule($field_type, $interval, true) ) {
+ return false;
+ }
+
+ if ( !$this->_validateNumberRule($field_type, $increment) ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Validates, that number within range OR an asterisk is given
+ *
+ * @param int $field_type
+ * @param string $rule
+ * @param bool $asterisk_allowed
+ * @return bool
+ * @access protected
+ */
+ protected function _validateNumberRule($field_type, $rule, $asterisk_allowed = false)
+ {
+ if ( "$rule" === '*' ) {
+ return $asterisk_allowed;
+ }
+
+ $int_rule = (int)$rule;
+
+ if ( !is_numeric($rule) || "$int_rule" !== "$rule" ) {
+ // not integer
+ return false;
+ }
+
+ $range_mapping = Array (
+ kCronHelper::MINUTE => Array ('from' => 0, 'to' => 59),
+ kCronHelper::HOUR => Array ('from' => 0, 'to' => 23),
+ kCronHelper::DAY => Array ('from' => 1, 'to' => 31),
+ kCronHelper::MONTH => Array ('from' => 1, 'to' => 12),
+ kCronHelper::WEEKDAY => Array ('from' => 0, 'to' => 7),
+ );
+
+ return $int_rule >= $range_mapping[$field_type]['from'] && $int_rule <= $range_mapping[$field_type]['to'];
+ }
+
+ /**
+ * Tries to match given date to given expression
+ *
+ * @param int $field_type
+ * @param int $date
+ * @param string $rule
+ * @return bool
+ * @access public
+ */
+ public function match($field_type, $date, $rule)
+ {
+ $date_part = $this->_getDatePart($field_type, $date, $rule);
+
+ if ( $this->_isIncrementRule($rule) ) {
+ return $this->_isInIncrement($date_part, $rule);
+ }
+ elseif ( $this->_isRangeRule($rule) ) {
+ return $this->_isInRange($date_part, $rule);
+ }
+
+ return $rule == '*' || $date_part == $rule;
+ }
+
+ /**
+ * Returns only part, needed based on field type of date in timestamp
+ *
+ * @param int $field_type
+ * @param int $date
+ * @param string $rule
+ * @return int
+ * @access protected
+ */
+ protected function _getDatePart($field_type, $date, $rule)
+ {
+ $mapping = Array (
+ kCronHelper::MINUTE => 'i',
+ kCronHelper::HOUR => 'G',
+ kCronHelper::DAY => 'j',
+ kCronHelper::MONTH => 'n',
+ kCronHelper::WEEKDAY => 'N',
+ );
+
+ if ( $field_type == kCronHelper::WEEKDAY ) {
+ // Test to see which Sunday to use -- 0 == 7 == Sunday
+ $mapping[$field_type] = in_array(7, str_split($rule)) ? 'N' : 'w';
+ }
+
+ return (int)adodb_date($mapping[$field_type], $date);
+ }
+
+ /**
+ * Test if a value is within a range
+ *
+ * @param string $date_value Set date value
+ * @param string $rule Value to test
+ * @return bool
+ * @access protected
+ */
+ protected function _isInRange($date_value, $rule)
+ {
+ $parts = array_map('trim', explode('-', $rule, 2));
+
+ return $date_value >= $parts[0] && $date_value <= $parts[1];
+ }
+
+ /**
+ * Test if a value is within an increments of ranges (offset[-to]/step size)
+ *
+ * @param string $date_value Set date value
+ * @param string $rule Value to test
+ * @return bool
+ * @access protected
+ */
+ protected function _isInIncrement($date_value, $rule)
+ {
+ $parts = array_map('trim', explode('/', $rule, 2));
+ $stepSize = isset($parts[1]) ? $parts[1] : 0;
+
+ if ( $parts[0] == '*' || $parts[0] == 0 ) {
+ return (int)$date_value % $stepSize == 0;
+ }
+
+ $range = explode('-', $parts[0], 2);
+ $offset = $range[0];
+ $to = isset($range[1]) ? $range[1] : $date_value;
+
+ // Ensure that the date value is within the range
+ if ( $date_value < $offset || $date_value > $to ) {
+ return false;
+ }
+
+ for ($i = $offset; $i <= $to; $i += $stepSize) {
+ if ( $i == $date_value ) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Increments/decrements given date for 1 unit based on field type
+ *
+ * @param int $field_type
+ * @param int $date
+ * @param bool $inverse
+ * @return int
+ * @access public
+ */
+ public function increment($field_type, $date, $inverse = false)
+ {
+ $mapping = Array (
+ kCronHelper::MINUTE => '1 minute',
+ kCronHelper::HOUR => '1 hour',
+ kCronHelper::DAY => '1 day',
+ kCronHelper::MONTH => '1 month',
+ kCronHelper::WEEKDAY => '1 day',
+ );
+
+ return $this->_resetTime($field_type, strtotime(($inverse ? '-' : '+') . $mapping[$field_type], $date), $inverse);
+ }
+
+ /**
+ * Resets time based on field type
+ *
+ * @param int $field_type
+ * @param int $date
+ * @param bool $inverse
+ * @return int
+ * @access public
+ */
+ protected function _resetTime($field_type, $date, $inverse = false)
+ {
+ if ( $field_type == kCronHelper::MONTH || $field_type == kCronHelper::WEEKDAY || $field_type == kCronHelper::DAY ) {
+ if ( $inverse ) {
+ $date = strtotime(adodb_date('Y-m-d 23:59:59', $date));
+ // set time 23:59:00
+ }
+ else {
+ // set time 00:00:00
+ $date = strtotime(adodb_date('Y-m-d 00:00:00', $date));
+ }
+ }
+ elseif ( $field_type == kCronHelper::HOUR ) {
+ if ( $inverse ) {
+ // set time <current_hour>:59:00
+ $date = strtotime(adodb_date('Y-m-d H:59:59', $date));
+ }
+ else {
+ // set time <current_hour>:00:00
+ $date = strtotime(adodb_date('Y-m-d H:00:00', $date));
+ }
+ }
+
+ return $date;
+ }
+}
\ No newline at end of file
Index: core/units/helpers/helpers_config.php
===================================================================
--- core/units/helpers/helpers_config.php (revision 15359)
+++ core/units/helpers/helpers_config.php (working copy)
@@ -72,5 +72,6 @@
Array ('pseudo' => 'PageHelper', 'class' => 'PageHelper', 'file' => 'page_helper.php', 'build_event' => ''),
Array ('pseudo' => 'BackupHelper', 'class' => 'BackupHelper', 'file' => 'backup_helper.php', 'build_event' => ''),
Array ('pseudo' => 'AjaxFormHelper', 'class' => 'AjaxFormHelper', 'file' => 'ajax_form_helper.php', 'build_event' => ''),
+ Array ('pseudo' => 'kCronHelper', 'class' => 'kCronHelper', 'file' => 'cron_helper.php', 'build_event' => ''),
),
);
\ No newline at end of file
Index: core/units/images/images_config.php
===================================================================
--- core/units/images/images_config.php (revision 15359)
+++ core/units/images/images_config.php (working copy)
@@ -70,8 +70,8 @@
),
'ScheduledTasks' => Array (
- 'clean_catalog_images' => Array ('EventName' => 'OnCleanImages', 'RunInterval' => 604800, 'Status' => STATUS_DISABLED),
- 'clean_resized_catalog_images' => Array ('EventName' => 'OnCleanResizedImages', 'RunInterval' => 2592000, 'Status' => STATUS_DISABLED),
+ 'clean_catalog_images' => Array ('EventName' => 'OnCleanImages', 'RunSchedule' => '0 0 * * 0', 'Status' => STATUS_DISABLED),
+ 'clean_resized_catalog_images' => Array ('EventName' => 'OnCleanResizedImages', 'RunSchedule' => '0 0 1 * *', 'Status' => STATUS_DISABLED),
),
'IDField' => 'ImageId',
Index: core/units/logs/email_logs/email_logs_config.php
===================================================================
--- core/units/logs/email_logs/email_logs_config.php (revision 15363)
+++ core/units/logs/email_logs/email_logs_config.php (working copy)
@@ -32,7 +32,7 @@
),
'ScheduledTasks' => Array(
- 'rotate_email_logs' => Array('EventName' => 'OnRotate', 'RunInterval' => 86400),
+ 'rotate_email_logs' => Array('EventName' => 'OnRotate', 'RunSchedule' => '0 0 * * *'),
),
'IDField' => 'EmailLogId',
Index: core/units/mailing_lists/mailing_lists_config.php
===================================================================
--- core/units/mailing_lists/mailing_lists_config.php (revision 15359)
+++ core/units/mailing_lists/mailing_lists_config.php (working copy)
@@ -32,8 +32,8 @@
),
'ScheduledTasks' => Array (
- 'generate_mailing_queue' => Array ('EventName' => 'OnGenerateEmailQueue', 'RunInterval' => 1800),
- 'process_mailing_queue' => Array ('EventName' => 'OnProcessEmailQueue', 'RunInterval' => 1800),
+ 'generate_mailing_queue' => Array ('EventName' => 'OnGenerateEmailQueue', 'RunSchedule' => '*/30 * * * *'),
+ 'process_mailing_queue' => Array ('EventName' => 'OnProcessEmailQueue', 'RunSchedule' => '*/30 * * * *'),
),
'IDField' => 'MailingId',
Index: core/units/scheduled_tasks/scheduled_task_eh.php
===================================================================
--- core/units/scheduled_tasks/scheduled_task_eh.php (revision 15359)
+++ core/units/scheduled_tasks/scheduled_task_eh.php (working copy)
@@ -78,6 +78,9 @@
$processed_ids = Array ();
$scheduled_tasks_from_db = $this->Conn->Query($object->GetSelectSQL(), 'Name');
+ $cron_helper = $this->Application->recallObject('kCronHelper');
+ /* @var $cron_helper kCronHelper */
+
foreach ($scheduled_tasks_from_cache as $scheduled_task_name => $scheduled_task_params) {
if ( !isset($scheduled_tasks_from_db[$scheduled_task_name]) ) {
$fields_hash = Array (
@@ -85,11 +88,12 @@
'Name' => $scheduled_task_name,
'Type' => ScheduledTask::TYPE_SYSTEM,
'Status' => isset($scheduled_task_params['Status']) ? $scheduled_task_params['Status'] : STATUS_ACTIVE,
- 'RunInterval' => $scheduled_task_params['RunInterval'],
+ 'RunSchedule' => $scheduled_task_params['RunSchedule'],
);
$object->Clear();
$object->SetDBFieldsFromHash($fields_hash);
+ $cron_helper->load($object, 'RunSchedule');
$object->Create();
}
else {
@@ -203,4 +207,92 @@
$this->clearSelectedIDs($event);
}
+
+ /**
+ * Loads schedule from database to virtual fields
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnAfterItemLoad(kEvent $event)
+ {
+ parent::OnAfterItemLoad($event);
+
+ $object = $event->getObject();
+ /* @var $object kDBItem */
+
+ $cron_helper = $this->Application->recallObject('kCronHelper');
+ /* @var $cron_helper kCronHelper */
+
+ $cron_helper->load($object, 'RunSchedule');
+ }
+
+ /**
+ * Validates schedule
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnBeforeItemCreate(kEvent $event)
+ {
+ parent::OnBeforeItemCreate($event);
+
+ $this->_itemChanged($event);
+ }
+
+ /**
+ * Validates schedule
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnBeforeItemUpdate(kEvent $event)
+ {
+ parent::OnBeforeItemUpdate($event);
+
+ $this->_itemChanged($event);
+ }
+
+ /**
+ * Validates schedule
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function _itemChanged(kEvent $event)
+ {
+ $object = $event->getObject();
+ /* @var $object kDBItem */
+
+ $cron_helper = $this->Application->recallObject('kCronHelper');
+ /* @var $cron_helper kCronHelper */
+
+ if ( $cron_helper->validateAndSave($object, 'RunSchedule') && !$object->GetDBField('NextRunOn_date') ) {
+ $next_run = $cron_helper->getMatch($object->GetDBField('RunSchedule'));
+ $object->SetDBField('NextRunOn_date', $next_run);
+ $object->SetDBField('NextRunOn_time', $next_run);
+ }
+ }
+
+ /**
+ * Creates schedule fields
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnAfterConfigRead(kEvent $event)
+ {
+ parent::OnAfterConfigRead($event);
+
+ $cron_helper = $this->Application->recallObject('kCronHelper');
+ /* @var $cron_helper kCronHelper */
+
+ $cron_helper->initUnit($event->Prefix, 'RunSchedule');
+
+ }
}
\ No newline at end of file
Index: core/units/scheduled_tasks/scheduled_tasks_config.php
===================================================================
--- core/units/scheduled_tasks/scheduled_tasks_config.php (revision 15359)
+++ core/units/scheduled_tasks/scheduled_tasks_config.php (working copy)
@@ -117,7 +117,7 @@
'type' => 'string', 'max_len' => 255,
'required' => 1, 'not_null' => 1, 'default' => ''
),
- 'RunInterval' => Array ('type' => 'int', 'required' => 1, 'not_null' => 1, 'default' => 0),
+ 'RunSchedule' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => '* * * * *'),
'LastRunOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => NULL),
'LastRunStatus' => Array (
@@ -126,7 +126,7 @@
'not_null' => 1, 'default' => 1
),
- 'NextRunOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'required' => 1, 'default' => '#NOW#'),
+ 'NextRunOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => NULL),
'RunTime' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'Timeout' => Array (
'type' => 'int',
@@ -148,18 +148,18 @@
0 => 'icon16_disabled.png',
),
'Fields' => Array (
- 'ScheduledTaskId' => Array ('title' => 'column:la_fld_Id', 'data_block' => 'grid_checkbox_td', 'filter_block' => 'grid_range_filter', 'width' => 50, ),
- 'Name' => Array ('filter_block' => 'grid_like_filter', 'width' => 200, ),
- 'Type' => Array ('filter_block' => 'grid_options_filter', 'width' => 60, ),
- 'Event' => Array ('filter_block' => 'grid_like_filter', 'width' => 280, ),
- 'RunInterval' => Array ('filter_block' => 'grid_range_filter', 'width' => 100, ),
- 'LastRunOn' => Array ('filter_block' => 'grid_date_range_filter', 'width' => 145, ),
- 'RunTime' => Array ('filter_block' => 'grid_range_filter', 'width' => 145, ),
- 'LastRunStatus' => Array ('filter_block' => 'grid_options_filter', 'width' => 120, ),
- 'NextRunOn' => Array ('filter_block' => 'grid_date_range_filter', 'width' => 145, ),
- 'Status' => Array ('filter_block' => 'grid_options_filter', 'width' => 65, ),
- 'Timeout' => Array ('filter_block' => 'grid_range_filter', 'width' => 85, ),
- 'LastTimeoutOn' => Array ('filter_block' => 'grid_date_range_filter', 'width' => 145, ),
+ 'ScheduledTaskId' => Array ('title' => 'column:la_fld_Id', 'filter_block' => 'grid_range_filter', 'width' => 80),
+ 'Name' => Array ('filter_block' => 'grid_like_filter', 'width' => 200),
+ 'Type' => Array ('filter_block' => 'grid_options_filter', 'width' => 60),
+ 'Event' => Array ('filter_block' => 'grid_like_filter', 'width' => 280),
+ 'RunSchedule' => Array ('filter_block' => 'grid_range_filter', 'width' => 100),
+ 'LastRunOn' => Array ('filter_block' => 'grid_date_range_filter', 'width' => 145),
+ 'RunTime' => Array ('filter_block' => 'grid_range_filter', 'width' => 100),
+ 'LastRunStatus' => Array ('filter_block' => 'grid_options_filter', 'width' => 90),
+ 'NextRunOn' => Array ('filter_block' => 'grid_date_range_filter', 'width' => 145),
+ 'Status' => Array ('filter_block' => 'grid_options_filter', 'width' => 65),
+ 'Timeout' => Array ('filter_block' => 'grid_range_filter', 'width' => 85),
+ 'LastTimeoutOn' => Array ('filter_block' => 'grid_date_range_filter', 'width' => 145),
'SiteDomainLimitation' => Array ('data_block' => 'grid_picker_td', 'filter_block' => 'grid_multioptions_filter', 'separator' => ', ', 'width' => 145),
),
),
Index: core/units/users/users_config.php
===================================================================
--- core/units/users/users_config.php (revision 15359)
+++ core/units/users/users_config.php (working copy)
@@ -93,8 +93,8 @@
),
'ScheduledTasks' => Array(
- 'membership_expiration' => Array('EventName' => 'OnCheckExpiredMembership', 'RunInterval' => 1800),
- 'delete_expired_sessions' => Array('EventName' => 'OnDeleteExpiredSessions', 'RunInterval' => 43200),
+ 'membership_expiration' => Array('EventName' => 'OnCheckExpiredMembership', 'RunSchedule' => '*/30 * * * *'),
+ 'delete_expired_sessions' => Array('EventName' => 'OnDeleteExpiredSessions', 'RunSchedule' => '0 */12 * * *'),
),
'IDField' => 'PortalUserId',
schedule_tasks_cron_interface_modules.patch [^] (4,808 bytes) 2012-07-12 09:47
[Show Content]
Index: in-auction/units/listing/listing_config.php
===================================================================
--- in-auction/units/listing/listing_config.php (revision 15331)
+++ in-auction/units/listing/listing_config.php (working copy)
@@ -23,7 +23,7 @@
'ScheduledTasks' => Array(
- 'list_items' => Array('EventName' => 'OnListItems', 'RunInterval' => 600),
+ 'list_items' => Array('EventName' => 'OnListItems', 'RunSchedule' => '*/10 * * * *'),
),
'QueryString' => Array (
Index: in-auction/units/sections/sections_config.php
===================================================================
--- in-auction/units/sections/sections_config.php (revision 15331)
+++ in-auction/units/sections/sections_config.php (working copy)
@@ -27,16 +27,16 @@
),
'ScheduledTasks' => Array(
- 'seller_transactions' => Array('EventName' => 'OnGetSellerTransactions', 'RunInterval' => 600),
- 'seller_list' => Array('EventName' => 'OnGetSellerList', 'RunInterval' => 600),
- 'auto_dispute' => Array('EventName' => 'OnAutoDispute', 'RunInterval' => 600),
- 'auctions_schedule' => Array('EventName' => 'OnProcessSchedule', 'RunInterval' => 1800),
- 'subscribe_ebay_notifications' => Array('EventName' => 'OnSubscribeListingNotifications', 'RunInterval' => 360000),
- 'delete_old_hits' => Array('EventName' => 'OnDeleteOldHits', 'RunInterval' => 72000),
- 'revise_checkout_statuses' => Array('EventName' => 'OnReviseCheckoutStatuses', 'RunInterval' => 43200),
- 'receive_feedbacks' => Array('EventName' => 'OnReceiveFeedbacks', 'RunInterval' => 43200),
- 'send_feedbacks' => Array('EventName' => 'OnSendFeedbacks', 'RunInterval' => 43200),
- 'send_feedback_notifications' => Array('EventName' => 'OnSendFeedbackNotifications', 'RunInterval' => 43200),
+ 'seller_transactions' => Array('EventName' => 'OnGetSellerTransactions', 'RunSchedule' => '*/10 * * * *'),
+ 'seller_list' => Array('EventName' => 'OnGetSellerList', 'RunSchedule' => '*/10 * * * *'),
+ 'auto_dispute' => Array('EventName' => 'OnAutoDispute', 'RunSchedule' => '*/10 * * * *'),
+ 'auctions_schedule' => Array('EventName' => 'OnProcessSchedule', 'RunSchedule' => '*/30 * * * *'),
+ 'subscribe_ebay_notifications' => Array('EventName' => 'OnSubscribeListingNotifications', 'RunSchedule' => '0 0 */5 * *'),
+ 'delete_old_hits' => Array('EventName' => 'OnDeleteOldHits', 'RunSchedule' => '0 */20 * * *'),
+ 'revise_checkout_statuses' => Array('EventName' => 'OnReviseCheckoutStatuses', 'RunSchedule' => '0 */12 * * *'),
+ 'receive_feedbacks' => Array('EventName' => 'OnReceiveFeedbacks', 'RunSchedule' => '0 */12 * * *'),
+ 'send_feedbacks' => Array('EventName' => 'OnSendFeedbacks', 'RunSchedule' => '0 */12 * * *'),
+ 'send_feedback_notifications' => Array('EventName' => 'OnSendFeedbackNotifications', 'RunSchedule' => '0 */12 * * *'),
),
Index: in-link/units/link_validation/link_validation_config.php
===================================================================
--- in-link/units/link_validation/link_validation_config.php (revision 15331)
+++ in-link/units/link_validation/link_validation_config.php (working copy)
@@ -45,7 +45,7 @@
),
'ScheduledTasks' => Array (
- 'link_validation' => Array ('EventName' => 'OnCronValidation', 'RunInterval' => 3600*24),
+ 'link_validation' => Array ('EventName' => 'OnCronValidation', 'RunSchedule' => '0 0 * * *'),
),
'IDField' => 'LinkValidationId',
Index: in-link/units/listings/listings_config.php
===================================================================
--- in-link/units/listings/listings_config.php (revision 15331)
+++ in-link/units/listings/listings_config.php (working copy)
@@ -44,7 +44,7 @@
),
'ScheduledTasks' => Array (
- 'listings_expiration' => Array ('EventName' => 'OnCheckExpiredPaidListings', 'RunInterval' => 1800),
+ 'listings_expiration' => Array ('EventName' => 'OnCheckExpiredPaidListings', 'RunSchedule' => '*/30 * * * *'),
),
'IDField' => 'ListingId',
Index: in-news/units/articles/articles_config.php
===================================================================
--- in-news/units/articles/articles_config.php (revision 15353)
+++ in-news/units/articles/articles_config.php (working copy)
@@ -132,7 +132,7 @@
),
'ScheduledTasks' => Array(
- 'update_rss_articles' => Array('EventName' => 'OnUpdateRSSArticles', 'RunInterval' => 60),
+ 'update_rss_articles' => Array('EventName' => 'OnUpdateRSSArticles', 'RunSchedule' => '* * * * *'),
),
'IDField' => 'NewsId',
'StatusField' => Array ('Status'), // field, that is affected by Approve/Decline events
schedule_tasks_cron_interface_core_upgrade_addon.patch [^] (2,206 bytes) 2012-07-16 06:20
[Show Content]
Index: upgrades.php
===================================================================
--- upgrades.php (revision 15448)
+++ upgrades.php (working copy)
@@ -2236,5 +2236,59 @@
$sql = 'DELETE FROM ' . TABLE_PREFIX . 'SystemSettings WHERE VariableName = "QuickCategoryPermissionRebuild"';
$this->Conn->Query($sql);
+
+ $this->_updateScheduledTaskRunSchedule();
}
+
+ /**
+ * Transforms RunInterval into RunSchedule column for Scheduled Tasks
+ *
+ * @return void
+ * @access protected
+ */
+ protected function _updateScheduledTaskRunSchedule()
+ {
+ // minute hour day_of_month month day_of_week
+ $id_field = $this->Application->getUnitOption('scheduled-task', 'IDField');
+ $table_name = $this->Application->getUnitOption('scheduled-task', 'TableName');
+
+ $sql = 'SELECT RunInterval, ' . $id_field . '
+ FROM ' . $table_name;
+ $run_intervals = $this->Conn->GetCol($sql, $id_field);
+
+ $ranges = Array (0 => 'min', 1 => 'hour', 2 => 'day', 3 => 'month');
+ $range_values = Array ('min' => 60, 'hour' => 60, 'day' => 24, 'month' => 30);
+ $range_masks = Array ('min' => '*/%s * * * *', 'hour' => '0 */%s * * *', 'day' => '0 0 */%s * *', 'month' => '0 0 1 */%s *');
+
+ foreach ($run_intervals as $scheduled_task_id => $interval) {
+ $mask_index = 'month';
+
+ foreach ($ranges as $range_index => $range_name) {
+ $range_value = $range_values[$range_name];
+
+ if ( $interval >= $range_value ) {
+ $interval = ceil($interval / $range_value);
+ }
+ else {
+ $mask_index = $ranges[$range_index - 1];
+ break;
+ }
+ }
+
+ $run_schedule = sprintf($range_masks[$mask_index], $interval);
+
+ if ( $run_schedule == '0 0 */7 * *' ) {
+ // once in 7 days = once in a week
+ $run_schedule = '0 0 * * 0';
+ }
+
+ $run_schedule = preg_replace('/(\*\/1( |$))/', '*\\2', $run_schedule);
+
+ $fields_hash = Array ('RunSchedule' => $run_schedule);
+ $this->Conn->doUpdate($fields_hash, $table_name, $id_field . ' = ' . $scheduled_task_id);
+ }
+
+ // drop RunInterval column
+ $this->Conn->Query('ALTER TABLE ' . $table_name . ' DROP RunInterval');
+ }
}
\ No newline at end of file
|