Commit 449fb3ff4c03f747975bf059fcb38e907542cbfc

Authored by Megan Watson
1 parent 3cb20a4f

KTS-2691

"Add the ability to enable / disable tasks within the scheduler"
Fixed.  Tasks can be set as enabled / disabled / system. System tasks can't be disabled.

Committed by: Megan Watson
Reviewed by: Conrad Vermeulen



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7719 c91229c3-7414-0410-bfa2-8a42b809f60b
bin/scheduler.php
@@ -96,7 +96,7 @@ function updateTask($aFieldValues, $iId) { @@ -96,7 +96,7 @@ function updateTask($aFieldValues, $iId) {
96 function getTaskList() { 96 function getTaskList() {
97 $now = date('Y-m-d H:i:s'); //time(); 97 $now = date('Y-m-d H:i:s'); //time();
98 98
99 - $query = "SELECT * FROM scheduler_tasks WHERE is_complete = 0 AND run_time < '{$now}'"; 99 + $query = "SELECT * FROM scheduler_tasks WHERE is_complete = 0 AND run_time < '{$now}' AND status != 'disabled'";
100 100
101 $result = DBUtil::getResultArray($query); 101 $result = DBUtil::getResultArray($query);
102 102
plugins/ktcore/scheduler/scheduler.php
1 <?php 1 <?php
2 /** 2 /**
3 - * $Id:$ 3 + * $Id:$
4 * 4 *
5 * KnowledgeTree Open Source Edition 5 * KnowledgeTree Open Source Edition
6 * Document Management Made Simple 6 * Document Management Made Simple
7 * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited 7 * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
8 - * 8 + *
9 * This program is free software; you can redistribute it and/or modify it under 9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 3 as published by the 10 * the terms of the GNU General Public License version 3 as published by the
11 * Free Software Foundation. 11 * Free Software Foundation.
12 - * 12 + *
13 * This program is distributed in the hope that it will be useful, but WITHOUT 13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * details. 16 * details.
17 - * 17 + *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 - * 20 + *
21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, 21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. 22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
23 - * 23 + *
24 * The interactive user interfaces in modified source and object code versions 24 * The interactive user interfaces in modified source and object code versions
25 * of this program must display Appropriate Legal Notices, as required under 25 * of this program must display Appropriate Legal Notices, as required under
26 * Section 5 of the GNU General Public License version 3. 26 * Section 5 of the GNU General Public License version 3.
27 - * 27 + *
28 * In accordance with Section 7(b) of the GNU General Public License version 3, 28 * In accordance with Section 7(b) of the GNU General Public License version 3,
29 * these Appropriate Legal Notices must retain the display of the "Powered by 29 * these Appropriate Legal Notices must retain the display of the "Powered by
30 - * KnowledgeTree" logo and retain the original copyright notice. If the display of the 30 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
31 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices 31 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
32 - * must display the words "Powered by KnowledgeTree" and retain the original  
33 - * copyright notice. 32 + * must display the words "Powered by KnowledgeTree" and retain the original
  33 + * copyright notice.
34 * Contributor( s): ______________________________________ 34 * Contributor( s): ______________________________________
35 * 35 *
36 */ 36 */
@@ -47,7 +47,8 @@ class Scheduler @@ -47,7 +47,8 @@ class Scheduler
47 var $aParams = ''; 47 var $aParams = '';
48 var $sFreq = 'daily'; 48 var $sFreq = 'daily';
49 var $iStartTime = ''; 49 var $iStartTime = '';
50 - 50 + var $sStatus = 'disabled';
  51 +
51 /** 52 /**
52 * Constructor function - set the name of the task 53 * Constructor function - set the name of the task
53 */ 54 */
@@ -56,14 +57,14 @@ class Scheduler @@ -56,14 +57,14 @@ class Scheduler
56 $this->sFreq = 'daily'; 57 $this->sFreq = 'daily';
57 $this->iStartTime = time(); 58 $this->iStartTime = time();
58 } 59 }
59 - 60 +
60 /** 61 /**
61 * Set the name of the task 62 * Set the name of the task
62 */ 63 */
63 function setTaskName($sName) { 64 function setTaskName($sName) {
64 $this->sName = $sName; 65 $this->sName = $sName;
65 } 66 }
66 - 67 +
67 /** 68 /**
68 * Set the path to the script from the KT base path 69 * Set the path to the script from the KT base path
69 * For example: "/var/tasks/script.php" or "/bin/script.php" 70 * For example: "/var/tasks/script.php" or "/bin/script.php"
@@ -71,14 +72,14 @@ class Scheduler @@ -71,14 +72,14 @@ class Scheduler
71 function setScriptPath($sPath) { 72 function setScriptPath($sPath) {
72 $this->sPath = $sPath; 73 $this->sPath = $sPath;
73 } 74 }
74 - 75 +
75 /** 76 /**
76 * Add a parameter pair to pass to the script 77 * Add a parameter pair to pass to the script
77 */ 78 */
78 function addParameter($param, $value){ 79 function addParameter($param, $value){
79 $this->aParams[$param] = $value; 80 $this->aParams[$param] = $value;
80 } 81 }
81 - 82 +
82 /** 83 /**
83 * Set the frequency with which the task must be run 84 * Set the frequency with which the task must be run
84 * Frequencies are: daily, weekly, monthly, hourly, half_hourly, quarter_hourly, 10mins, 5mins and once 85 * Frequencies are: daily, weekly, monthly, hourly, half_hourly, quarter_hourly, 10mins, 5mins and once
@@ -86,16 +87,34 @@ class Scheduler @@ -86,16 +87,34 @@ class Scheduler
86 function setFrequency($sFrequency) { 87 function setFrequency($sFrequency) {
87 $this->sFreq = $sFrequency; 88 $this->sFreq = $sFrequency;
88 } 89 }
89 - 90 +
90 /** 91 /**
91 - * Set the time at which the task should first be run or if it is a once off, the time to run it. 92 + * Set the time at which the task should first be run or if it is a once off, the time to run it.
92 * Time should be in datetime format. 93 * Time should be in datetime format.
93 - * By default the time is set to now. 94 + * By default the time is set to now.
94 */ 95 */
95 function setFirstRunTime($iTime) { 96 function setFirstRunTime($iTime) {
96 $this->iStartTime = !empty($iTime) ? $iTime : date('Y-m-d H:i:s'); 97 $this->iStartTime = !empty($iTime) ? $iTime : date('Y-m-d H:i:s');
97 } 98 }
98 - 99 +
  100 + /**
  101 + * Set the task as enabled or disabled. If the task is already set as a system task, then ignore.
  102 + */
  103 + function setEnabled($bStatus = FALSE) {
  104 + if($bStatus && $this->sStatus != 'system'){
  105 + $this->sStatus = 'enabled';
  106 + }
  107 + }
  108 +
  109 + /**
  110 + * Set the task as a system task, this cannot be enabled or disabled.
  111 + */
  112 + function setAsSystemTask($bSystem = FALSE) {
  113 + if($bSystem){
  114 + $this->sStatus = 'system';
  115 + }
  116 + }
  117 +
99 /** 118 /**
100 * Create a script - write it to the filesystem. 119 * Create a script - write it to the filesystem.
101 * Scripts are saved in the KT_DIR."/var/tasks/" directory. 120 * Scripts are saved in the KT_DIR."/var/tasks/" directory.
@@ -105,33 +124,33 @@ class Scheduler @@ -105,33 +124,33 @@ class Scheduler
105 // Path to scripts 124 // Path to scripts
106 $ktPath = '/var/tasks/'; 125 $ktPath = '/var/tasks/';
107 $path = KT_DIR.$ktPath; 126 $path = KT_DIR.$ktPath;
108 - 127 +
109 if(!is_dir($path)){ 128 if(!is_dir($path)){
110 mkdir($path, '0755'); 129 mkdir($path, '0755');
111 } 130 }
112 - 131 +
113 // Create script file 132 // Create script file
114 $sName = str_replace(' ', '_', $this->sName); 133 $sName = str_replace(' ', '_', $this->sName);
115 $sName = str_replace('', "'", $sName); 134 $sName = str_replace('', "'", $sName);
116 $sName = str_replace('', "&", $sName); 135 $sName = str_replace('', "&", $sName);
117 $sFileName = $sName.'_'.mt_rand(1, 999).'.php'; 136 $sFileName = $sName.'_'.mt_rand(1, 999).'.php';
118 - 137 +
119 while(file_exists($path.$sFileName)){ 138 while(file_exists($path.$sFileName)){
120 $sFileName = $sTask.'_'.mt_rand(1, 9999).'.php'; 139 $sFileName = $sTask.'_'.mt_rand(1, 9999).'.php';
121 } 140 }
122 - 141 +
123 $fp = fopen($path.$sFileName, 'wb'); 142 $fp = fopen($path.$sFileName, 'wb');
124 fwrite($fp, $sScript); 143 fwrite($fp, $sScript);
125 fclose($fp); 144 fclose($fp);
126 - 145 +
127 $this->sPath = $ktPath.$sFileName; 146 $this->sPath = $ktPath.$sFileName;
128 } 147 }
129 - 148 +
130 /** 149 /**
131 * Register the task in the scheduler 150 * Register the task in the scheduler
132 */ 151 */
133 function registerTask(){ 152 function registerTask(){
134 - schedulerUtil::registerTask($this->sName, $this->sPath, $this->aParams, $this->sFreq, $this->iStartTime); 153 + schedulerUtil::registerTask($this->sName, $this->sPath, $this->aParams, $this->sFreq, $this->iStartTime, $this->sStatus);
135 } 154 }
136 } 155 }
137 ?> 156 ?>
plugins/ktcore/scheduler/schedulerDashlet.php
@@ -5,32 +5,32 @@ @@ -5,32 +5,32 @@
5 * KnowledgeTree Open Source Edition 5 * KnowledgeTree Open Source Edition
6 * Document Management Made Simple 6 * Document Management Made Simple
7 * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited 7 * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
8 - * 8 + *
9 * This program is free software; you can redistribute it and/or modify it under 9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 3 as published by the 10 * the terms of the GNU General Public License version 3 as published by the
11 * Free Software Foundation. 11 * Free Software Foundation.
12 - * 12 + *
13 * This program is distributed in the hope that it will be useful, but WITHOUT 13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * details. 16 * details.
17 - * 17 + *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 - * 20 + *
21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, 21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. 22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
23 - * 23 + *
24 * The interactive user interfaces in modified source and object code versions 24 * The interactive user interfaces in modified source and object code versions
25 * of this program must display Appropriate Legal Notices, as required under 25 * of this program must display Appropriate Legal Notices, as required under
26 * Section 5 of the GNU General Public License version 3. 26 * Section 5 of the GNU General Public License version 3.
27 - * 27 + *
28 * In accordance with Section 7(b) of the GNU General Public License version 3, 28 * In accordance with Section 7(b) of the GNU General Public License version 3,
29 * these Appropriate Legal Notices must retain the display of the "Powered by 29 * these Appropriate Legal Notices must retain the display of the "Powered by
30 - * KnowledgeTree" logo and retain the original copyright notice. If the display of the 30 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
31 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices 31 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
32 - * must display the words "Powered by KnowledgeTree" and retain the original  
33 - * copyright notice. 32 + * must display the words "Powered by KnowledgeTree" and retain the original
  33 + * copyright notice.
