diff --git a/bin/scheduler.php b/bin/scheduler.php
index 08c4d30..d32ac35 100644
--- a/bin/scheduler.php
+++ b/bin/scheduler.php
@@ -5,36 +5,36 @@
* KnowledgeTree Open Source Edition
* Document Management Made Simple
* Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
- *
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation.
- *
+ *
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
- *
+ *
* You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
* Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
- *
+ *
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
- *
+ *
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
- * KnowledgeTree" logo and retain the original copyright notice. If the display of the
+ * KnowledgeTree" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
- * must display the words "Powered by KnowledgeTree" and retain the original
- * copyright notice.
+ * must display the words "Powered by KnowledgeTree" and retain the original
+ * copyright notice.
* Contributor( s): ______________________________________
*
*/
-
+
require_once('../config/dmsDefaults.php');
require_once(KT_LIB_DIR . '/database/dbutil.inc');
@@ -73,6 +73,12 @@ function calculateRunTime($sFreq, $iTime) {
case '5mins':
$iDiff = (60*5);
break;
+ case '1min':
+ $iDiff = 60;
+ break;
+ case '30secs':
+ $iDiff = 30;
+ break;
case 'once':
$iDiff = 0;
break;
@@ -89,11 +95,11 @@ function updateTask($sTable, $aFieldValues, $iId) {
// Get the list of tasks due to be run from the database
function getTaskList($sTable) {
$now = date('Y-m-d H:i:s'); //time();
- $query = "SELECT * FROM {$sTable}
+ $query = "SELECT * FROM {$sTable}
WHERE is_complete = 0 AND run_time < '{$now}'";
-
+
$result = DBUtil::getResultArray($query);
-
+
if (PEAR::isError($result)){
exit();
}
@@ -108,21 +114,23 @@ $sTable = 'scheduler_tasks';
// Get task list
$aList = getTaskList($sTable);
+global $default;
+
// Loop through tasks and run
if(!empty($aList)){
foreach($aList as $item){
$aUpdate = array();
$iEnd = 0; $iStart = 0; $iDuration = 0;
- $sFreq = ''; $sParameters = '';
+ $sFreq = ''; $sParameters = '';
$retval = TRUE;
-
+
// Set up start variables
$sTask = $item['task'];
$sTaskUrl = $item['script_url'];
$iDuration = $item['run_duration'];
$sFreq = $item['frequency'];
$sParameters = $item['script_params'];
-
+
// Check if script is windows or *nix compatible
$extArr = explode('.', $sTaskUrl);
$ext = array_pop($extArr);
@@ -162,19 +170,39 @@ if(!empty($aList)){
break;
}
}
-
+
$iTime = time();
$iStart = explode(' ', microtime());
-
+
// Run the script
- $file = KT_DIR . escapeshellcmd($sTaskUrl);
- system("{$file} {$sParameters} >> /dev/null", $retval);
-
+ $file =escapeshellcmd($sTaskUrl);
+
+ $cmd = "\"$file\" {$sParameters}";
+
+ if (OS_WINDOWS)
+ {
+ $cmd = str_replace( '/','\\',$cmd);
+ $res = `"$cmd" 2>&1`;
+ }
+ else
+ {
+ $res = shell_exec($cmd." 2>&1");
+ }
+
+ if (!empty($res))
+ {
+ $default->log->info("Scheduler - Task: $sTask");
+ $default->log->info("Scheduler - Command: $cmd");
+ $default->log->info("Scheduler - Output: $res");
+ $default->log->info("Scheduler - Background tasks should not produce output. Please review why this is producing output.");
+ }
+
+
// On completion - reset run time
$iEnd = explode(' ', microtime());
$iDuration = ($iEnd[1] + $iEnd[0]) - ($iStart[1] + $iStart[0]);
$iDuration = round($iDuration, 3);
-
+
if(($sFreq == 'once' || empty($sFreq)) && $retval !== FALSE){
// Set is_complete to true
$aUpdate['is_complete'] = '1';
@@ -184,9 +212,9 @@ if(!empty($aList)){
}
$aUpdate['previous_run_time'] = date('Y-m-d H:i:s', $iTime);
$aUpdate['run_duration'] = $iDuration;
-
+
updateTask($sTable, $aUpdate, $item['id']);
-
+
// clear parameters
if(!empty($aParams)){
foreach($aParams as $param){
diff --git a/bin/win32/schedulerService.php b/bin/win32/schedulerService.php
index 1d75762..c3b6786 100644
--- a/bin/win32/schedulerService.php
+++ b/bin/win32/schedulerService.php
@@ -6,6 +6,20 @@ $myservicename = 'ktscheduler';
if (!win32_start_service_ctrl_dispatcher($myservicename)) die('Could not connect to service :'.$myservicename);
win32_set_service_status(WIN32_SERVICE_RUNNING);
+require_once('../../config/dmsDefaults.php');
+
+global $default;
+
+$config = KTConfig::getSingleton();
+$schedulerInterval = $config->get('KnowledgeTree/schedulerInterval',10); // interval in seconds
+$phpPath = $config->get('externalBinary/php','php');
+
+if (!is_file($phpPath))
+{
+ $default->log->error("Scheduler: php not found: $phpPath");
+ exit;
+}
+
// Main Scheduler Service Loop
while (1) {
@@ -23,15 +37,20 @@ while (1) {
// Setup php binary path
$phpPath = realpath('../../php/php.exe');
- if (!is_file($phpPath))
- {
- die('Cannot find php.exe');
- }
-
+
+
// Run the scheduler script
- system("$phpPath scheduler.php");
- sleep(10); // Run every 10 seconds
+ $cmd = "\"$phpPath\" scheduler.php";
+
+ $cmd = str_replace( '/','\\',$cmd);
+ $res = `"$cmd" 2>&1`;
+ if (!empty($res))
+ {
+ $default->log->error('Scheduler: unexpected output - ' .$res);
+ }
+
+ sleep($schedulerInterval);
}
win32_set_service_status(WIN32_SERVICE_STOPPED);
diff --git a/lib/config/config.inc.php b/lib/config/config.inc.php
index d63f2cb..a5d7894 100644
--- a/lib/config/config.inc.php
+++ b/lib/config/config.inc.php
@@ -5,32 +5,32 @@
* KnowledgeTree Open Source Edition
* Document Management Made Simple
* Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
- *
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation.
- *
+ *
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
- *
+ *
* You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
* Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
- *
+ *
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
- *
+ *
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
- * KnowledgeTree" logo and retain the original copyright notice. If the display of the
+ * KnowledgeTree" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
- * must display the words "Powered by KnowledgeTree" and retain the original
- * copyright notice.
+ * must display the words "Powered by KnowledgeTree" and retain the original
+ * copyright notice.
* Contributor( s): ______________________________________
*
*/
@@ -150,6 +150,25 @@ class KTConfig {
return $oDefault;
}
+ /**
+ * Return the location of the config.ini
+ *
+ * @return string
+ */
+ static function getConfigFilename()
+ {
+ $configPath = file_get_contents(KT_DIR . '/config/config-path');
+
+ if (is_file($configPath))
+ {
+ return $configPath;
+ }
+ else
+ {
+ return KT_DIR . '/' . $configPath;
+ }
+ }
+
static function &getSingleton() {
static $singleton = null;
diff --git a/lib/upgrades/Ini.inc.php b/lib/upgrades/Ini.inc.php
index e5be4a4..e900ba8 100644
--- a/lib/upgrades/Ini.inc.php
+++ b/lib/upgrades/Ini.inc.php
@@ -5,32 +5,32 @@
* KnowledgeTree Open Source Edition
* Document Management Made Simple
* Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
- *
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation.
- *
+ *
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
- *
+ *
* You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
* Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
- *
+ *
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
- *
+ *
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
- * KnowledgeTree" logo and retain the original copyright notice. If the display of the
+ * KnowledgeTree" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
- * must display the words "Powered by KnowledgeTree" and retain the original
- * copyright notice.
+ * must display the words "Powered by KnowledgeTree" and retain the original
+ * copyright notice.
* Contributor( s): ______________________________________
*
*/
@@ -48,7 +48,27 @@ class Ini {
function Ini($iniFile = '../../config.ini') {
$this->iniFile = $iniFile;
- $this->read($iniFile);
+ $this->backupIni($iniFile);
+ $this->read($iniFile);
+ }
+
+ /**
+ * Create a backup with the date as an extension in the same location as the original config.ini
+ *
+ * @param string $iniFile
+ * @return boolean
+ */
+ function backupIni($iniFile)
+ {
+ $content = file_get_contents($iniFile);
+ if ($content === false)
+ {
+ return false;
+ }
+ $date = date('YmdHis');
+
+ $backupFile = $iniFile . '.' .$date;
+ return file_put_contents($backupFile, $content) !== false;
}
function read($iniFile) {
@@ -85,7 +105,7 @@ class Ini {
$key = trim(substr($iniLine, 0, $equalsPos));
$value = trim(substr($iniLine, $equalsPos+1));
if (substr($value, 1, 1) == '"' && substr( $value, -1, 1) == '"') {
- $value = substr($value, 1, -1);
+ $value = substr($value, 1, -1);
}
$this->cleanArray[$section][$key] = stripcslashes($value);
} else {
@@ -104,21 +124,21 @@ class Ini {
$fileHandle = fopen($iniFile, 'wb');
foreach ($this->cleanArray as $section => $items) {
if (substr($section, 0, strlen('_blankline_')) === '_blankline_' ) {
- fwrite ($fileHandle, "\r\n");
+ fwrite ($fileHandle, "\r\n");
continue;
}
if (substr($section, 0, strlen('_comment_')) === '_comment_' ) {
- fwrite ($fileHandle, "$items\r\n");
+ fwrite ($fileHandle, "$items\r\n");
continue;
}
fwrite ($fileHandle, "[".$section."]\r\n");
foreach ($items as $key => $value) {
if (substr($key, 0, strlen('_blankline_')) === '_blankline_' ) {
- fwrite ($fileHandle, "\r\n");
+ fwrite ($fileHandle, "\r\n");
continue;
}
if (substr($key, 0, strlen('_comment_')) === '_comment_' ) {
- fwrite ($fileHandle, "$value\r\n");
+ fwrite ($fileHandle, "$value\r\n");
continue;
}
@@ -145,7 +165,7 @@ class Ini {
}
return false;
}
-
+
function addItem($addSection, $addItem, $value, $itemComment = '', $sectionComment = '') {
if($this->itemExists($addSection, $addItem)) return false;
diff --git a/lib/upgrades/UpgradeFunctions.inc.php b/lib/upgrades/UpgradeFunctions.inc.php
index 12ebac6..724cbce 100644
--- a/lib/upgrades/UpgradeFunctions.inc.php
+++ b/lib/upgrades/UpgradeFunctions.inc.php
@@ -5,32 +5,32 @@
* KnowledgeTree Open Source Edition
* Document Management Made Simple
* Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
- *
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation.
- *
+ *
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
- *
+ *
* You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
* Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
- *
+ *
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
- *
+ *
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
- * KnowledgeTree" logo and retain the original copyright notice. If the display of the
+ * KnowledgeTree" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
- * must display the words "Powered by KnowledgeTree" and retain the original
- * copyright notice.
+ * must display the words "Powered by KnowledgeTree" and retain the original
+ * copyright notice.
* Contributor( s): ______________________________________
*
*/
@@ -916,9 +916,12 @@ class UpgradeFunctions {
// {{{ updateConfigFile35
function updateConfigFile35()
{
- if(file_exists('../../config.ini')) {
+ $configPath = KTConfig::getConfigFilename();
+ $configPath = str_replace(array("\n","\r"), array('',''), $configPath);
+
+ if(file_exists($configPath)) {
- $ini = new Ini();
+ $ini = new Ini($configPath);
// Webservices Section
$ini->addItem('webservice', 'uploadDirectory', '${varDirectory}/uploads');
@@ -1008,7 +1011,6 @@ class UpgradeFunctions {
$ini->addItem('DiskUsage', 'urgentThreshold', '5', "When free space in a mount point is less than this percentage,\r\n; the disk usage dashlet will highlight the mount in RED");
$ini->write();
-
}
}
// }}}
@@ -1031,7 +1033,7 @@ class UpgradeFunctions {
$oScheduler = new Scheduler('Indexing');
$oScheduler->setScriptPath(KT_DIR . '/bin/indexingTask.' . $ext);
- $oScheduler->setFrequency('5mins');
+ $oScheduler->setFrequency('1min');
$oScheduler->setFirstRunTime(date('Y-m-d H:i',mktime($hour, $min, 0, $mon, $day, $year)));
$oScheduler->registerTask();
diff --git a/sql/mysql/install/data.sql b/sql/mysql/install/data.sql
index 5465f77..c70e5a6 100644
--- a/sql/mysql/install/data.sql
+++ b/sql/mysql/install/data.sql
@@ -794,6 +794,7 @@ UNLOCK TABLES;
LOCK TABLES `scheduler_tasks` WRITE;
/*!40000 ALTER TABLE `scheduler_tasks` DISABLE KEYS */;
+INSERT INTO `scheduler_tasks` VALUES (1,'Indexing','/knowledgetree/ktdms.trunk/bin/indexingTask.sh','',0,'1min',NULL,NULL,0),(2,'Index Migration','/knowledgetree/ktdms.trunk/bin/indexMigrationTask.sh','',0,'5mins',NULL,NULL,0),(3,'Index Optimisation','/knowledgetree/ktdms.trunk/bin/optimizeIndexes.sh','',0,'weekly',NULL,NULL,0);
/*!40000 ALTER TABLE `scheduler_tasks` ENABLE KEYS */;
UNLOCK TABLES;
@@ -1691,6 +1692,7 @@ UNLOCK TABLES;
LOCK TABLES `zseq_scheduler_tasks` WRITE;
/*!40000 ALTER TABLE `zseq_scheduler_tasks` DISABLE KEYS */;
+INSERT INTO `zseq_scheduler_tasks` VALUES (3);
/*!40000 ALTER TABLE `zseq_scheduler_tasks` ENABLE KEYS */;
UNLOCK TABLES;