Commit 096bf8dfb24b53787d674382bb062bf9976612f1
1 parent
65411235
Merged in from DEV trunk...
KTS-673 "The search algorithm needs some work" Updated. Committed By: Conrad Vermeulen Reviewed By: Kevin Fourie KTS-1554 "Implement a Scheduler" Updated. is_background was removed from dtabase. Committed by: Conrad Vermeulen Reviewed by: Kevin Fourie KTS-673 "The search algorithm needs some work" Updated. Updated reference from Lucene to Document Indexer Committed By: Conrad Vermeulen Reviewed By: Kevin Fourie KTS-1753 " Implement Disk Usage Plugin" Updated. Added cross platform calling of df Committed By: Conrad Vermeulen Reviewed By: Kevin Fourie KTS-1753 " Implement Disk Usage Plugin" Updated. Removed term disk from Disk Mount. Committed By: Conrad Vermeulen Reviewed By: Kevin Fourie KTS-1753 " Implement Disk Usage Plugin" Updated. Removed empty line from DF Committed By: Conrad Vermeulen Reviewed By: Kevin Fourie git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@7520 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
5 changed files
with
83 additions
and
75 deletions
plugins/housekeeper/DiskUsageDashlet.inc.php
| ... | ... | @@ -6,32 +6,32 @@ |
| 6 | 6 | * KnowledgeTree Open Source Edition |
| 7 | 7 | * Document Management Made Simple |
| 8 | 8 | * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited |
| 9 | - * | |
| 9 | + * | |
| 10 | 10 | * This program is free software; you can redistribute it and/or modify it under |
| 11 | 11 | * the terms of the GNU General Public License version 3 as published by the |
| 12 | 12 | * Free Software Foundation. |
| 13 | - * | |
| 13 | + * | |
| 14 | 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 16 | 16 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 17 | 17 | * details. |
| 18 | - * | |
| 18 | + * | |
| 19 | 19 | * You should have received a copy of the GNU General Public License |
| 20 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | - * | |
| 21 | + * | |
| 22 | 22 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, |
| 23 | 23 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. |
| 24 | - * | |
| 24 | + * | |
| 25 | 25 | * The interactive user interfaces in modified source and object code versions |
| 26 | 26 | * of this program must display Appropriate Legal Notices, as required under |
| 27 | 27 | * Section 5 of the GNU General Public License version 3. |
| 28 | - * | |
| 28 | + * | |
| 29 | 29 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 30 | 30 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 31 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 31 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 32 | 32 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 33 | - * must display the words "Powered by KnowledgeTree" and retain the original | |
| 34 | - * copyright notice. | |
| 33 | + * must display the words "Powered by KnowledgeTree" and retain the original | |
| 34 | + * copyright notice. | |
| 35 | 35 | * Contributor( s): ______________________________________ |
| 36 | 36 | */ |
| 37 | 37 | |
| ... | ... | @@ -83,14 +83,26 @@ class DiskUsageDashlet extends KTBaseDashlet |
| 83 | 83 | // we will only check if the result is not cached, or after 5 minutes |
| 84 | 84 | if ($check) |
| 85 | 85 | { |
| 86 | - $result = ktutil::pexec($this->dfCmd); | |
| 86 | + $cmd = $this->dfCmd; | |
| 87 | + | |
| 88 | + if (OS_WINDOWS) | |
| 89 | + { | |
| 90 | + $cmd = str_replace( '/','\\',$cmd); | |
| 91 | + $result = `"$cmd" 2>&1`; | |
| 92 | + } | |
| 93 | + else | |
| 94 | + { | |
| 95 | + $result = shell_exec($cmd." 2>&1"); | |
| 96 | + } | |
| 97 | + | |
| 98 | + $result = explode("\n", $result); | |
| 87 | 99 | |
| 88 | - $result = $result['out']; | |
| 89 | - unset($result[0]); | |
| 100 | + unset($result[0]); // gets rid of headings | |
| 90 | 101 | |
| 91 | 102 | $usage=array(); |
| 92 | 103 | foreach($result as $line) |
| 93 | 104 | { |
| 105 | + if (empty($line)) continue; | |
| 94 | 106 | preg_match('/(.*)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\%\s+(.*)/', $line, $matches); |
| 95 | 107 | list($line, $filesystem, $size, $used, $avail, $usedp, $mount) = $matches; |
| 96 | 108 | ... | ... |
plugins/housekeeper/HouseKeeperPlugin.php
| ... | ... | @@ -77,8 +77,6 @@ class HouseKeeperPlugin extends KTPlugin |
| 77 | 77 | 'canClean'=>true |
| 78 | 78 | )); |
| 79 | 79 | |
| 80 | - if (!OS_WINDOWS) | |
| 81 | - { | |
| 82 | 80 | $this->folders[] = |
| 83 | 81 | array( |
| 84 | 82 | 'name'=>_kt('System Temporary Folder'), |
| ... | ... | @@ -86,7 +84,6 @@ class HouseKeeperPlugin extends KTPlugin |
| 86 | 84 | 'pattern'=>'(sess_.+)?(.+\.log$)?', |
| 87 | 85 | 'canClean'=>true |
| 88 | 86 | ); |
| 89 | - } | |
| 90 | 87 | |
| 91 | 88 | $this->folders[] = |
| 92 | 89 | array( |
| ... | ... | @@ -97,7 +94,7 @@ class HouseKeeperPlugin extends KTPlugin |
| 97 | 94 | ); |
| 98 | 95 | $this->folders[] = |
| 99 | 96 | array( |
| 100 | - 'name'=>_kt('KnowledgeTree Lucene Indexes'), | |
| 97 | + 'name'=>_kt('KnowledgeTree Document Index'), | |
| 101 | 98 | 'folder'=>$luceneDir, |
| 102 | 99 | 'pattern'=>'', |
| 103 | 100 | 'canClean'=>false | ... | ... |
plugins/housekeeper/templates/DiskUsage.smarty
| 1 | 1 | <table border=0 cellspacing="0" cellpadding="0" width="100%"> |
| 2 | 2 | <tr> |
| 3 | - <td width="250"><B>{i18n}Disk Mount{/i18n}</td> | |
| 3 | + <td width="250"><B>{i18n}Mount{/i18n}</td> | |
| 4 | 4 | <td align="center"><B>{i18n}Size{/i18n}</td> |
| 5 | 5 | <td align="center"><B>{i18n}Used{/i18n}</td> |
| 6 | 6 | <td align="center"><B>{i18n}Available{/i18n}</td> | ... | ... |
plugins/ktcore/scheduler/schedulerUtil.php
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * $Id:$ | |
| 3 | + * $Id:$ | |
| 4 | 4 | * |
| 5 | 5 | * KnowledgeTree Open Source Edition |
| 6 | 6 | * Document Management Made Simple |
| 7 | 7 | * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited |
| 8 | - * | |
| 8 | + * | |
| 9 | 9 | * This program is free software; you can redistribute it and/or modify it under |
| 10 | 10 | * the terms of the GNU General Public License version 3 as published by the |
| 11 | 11 | * Free Software Foundation. |
| 12 | - * | |
| 12 | + * | |
| 13 | 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 15 | 15 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 16 | 16 | * details. |
| 17 | - * | |
| 17 | + * | |
| 18 | 18 | * You should have received a copy of the GNU General Public License |
| 19 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | - * | |
| 20 | + * | |
| 21 | 21 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, |
| 22 | 22 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. |
| 23 | - * | |
| 23 | + * | |
| 24 | 24 | * The interactive user interfaces in modified source and object code versions |
| 25 | 25 | * of this program must display Appropriate Legal Notices, as required under |
| 26 | 26 | * Section 5 of the GNU General Public License version 3. |
| 27 | - * | |
| 27 | + * | |
| 28 | 28 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 29 | 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 | 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 | 34 | * Contributor( s): ______________________________________ |
| 35 | 35 | * |
| 36 | 36 | */ |
| ... | ... | @@ -41,7 +41,7 @@ require_once('schedulerEntity.php'); |
| 41 | 41 | |
| 42 | 42 | class schedulerUtil extends KTUtil |
| 43 | 43 | { |
| 44 | - | |
| 44 | + | |
| 45 | 45 | /** |
| 46 | 46 | * Create a task |
| 47 | 47 | * Parameters must be passed as an associative array => array('param1' => 'value1') |
| ... | ... | @@ -50,75 +50,74 @@ class schedulerUtil extends KTUtil |
| 50 | 50 | // Path to scripts |
| 51 | 51 | $ktPath = '/var/tasks/'; |
| 52 | 52 | $path = KT_DIR.$ktPath; |
| 53 | - | |
| 53 | + | |
| 54 | 54 | if(!is_dir($path)){ |
| 55 | 55 | mkdir($path, '0755'); |
| 56 | 56 | } |
| 57 | - | |
| 57 | + | |
| 58 | 58 | // Create script file |
| 59 | 59 | $sName = str_replace(' ', '_', $sTask); |
| 60 | 60 | $sName = str_replace('', "'", $sName); |
| 61 | 61 | $sName = str_replace('', "&", $sName); |
| 62 | 62 | $sFileName = $sName.'_'.mt_rand(1, 999).'.php'; |
| 63 | - | |
| 63 | + | |
| 64 | 64 | while(file_exists($path.$sFileName)){ |
| 65 | 65 | $sFileName = $sTask.'_'.mt_rand(1, 9999).'.php'; |
| 66 | 66 | } |
| 67 | - | |
| 67 | + | |
| 68 | 68 | $fp = fopen($path.$sFileName, 'w'); |
| 69 | 69 | fwrite($fp, $sScript); |
| 70 | 70 | fclose($fp); |
| 71 | - | |
| 71 | + | |
| 72 | 72 | // Register task in the schedule |
| 73 | 73 | schedulerUtil::registerTask($sTask, $ktPath.$sFileName, $sParams, $sFreq, $iStartTime); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - | |
| 76 | + | |
| 77 | 77 | /** |
| 78 | 78 | * Method to register a task in the schedule |
| 79 | 79 | */ |
| 80 | 80 | function registerTask($sTask, $sUrl, $aParams, $sFreq, $iStartTime = NULL) { |
| 81 | 81 | // Run task on next iteration if no start time given |
| 82 | 82 | $iStartTime = (!empty($iStartTime)) ? strtotime($iStartTime) : time(); |
| 83 | - | |
| 83 | + | |
| 84 | 84 | // Calculate the next run time - get frequency |
| 85 | 85 | $iNextTime = schedulerUtil::calculateRunTime($sFreq, $iStartTime); |
| 86 | - | |
| 86 | + | |
| 87 | 87 | // Convert parameter array to a string => param=value|param2=value2|param3=value3 |
| 88 | 88 | $sParams = schedulerUtil::convertParams($aParams); |
| 89 | - | |
| 89 | + | |
| 90 | 90 | // Convert run times to date time format for DB storage |
| 91 | 91 | $dNextTime = date('Y-m-d H:i:s', $iNextTime); |
| 92 | 92 | $dStartTime = date('Y-m-d H:i:s', $iStartTime); |
| 93 | - | |
| 93 | + | |
| 94 | 94 | // Insert task into DB / task list |
| 95 | 95 | $aTask = array(); |
| 96 | 96 | $aTask['task'] = $sTask; |
| 97 | 97 | $aTask['script_url'] = $sUrl; |
| 98 | 98 | $aTask['script_params'] = $sParams; |
| 99 | - $aTask['is_background'] = '0'; | |
| 100 | 99 | $aTask['is_complete'] = '0'; |
| 101 | 100 | $aTask['frequency'] = $sFreq; |
| 102 | 101 | $aTask['run_time'] = $dNextTime; |
| 103 | 102 | $aTask['previous_run_time'] = $dStartTime; |
| 104 | 103 | $aTask['run_duration'] = '0'; |
| 105 | - | |
| 104 | + | |
| 106 | 105 | $oEntity = schedulerEntity::createFromArray($aTask); |
| 107 | 106 | if (PEAR::isError($oEntity)){ |
| 108 | 107 | return _kt('Scheduler object can\'t be created'); |
| 109 | 108 | } |
| 110 | - | |
| 109 | + | |
| 111 | 110 | return $iNextTime; |
| 112 | 111 | } |
| 113 | - | |
| 112 | + | |
| 114 | 113 | /** |
| 115 | 114 | * Method to register a background task to be run immediately |
| 116 | 115 | */ |
| 117 | 116 | function registerBackgroundTask($sTask, $sUrl, $aParams) { |
| 118 | - | |
| 117 | + | |
| 119 | 118 | // Convert parameter array to a string => param=value|param2=value2|param3=value3 |
| 120 | 119 | $sParams = schedulerUtil::convertParams($aParams); |
| 121 | - | |
| 120 | + | |
| 122 | 121 | // Insert task into DB / task list |
| 123 | 122 | $aTask = array(); |
| 124 | 123 | $aTask['task'] = $sTask; |
| ... | ... | @@ -128,14 +127,14 @@ class schedulerUtil extends KTUtil |
| 128 | 127 | $aTask['is_complete'] = '0'; |
| 129 | 128 | $aTask['run_time'] = date('Y-m-d H:i:s'); |
| 130 | 129 | $aTask['run_duration'] = '0'; |
| 131 | - | |
| 130 | + | |
| 132 | 131 | $oEntity = schedulerEntity::createFromArray($aTask); |
| 133 | 132 | if (PEAR::isError($oEntity)){ |
| 134 | 133 | return _kt('Scheduler object can\'t be created'); |
| 135 | - } | |
| 134 | + } | |
| 136 | 135 | return 'TRUE'; |
| 137 | 136 | } |
| 138 | - | |
| 137 | + | |
| 139 | 138 | /** |
| 140 | 139 | * Convert parameter array to a string |
| 141 | 140 | */ |
| ... | ... | @@ -150,15 +149,15 @@ class schedulerUtil extends KTUtil |
| 150 | 149 | }else{ |
| 151 | 150 | $sParams = $aParams; |
| 152 | 151 | } |
| 153 | - | |
| 152 | + | |
| 154 | 153 | return $sParams; |
| 155 | 154 | } |
| 156 | - | |
| 155 | + | |
| 157 | 156 | /** |
| 158 | 157 | * Calculate the next run time based on the frequency of iteration and the given time |
| 159 | 158 | */ |
| 160 | 159 | function calculateRunTime($sFreq, $iTime) { |
| 161 | - | |
| 160 | + | |
| 162 | 161 | switch($sFreq){ |
| 163 | 162 | case 'monthly': |
| 164 | 163 | $iDays = date('t', $iTime); |
| ... | ... | @@ -191,105 +190,105 @@ class schedulerUtil extends KTUtil |
| 191 | 190 | } |
| 192 | 191 | $iNextTime = $iTime + $iDiff; |
| 193 | 192 | return $iNextTime; |
| 194 | - } | |
| 195 | - | |
| 193 | + } | |
| 194 | + | |
| 196 | 195 | /** |
| 197 | 196 | * Update the frequency of a task |
| 198 | 197 | */ |
| 199 | 198 | function updateTask($id, $sFreq) { |
| 200 | 199 | $oScheduler = schedulerEntity::get($id); |
| 201 | - | |
| 200 | + | |
| 202 | 201 | if (PEAR::isError($oScheduler)){ |
| 203 | 202 | return _kt('Object can\'t be created'); |
| 204 | 203 | } |
| 205 | - | |
| 206 | - // Recalculate the next run time, use the previous run time as the start time. | |
| 204 | + | |
| 205 | + // Recalculate the next run time, use the previous run time as the start time. | |
| 207 | 206 | $iPrevious = $oScheduler->getPrevious(); |
| 208 | 207 | $iNextTime = schedulerUtil::calculateRunTime($sFreq, $iPrevious); |
| 209 | - | |
| 208 | + | |
| 210 | 209 | $oScheduler->setFrequency($sFreq); |
| 211 | 210 | $oScheduler->setRunTime($iNextTime); |
| 212 | 211 | $oScheduler->update(); |
| 213 | 212 | } |
| 214 | - | |
| 213 | + | |
| 215 | 214 | /** |
| 216 | 215 | * Update the run time of a task |
| 217 | 216 | */ |
| 218 | 217 | function updateRunTime($id, $iNextTime) { |
| 219 | 218 | $oScheduler = schedulerEntity::get($id); |
| 220 | - | |
| 219 | + | |
| 221 | 220 | if (PEAR::isError($oScheduler)){ |
| 222 | 221 | return _kt('Object can\'t be created'); |
| 223 | 222 | } |
| 224 | - | |
| 223 | + | |
| 225 | 224 | $oScheduler->setRunTime($iNextTime); |
| 226 | 225 | $oScheduler->update(); |
| 227 | 226 | } |
| 228 | - | |
| 227 | + | |
| 229 | 228 | /** |
| 230 | 229 | * Check the last run time of the scheduler |
| 231 | 230 | */ |
| 232 | 231 | function checkLastRunTime() { |
| 233 | 232 | $now = date('Y-m-d H:i:s'); |
| 234 | 233 | $sLastRunTime = ''; $sNextRunTime = ''; |
| 235 | - | |
| 234 | + | |
| 236 | 235 | // Get the last time the scheduler was run |
| 237 | 236 | $aList = schedulerEntity::getLastRunTime($now); |
| 238 | - | |
| 237 | + | |
| 239 | 238 | if(PEAR::isError($aList)){ |
| 240 | 239 | return _kt('Tasks can\'t be retrieved'); |
| 241 | 240 | } |
| 242 | - | |
| 241 | + | |
| 243 | 242 | if(!empty($aList)){ |
| 244 | 243 | $sLastRunTime = $aList[0]->getPrevious(TRUE); |
| 245 | 244 | } |
| 246 | - | |
| 245 | + | |
| 247 | 246 | // Get the next date when it should be / have been executed |
| 248 | 247 | $aList2 = schedulerEntity::getNextRunTime(''); |
| 249 | - | |
| 248 | + | |
| 250 | 249 | if(PEAR::isError($aList2)){ |
| 251 | 250 | return _kt('Tasks can\'t be retrieved'); |
| 252 | 251 | } |
| 253 | - | |
| 252 | + | |
| 254 | 253 | if(!empty($aList2)){ |
| 255 | 254 | $sNextRunTime = $aList2[0]->getRunTime(); |
| 256 | 255 | } |
| 257 | - | |
| 256 | + | |
| 258 | 257 | return array('lastruntime' => $sLastRunTime, 'nextruntime' => $sNextRunTime); |
| 259 | 258 | } |
| 260 | - | |
| 259 | + | |
| 261 | 260 | /** |
| 262 | 261 | * Delete task by name |
| 263 | 262 | */ |
| 264 | 263 | function deleteByName($sName) { |
| 265 | 264 | // Get task by name |
| 266 | 265 | $oTask = schedulerEntity::getByTaskName($sName); |
| 267 | - | |
| 266 | + | |
| 268 | 267 | if(PEAR::isError($oTask)){ |
| 269 | 268 | return $oTask; |
| 270 | 269 | } |
| 271 | - | |
| 270 | + | |
| 272 | 271 | // Delete |
| 273 | 272 | return $oTask->delete(); |
| 274 | 273 | } |
| 275 | - | |
| 274 | + | |
| 276 | 275 | /** |
| 277 | 276 | * Get all completed tasks and delete |
| 278 | 277 | */ |
| 279 | 278 | function cleanUpTasks() { |
| 280 | 279 | // Get list of completed from database |
| 281 | 280 | $aList = schedulerEntity::getTaskList('1'); |
| 282 | - | |
| 281 | + | |
| 283 | 282 | if (PEAR::isError($aList)){ |
| 284 | 283 | return _kt('List of tasks can\'t be retrieved.'); |
| 285 | 284 | } |
| 286 | - | |
| 285 | + | |
| 287 | 286 | if(!empty($aList)){ |
| 288 | 287 | // start the background process |
| 289 | 288 | $bg = new background(); |
| 290 | 289 | $bg->checkConnection(); |
| 291 | 290 | $bg->keepConnectionAlive(); |
| 292 | - | |
| 291 | + | |
| 293 | 292 | foreach($aList as $oScheduler){ |
| 294 | 293 | $oScheduler->delete(); |
| 295 | 294 | } | ... | ... |
search2/indexing/indexerCore.inc.php
| ... | ... | @@ -489,7 +489,7 @@ abstract class Indexer |
| 489 | 489 | $content = preg_replace($src, $tgt, $content); |
| 490 | 490 | } while ($content != $orig); |
| 491 | 491 | |
| 492 | - return file_put_contents($filename, $content); | |
| 492 | + return file_put_contents($filename, $content) !== false; | |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | /** | ... | ... |