34 * Contributor( s): ______________________________________ 34 * Contributor( s): ______________________________________
35 * 35 *
36 */ 36 */
@@ -42,7 +42,7 @@ class schedulerDashlet extends KTBaseDashlet { @@ -42,7 +42,7 @@ class schedulerDashlet extends KTBaseDashlet {
42 var $oUser; 42 var $oUser;
43 var $sClass = "ktError"; 43 var $sClass = "ktError";
44 var $aTimes = array(); 44 var $aTimes = array();
45 - 45 +
46 function schedulerDashlet() { 46 function schedulerDashlet() {
47 $this->sTitle = _kt('Scheduler'); 47 $this->sTitle = _kt('Scheduler');
48 } 48 }
@@ -55,7 +55,7 @@ class schedulerDashlet extends KTBaseDashlet { @@ -55,7 +55,7 @@ class schedulerDashlet extends KTBaseDashlet {
55 } 55 }
56 return false; 56 return false;
57 } 57 }
58 - 58 +
59 /** 59 /**
60 * Get the last and next run times for the scheduler. 60 * Get the last and next run times for the scheduler.
61 * @return bool true if scheduler is overdue 61 * @return bool true if scheduler is overdue
@@ -63,26 +63,26 @@ class schedulerDashlet extends KTBaseDashlet { @@ -63,26 +63,26 @@ class schedulerDashlet extends KTBaseDashlet {
63 function checkOverDue() { 63 function checkOverDue() {
64 $this->aTimes = schedulerUtil::checkLastRunTime(); 64 $this->aTimes = schedulerUtil::checkLastRunTime();
65 $sNextRunTime = $this->aTimes['nextruntime']; 65 $sNextRunTime = $this->aTimes['nextruntime'];
66 - 66 +
67 $iNow = time(); 67 $iNow = time();
68 $iNext = strtotime($sNextRunTime); 68 $iNext = strtotime($sNextRunTime);
69 - 69 +
70 if($iNow > $iNext){ 70 if($iNow > $iNext){
71 $iDif = $iNow - $iNext; 71 $iDif = $iNow - $iNext;
72 - 72 +
73 // if it hasn't run for a whole day then display dashlet alert. 73 // if it hasn't run for a whole day then display dashlet alert.
74 if($iDif > 60*60*24) { 74 if($iDif > 60*60*24) {
75 return true; 75 return true;
76 } 76 }
77 } 77 }
78 - 78 +
79 return false; 79 return false;
80 } 80 }
81 - 81 +
82 /** 82 /**
83 * Calculate the time difference in days/hours/minutes 83 * Calculate the time difference in days/hours/minutes
84 */ 84 */
85 - function renderTime($iDif, $iUnit, $iRemainder, $sUnit, $sRemainder) { 85 + function renderTime($iDif, $iUnit, $iRemainder, $sUnit, $sRemainder) {
86 // days 86 // days
87 $iTime = round($iDif / $iUnit, 2); 87 $iTime = round($iDif / $iUnit, 2);
88 $aRemainder = explode('.', $iTime); 88 $aRemainder = explode('.', $iTime);
@@ -95,48 +95,48 @@ class schedulerDashlet extends KTBaseDashlet { @@ -95,48 +95,48 @@ class schedulerDashlet extends KTBaseDashlet {
95 $time = floor($iTime).' '.$sUnit.$remainder; 95 $time = floor($iTime).' '.$sUnit.$remainder;
96 return $time; 96 return $time;
97 } 97 }
98 - 98 +
99 /** 99 /**
100 * Get the last and next run times for the scheduler 100 * Get the last and next run times for the scheduler
101 */ 101 */
102 function getRunTimes() { 102 function getRunTimes() {
103 $bDue = FALSE; 103 $bDue = FALSE;
104 - 104 +
105 // Check when the scheduler last ran and when the next task run time should be 105 // Check when the scheduler last ran and when the next task run time should be
106 $aTimes = $this->aTimes; 106 $aTimes = $this->aTimes;
107 - $sLastRunTime = $aTimes['lastruntime']; 107 + $sLastRunTime = $aTimes['lastruntime'];
108 $sNextRunTime = $aTimes['nextruntime']; 108 $sNextRunTime = $aTimes['nextruntime'];
109 - 109 +
110 // Check if scheduler has missed the last run 110 // Check if scheduler has missed the last run
111 $iNow = time(); 111 $iNow = time();
112 $iNext = strtotime($sNextRunTime); 112 $iNext = strtotime($sNextRunTime);
113 - 113 +
114 if($iNow > $iNext){ 114 if($iNow > $iNext){
115 $bDue = TRUE; 115 $bDue = TRUE;
116 $iDif = $iNow - $iNext; 116 $iDif = $iNow - $iNext;
117 }else{ 117 }else{
118 $iDif = $iNext - $iNow; 118 $iDif = $iNext - $iNow;
119 } 119 }
120 - 120 +
121 $time = $iDif.' '._kt('seconds'); $remainder = ''; 121 $time = $iDif.' '._kt('seconds'); $remainder = '';
122 // Get the difference in easy units of time 122 // Get the difference in easy units of time
123 - if($iDif >= 60*60*24*7){ 123 + if($iDif >= 60*60*24*7){
124 // weeks 124 // weeks
125 $time = ' '.schedulerDashlet::renderTime($iDif, 60*60*24*7, 7, _kt('week(s)'), _kt('day(s)')); 125 $time = ' '.schedulerDashlet::renderTime($iDif, 60*60*24*7, 7, _kt('week(s)'), _kt('day(s)'));
126 - }else if($iDif >= 60*60*24){  
127 - // days 126 + }else if($iDif >= 60*60*24){
  127 + // days
128 $time = ' '.schedulerDashlet::renderTime($iDif, 60*60*24, 24, _kt('day(s)'), _kt('hour(s)')); 128 $time = ' '.schedulerDashlet::renderTime($iDif, 60*60*24, 24, _kt('day(s)'), _kt('hour(s)'));
129 - }else if($iDif >= 60*60){ 129 + }else if($iDif >= 60*60){
130 // hours 130 // hours
131 $time = ' '.schedulerDashlet::renderTime($iDif, 60*60, 60, _kt('hour(s)'), _kt('minute(s)')); 131 $time = ' '.schedulerDashlet::renderTime($iDif, 60*60, 60, _kt('hour(s)'), _kt('minute(s)'));
132 - }else if($iDif >= 60){ 132 + }else if($iDif >= 60){
133 // minutes 133 // minutes
134 $time = ' '.schedulerDashlet::renderTime($iDif, 60, 60, _kt('minute(s)'), _kt('second(s)')); 134 $time = ' '.schedulerDashlet::renderTime($iDif, 60, 60, _kt('minute(s)'), _kt('second(s)'));
135 } 135 }
136 - 136 +
137 return array('lasttime' => $sLastRunTime, 'timedif' => $time, 'due' => $bDue); 137 return array('lasttime' => $sLastRunTime, 'timedif' => $time, 'due' => $bDue);
138 } 138 }
139 - 139 +
140 function render() { 140 function render() {
141 $bWin = false; 141 $bWin = false;
142 if(OS_WINDOWS){ 142 if(OS_WINDOWS){
@@ -146,11 +146,11 @@ class schedulerDashlet extends KTBaseDashlet { @@ -146,11 +146,11 @@ class schedulerDashlet extends KTBaseDashlet {
146 $sLastTime = $aTimes['lasttime']; 146 $sLastTime = $aTimes['lasttime'];
147 $sTimeDif = $aTimes['timedif']; 147 $sTimeDif = $aTimes['timedif'];
148 $bDue = $aTimes['due']; 148 $bDue = $aTimes['due'];
149 -  
150 - 149 +
  150 +
151 $oKTConfig =& KTConfig::getSingleton(); 151 $oKTConfig =& KTConfig::getSingleton();
152 $rootUrl = $oKTConfig->get("rootUrl"); 152 $rootUrl = $oKTConfig->get("rootUrl");
153 - 153 +
154 if($oKTConfig->get("ui/morphEnabled") == '1') { 154 if($oKTConfig->get("ui/morphEnabled") == '1') {
155 $sImg = $rootUrl.'/skins/kts_'.$oKTConfig->get("ui/morphTo"); 155 $sImg = $rootUrl.'/skins/kts_'.$oKTConfig->get("ui/morphTo");
156 }else{ 156 }else{
@@ -158,9 +158,9 @@ class schedulerDashlet extends KTBaseDashlet { @@ -158,9 +158,9 @@ class schedulerDashlet extends KTBaseDashlet {
158 } 158 }
159 $sImgPlus = $sImg.'/bullet_toggle_plus.png'; 159 $sImgPlus = $sImg.'/bullet_toggle_plus.png';
160 $sImgMinus = $sImg.'/bullet_toggle_minus.png'; 160 $sImgMinus = $sImg.'/bullet_toggle_minus.png';
161 - 161 +
162 $sPath = KT_DIR.'/bin/scheduler.php'; 162 $sPath = KT_DIR.'/bin/scheduler.php';
163 - $sOnClick = " var cron = document.getElementById('cronguide'); 163 + $sOnClick = " var cron = document.getElementById('cronguide');
164 var icon = document.getElementById('scheduler_icon'); 164 var icon = document.getElementById('scheduler_icon');
165 if(cron.style.visibility == 'hidden'){ 165 if(cron.style.visibility == 'hidden'){
166 cron.style.visibility = 'visible'; cron.style.display = 'block'; 166 cron.style.visibility = 'visible'; cron.style.display = 'block';
@@ -169,9 +169,10 @@ class schedulerDashlet extends KTBaseDashlet { @@ -169,9 +169,10 @@ class schedulerDashlet extends KTBaseDashlet {
169 cron.style.visibility = 'hidden'; cron.style.display = 'none'; 169 cron.style.visibility = 'hidden'; cron.style.display = 'none';
170 icon.src = '{$sImgPlus}'; 170 icon.src = '{$sImgPlus}';
171 }"; 171 }";
172 - 172 +
173 $sAdmin = KTUtil::ktLink('admin.php', 'misc/scheduler'); 173 $sAdmin = KTUtil::ktLink('admin.php', 'misc/scheduler');
174 - 174 + $sAdminLink = "<a href='{$sAdmin}'>"._kt('Administration page').'</a>';
  175 +
175 $oTemplating =& KTTemplating::getSingleton(); 176 $oTemplating =& KTTemplating::getSingleton();
176 $oTemplate = $oTemplating->loadTemplate('ktcore/dashlets/scheduler'); 177 $oTemplate = $oTemplating->loadTemplate('ktcore/dashlets/scheduler');
177 178
@@ -181,7 +182,7 @@ class schedulerDashlet extends KTBaseDashlet { @@ -181,7 +182,7 @@ class schedulerDashlet extends KTBaseDashlet {
181 'isDue' => $bDue, 182 'isDue' => $bDue,
182 'bWin' => $bWin, 183 'bWin' => $bWin,
183 'sPath' => $sPath, 184 'sPath' => $sPath,
184 - 'sAdmin' => $sAdmin, 185 + 'sAdminLink' => $sAdminLink,
185 'sImg' => $sImgPlus, 186 'sImg' => $sImgPlus,
186 'onClick' => $sOnClick, 187 'onClick' => $sOnClick,
187 ); 188 );
plugins/ktcore/scheduler/schedulerEntity.php
@@ -52,6 +52,7 @@ class schedulerEntity extends KTEntity @@ -52,6 +52,7 @@ class schedulerEntity extends KTEntity
52 var $iRun_time; 52 var $iRun_time;
53 var $iPrevious_run_time; 53 var $iPrevious_run_time;
54 var $iRun_duration; 54 var $iRun_duration;
  55 + var $sStatus;
55 56
56 var $_aFieldToSelect = array( 57 var $_aFieldToSelect = array(
57 'iId' => 'id', 58 'iId' => 'id',
@@ -62,7 +63,8 @@ class schedulerEntity extends KTEntity @@ -62,7 +63,8 @@ class schedulerEntity extends KTEntity
62 'iFrequency' => 'frequency', 63 'iFrequency' => 'frequency',
63 'iRun_time' => 'run_time', 64 'iRun_time' => 'run_time',
64 'iPrevious_run_time' => 'previous_run_time', 65 'iPrevious_run_time' => 'previous_run_time',
65 - 'iRun_duration' => 'run_duration' 66 + 'iRun_duration' => 'run_duration',
  67 + 'sStatus' => 'status'
66 ); 68 );
67 69
68 function _table () { 70 function _table () {
@@ -78,6 +80,7 @@ class schedulerEntity extends KTEntity @@ -78,6 +80,7 @@ class schedulerEntity extends KTEntity
78 function getParams() { return $this->sScript_params; } 80 function getParams() { return $this->sScript_params; }
79 function getIsComplete() { return $this->bIs_complete; } 81 function getIsComplete() { return $this->bIs_complete; }
80 function getFrequency() { return $this->iFrequency; } 82 function getFrequency() { return $this->iFrequency; }
  83 + function getStatus() { return $this->sStatus; }
81 84
82 function getFrequencyByLang() { 85 function getFrequencyByLang() {
83 $aFrequencies = array( 86 $aFrequencies = array(
@@ -117,6 +120,7 @@ class schedulerEntity extends KTEntity @@ -117,6 +120,7 @@ class schedulerEntity extends KTEntity
117 function setRunTime($sValue) { return $this->iRun_time = date('Y-m-d H:i:s', $sValue); } 120 function setRunTime($sValue) { return $this->iRun_time = date('Y-m-d H:i:s', $sValue); }
118 function setPrevious($sValue) { return $this->iPrevious_run_time = date('Y-m-d H:i:s', $sValue); } 121 function setPrevious($sValue) { return $this->iPrevious_run_time = date('Y-m-d H:i:s', $sValue); }
119 function setRunDuration($sValue) { return $this->iRun_duration = $sValue; } 122 function setRunDuration($sValue) { return $this->iRun_duration = $sValue; }
  123 + function setStatus($sValue) { return $this->sStatus = $sValue; }
120 124
121 function get($iId) { 125 function get($iId) {
122 return KTEntityUtil::get('schedulerEntity', $iId); 126 return KTEntityUtil::get('schedulerEntity', $iId);
@@ -124,10 +128,11 @@ class schedulerEntity extends KTEntity @@ -124,10 +128,11 @@ class schedulerEntity extends KTEntity
124 128
125 function getTasksToRun() { 129 function getTasksToRun() {
126 $aOptions = array('multi' => true); 130 $aOptions = array('multi' => true);
127 - $aFields = array('is_complete', 'run_time'); 131 + $aFields = array('is_complete', 'run_time', 'status');
128 $aValues = array(); 132 $aValues = array();
129 $aValues[] = array('type' => 'equals', 'value' => '0'); 133 $aValues[] = array('type' => 'equals', 'value' => '0');
130 $aValues[] = array('type' => 'before', 'value' => time()); 134 $aValues[] = array('type' => 'before', 'value' => time());
  135 + $aValues[] = array('type' => 'nequals', 'value' => 'disabled');
131 136
132 return KTEntityUtil::getBy('schedulerEntity', $aFields, $aValues, $aOptions); 137 return KTEntityUtil::getBy('schedulerEntity', $aFields, $aValues, $aOptions);
133 } 138 }
@@ -139,9 +144,10 @@ class schedulerEntity extends KTEntity @@ -139,9 +144,10 @@ class schedulerEntity extends KTEntity
139 144
140 function getLastRunTime($date) { 145 function getLastRunTime($date) {
141 $aOptions = array('multi' => true, 'orderby' => 'previous_run_time DESC'); 146 $aOptions = array('multi' => true, 'orderby' => 'previous_run_time DESC');
142 - $aFields = array('previous_run_time'); 147 + $aFields = array('previous_run_time', 'status');
143 $aValues = array(); 148 $aValues = array();
144 $aValues[] = array('type' => 'before', 'value' => $date); 149 $aValues[] = array('type' => 'before', 'value' => $date);
  150 + $aValues[] = array('type' => 'nequals', 'value' => 'disabled');
145 151
146 return KTEntityUtil::getBy('schedulerEntity', $aFields, $aValues, $aOptions); 152 return KTEntityUtil::getBy('schedulerEntity', $aFields, $aValues, $aOptions);
147 } 153 }
@@ -175,11 +181,40 @@ class schedulerEntity extends KTEntity @@ -175,11 +181,40 @@ class schedulerEntity extends KTEntity
175 } 181 }
176 182
177 /** 183 /**
  184 + * Display the task name. If the task is disabled then grey it out.
  185 + *
  186 + */
  187 + function getTaskDiv() {
  188 + $sId = $this->getId();
  189 + $sStatus = $this->getStatus();
  190 +
  191 + $sDiv = "<span id='font{$sId}' ";
  192 + $sDiv .= ($sStatus != 'disabled') ? 'class="">' : 'class="descriptiveText">';
  193 + $sDiv .= $this->getTask().'</span>';
  194 + return $sDiv;
  195 + }
  196 +
  197 + function getFreqDiv() {
  198 + $sId = $this->getId();
  199 + $sStatus = $this->getStatus();
  200 + $sFreqs = $this->getFrequencyByLang();
  201 +
  202 + $sLink = "<a href='#' id='freqDrop{$sId}' onclick='javascript: showFrequencyDiv(\"{$sId}\");'";
  203 + $sLink .= ($sStatus == 'disabled') ? 'style="visibility: hidden;" >' : '>';
  204 + $sLink .= "<div id='div{$sId}'>$sFreqs</div></a>";
  205 + return $sLink;
  206 + }
  207 +
  208 + /**
178 * Get a link to alter the frequency of a task 209 * Get a link to alter the frequency of a task
179 */ 210 */
180 function getAlterFreqLink() { 211 function getAlterFreqLink() {
181 $sId = $this->getId(); 212 $sId = $this->getId();
182 - $sLink = "<a href='#' onclick='javascript: showFrequencyDiv({$sId});'>"._kt('Alter frequency')."</a>"; 213 + $sStatus = $this->getStatus();
  214 +
  215 + $sLink = "<a href='#' id='freqLink{$this->getId()}' onclick='javascript: showFrequencyDiv({$sId});'";
  216 + $sLink .= ($sStatus == 'disabled') ? 'style="visibility: hidden;" >' : '>';
  217 + $sLink .= _kt('Alter frequency')."</a>";
183 return $sLink; 218 return $sLink;
184 } 219 }
185 220
@@ -188,9 +223,33 @@ class schedulerEntity extends KTEntity @@ -188,9 +223,33 @@ class schedulerEntity extends KTEntity
188 */ 223 */
189 function getRunNowLink() { 224 function getRunNowLink() {
190 $sId = $this->getId(); 225 $sId = $this->getId();
  226 + $sStatus = $this->getStatus();
191 $sUrl = KTUtil::ktLink('admin.php', 'misc/scheduler', 'action=updateRunTime'); 227 $sUrl = KTUtil::ktLink('admin.php', 'misc/scheduler', 'action=updateRunTime');
192 - $sLink = "<a href='#' onclick='javascript: runOnNext(\"{$sId}\", \"{$sUrl}\");'>"._kt('Run on next iteration')."</a>"; 228 +
  229 + $sLink = "<a href='#' id='runnowLink{$this->getId()}' onclick='javascript: runOnNext(\"{$sId}\", \"{$sUrl}\");'";
  230 + $sLink .= ($sStatus == 'disabled') ? 'style="visibility: hidden;" >' : '>';
  231 + $sLink .= _kt('Run on next iteration')."</a>";
  232 + return $sLink;
  233 + }
  234 +
  235 + /**
  236 + * Run the task on the next iteration
  237 + */
  238 + function getStatusLink() {
  239 + $sId = $this->getId();
  240 + $sStatus = $this->getStatus();
  241 + if($sStatus == 'system'){
  242 + return '';
  243 + }
  244 +
  245 + $sDisableText = _kt('Disable task');
  246 + $sEnableText = _kt('Enable task');
  247 +
  248 + $sLinkText = ($sStatus == 'enabled') ? $sDisableText : $sEnableText;
  249 + $sUrl = KTUtil::ktLink('admin.php', 'misc/scheduler', 'action=updateStatus');
  250 + $sLink = "<a id='statusLink{$this->getId()}' href='#'
  251 + onclick='javascript: toggleStatus(\"{$sId}\", \"{$sUrl}\", \"{$sDisableText}\", \"{$sEnableText}\");'>{$sLinkText}</a>";
193 return $sLink; 252 return $sLink;
194 } 253 }
195 } 254 }
196 -?> 255 -?>
  256 +?>
197 \ No newline at end of file 257 \ No newline at end of file
plugins/ktcore/scheduler/schedulerUtil.php
@@ -77,7 +77,7 @@ class schedulerUtil extends KTUtil @@ -77,7 +77,7 @@ class schedulerUtil extends KTUtil
77 /** 77 /**
78 * Method to register a task in the schedule 78 * Method to register a task in the schedule
79 */ 79 */
80 - function registerTask($sTask, $sUrl, $aParams, $sFreq, $iStartTime = NULL) { 80 + function registerTask($sTask, $sUrl, $aParams, $sFreq, $iStartTime = NULL, $sStatus = 'disabled') {
81 // Run task on next iteration if no start time given 81 // Run task on next iteration if no start time given
82 $iStartTime = (!empty($iStartTime)) ? strtotime($iStartTime) : time(); 82 $iStartTime = (!empty($iStartTime)) ? strtotime($iStartTime) : time();
83 83
@@ -101,6 +101,7 @@ class schedulerUtil extends KTUtil @@ -101,6 +101,7 @@ class schedulerUtil extends KTUtil
101 $aTask['run_time'] = $dNextTime; 101 $aTask['run_time'] = $dNextTime;
102 $aTask['previous_run_time'] = $dStartTime; 102 $aTask['previous_run_time'] = $dStartTime;
103 $aTask['run_duration'] = '0'; 103 $aTask['run_duration'] = '0';
  104 + $sTask['status'] = $sStatus;
104 105
105 $oEntity = schedulerEntity::createFromArray($aTask); 106 $oEntity = schedulerEntity::createFromArray($aTask);
106 if (PEAR::isError($oEntity)){ 107 if (PEAR::isError($oEntity)){
@@ -127,6 +128,7 @@ class schedulerUtil extends KTUtil @@ -127,6 +128,7 @@ class schedulerUtil extends KTUtil
127 $aTask['is_complete'] = '0'; 128 $aTask['is_complete'] = '0';
128 $aTask['run_time'] = date('Y-m-d H:i:s'); 129 $aTask['run_time'] = date('Y-m-d H:i:s');
129 $aTask['run_duration'] = '0'; 130 $aTask['run_duration'] = '0';
  131 + $aTask['status'] = 'enabled';
130 132
131 $oEntity = schedulerEntity::createFromArray($aTask); 133 $oEntity = schedulerEntity::createFromArray($aTask);
132 if (PEAR::isError($oEntity)){ 134 if (PEAR::isError($oEntity)){
@@ -232,6 +234,29 @@ class schedulerUtil extends KTUtil @@ -232,6 +234,29 @@ class schedulerUtil extends KTUtil
232 } 234 }
233 235
234 /** 236 /**
  237 + * Toggle whether a task is enabled or disabled. If its a system task, then ignore.
  238 + */
  239 + function toggleStatus($id) {
  240 + $oScheduler = schedulerEntity::get($id);
  241 +
  242 + if (PEAR::isError($oScheduler)){
  243 + return _kt('Object can\'t be created');
  244 + }
  245 +
  246 + $sStatus = $oScheduler->getStatus();
  247 +
  248 + if($sStatus == 'system'){
  249 + // ignore
  250 + return $sStatus;
  251 + }
  252 +
  253 + $sNewStatus = ($sStatus == 'enabled') ? 'disabled' : 'enabled';
  254 + $oScheduler->setStatus($sNewStatus);
  255 + $oScheduler->update();
  256 + return $sNewStatus;
  257 + }
  258 +
  259 + /**
235 * Check the last run time of the scheduler 260 * Check the last run time of the scheduler
236 */ 261 */
237 function checkLastRunTime() { 262 function checkLastRunTime() {
plugins/ktcore/scheduler/taskScheduler.php
@@ -120,5 +120,13 @@ class manageSchedulerDispatcher extends KTAdminDispatcher @@ -120,5 +120,13 @@ class manageSchedulerDispatcher extends KTAdminDispatcher
120 schedulerUtil::updateRunTime($id, $iNextTime); 120 schedulerUtil::updateRunTime($id, $iNextTime);
121 return $iNextTime; 121 return $iNextTime;
122 } 122 }
  123 +
  124 + /**
  125 + * Toggle the enable/disable on the task
  126 + */
  127 + function do_updateStatus() {
  128 + $fId = schedulerUtil::arrayGet($_REQUEST, 'fId');
  129 + schedulerUtil::toggleStatus($fId);
  130 + }
123 } 131 }
124 ?> 132 ?>
resources/js/scheduler.js
@@ -28,6 +28,38 @@ var runOnNext = function(fId, sUrl) { @@ -28,6 +28,38 @@ var runOnNext = function(fId, sUrl) {
28 var transaction = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, "fId="+fId); 28 var transaction = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, "fId="+fId);
29 } 29 }
30 30
  31 +//<!-- Enable / disable the task -->
  32 +var toggleStatus = function(fId, sUrl, sDisableText, sEnableText) {
  33 +
  34 + var statusLink = document.getElementById('statusLink'+fId);
  35 + var freqLink = document.getElementById('freqLink'+fId);
  36 + var runnowLink = document.getElementById('runnowLink'+fId);
  37 + var freqDrop = document.getElementById('freqDrop'+fId);
  38 + var fontClass = document.getElementById('font'+fId);
  39 + var freqDiv = document.getElementById('div'+fId);
  40 +
  41 + var callback = {
  42 + success: function(o) {
  43 + if(statusLink.innerHTML == sDisableText){
  44 + statusLink.innerHTML = sEnableText;
  45 + freqLink.style.visibility = "hidden";
  46 + runnowLink.style.visibility = "hidden";
  47 + freqDrop.style.visibility = "hidden";
  48 + fontClass.className = 'descriptiveText';
  49 + freqDiv.style.display = "none";
  50 + }else{
  51 + statusLink.innerHTML = sDisableText;
  52 + freqLink.style.visibility = "visible";
  53 + runnowLink.style.visibility = "visible";
  54 + freqDrop.style.visibility = "visible";
  55 + freqDiv.style.display = "block";
  56 + fontClass.className = '';
  57 + }
  58 + }
  59 + }
  60 + var transaction = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, "fId="+fId);
  61 +}
  62 +
31 var showFrequencyDiv = function(fId) { 63 var showFrequencyDiv = function(fId) {
32 var formDiv = document.getElementById('formDiv'); 64 var formDiv = document.getElementById('formDiv');
33 var fInput = document.getElementById('fId'); 65 var fInput = document.getElementById('fId');
templates/ktcore/dashlets/scheduler.smarty
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 {else} 5 {else}
6 <span class="descriptiveText">{i18n}No tasks have been run yet.{/i18n}</span> 6 <span class="descriptiveText">{i18n}No tasks have been run yet.{/i18n}</span>
7 {/if} 7 {/if}
8 -&nbsp;<span><a href="{$sAdmin}">Administration page</a></span> 8 +&nbsp;<span class="descriptiveText">{i18n arg_link=$sAdminLink}This can be configured via the #link#.{/i18n}</span>
9 9
10 <p> 10 <p>
11 {if !$lasttime} 11 {if !$lasttime}
templates/ktcore/scheduler.smarty
@@ -28,15 +28,13 @@ @@ -28,15 +28,13 @@
28 28
29 <tr class="{cycle name=rows values=",odd"}"> 29 <tr class="{cycle name=rows values=",odd"}">
30 <td width='2%'> 30 <td width='2%'>
31 - {$i++} 31 + {$i++}
32 </td> 32 </td>
33 <td> 33 <td>
34 - {$task->getTask()} 34 + {$task->getTaskDiv()}
35 </td> 35 </td>
36 - <td id="tblCol"><a href="#" onclick="javascript: showFrequencyDiv('{$task->getId()}');">  
37 - <div id="div{$task->getId()}">  
38 - {$task->getFrequencyByLang()}  
39 - </div></a> 36 + <td id="tblCol">
  37 + {$task->getFreqDiv()}
40 </td> 38 </td>
41 <td> 39 <td>
42 <div id="runDiv{$task->getId()}"> 40 <div id="runDiv{$task->getId()}">
@@ -49,11 +47,11 @@ @@ -49,11 +47,11 @@
49 </div> 47 </div>
50 {$task->getPrevious(TRUE)} 48 {$task->getPrevious(TRUE)}
51 </td> 49 </td>
52 - <td> 50 + <td width="10%">
53 {$task->getRunDuration()} 51 {$task->getRunDuration()}
54 </td> 52 </td>
55 <td> 53 <td>
56 - {$task->getAlterFreqLink()}&nbsp;&nbsp;{$task->getRunNowLink()} 54 + {$task->getAlterFreqLink()}&nbsp;&nbsp;{$task->getRunNowLink()}&nbsp;&nbsp;{$task->getStatusLink()}
57 </td> 55 </td>
58 </tr> 56 </tr>
59 57
@@ -70,7 +68,7 @@ @@ -70,7 +68,7 @@
70 68
71 <div id="formDiv" style="display: none; visibility: hidden;"> 69 <div id="formDiv" style="display: none; visibility: hidden;">
72 <form name="changefreq" id="changefreq" method="post" action="{$sUrl}"> 70 <form name="changefreq" id="changefreq" method="post" action="{$sUrl}">
73 - 71 +
74 <select name="frequency" id="frequency"> 72 <select name="frequency" id="frequency">
75 {html_options options=$aFrequencies} 73 {html_options options=$aFrequencies}
76 </select> 74 </select>