Commit 2fe5401e58e0858ccae50b1fd576c19a1748983d

Authored by Megan Watson
1 parent 0a4058ab

KTS-1554

"Implement a Scheduler"
Updated. Added a check on the extension to ensure .sh scripts run on *nix and .bat on windows, etc.

Committed by: Megan Watson
Reviewed by: Conrad Vermeulen



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7455 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 41 additions and 16 deletions
bin/scheduler.php
... ... @@ -117,24 +117,49 @@ if(!empty($aList)){
117 117 $sFreq = $item['frequency'];
118 118 $sParameters = $item['script_params'];
119 119  
120   - $iTime = time();
121   - $iStart = explode(' ', microtime());
122   -
123   - /* Set up parameters for use by the script
124   - $aParams = explode('|', $sParameters);
125   -
126   - foreach($aParams as $param){
127   - $aParam = explode('=', $param);
128   - if(!empty($aParam)){
129   - $$aParam[0] = $aParam[1];
130   - $sParamList .= "{$aParam[0]} {$aParam[1]} ";
  120 + // Check if script is windows or *nix compatible
  121 + $extArr = explode('.', $sTaskUrl);
  122 + $ext = array_pop($extArr);
  123 + $script = implode('.', $extArr);
  124 + if(OS_WINDOWS){
  125 + switch($ext){
  126 + case 'sh':
  127 + $sTaskUrl = $script.'.bat';
  128 + break;
  129 + case 'bin':
  130 + $sTaskUrl = $script.'.exe';
  131 + break;
  132 + }
  133 + }else{
  134 + switch($ext){
  135 + case 'bat':
  136 + if(file_exists(KT_DIR . $script.'.sh')){
  137 + $sTaskUrl = $script.'.sh';
  138 + break;
  139 + }
  140 + // File doesn't exist - log error
  141 + $default->log->error("Scheduler: Task script can't be found at ".KT_DIR."{$script}.sh");
  142 + continue;
  143 + break;
  144 + case 'exe':
  145 + if(file_exists(KT_DIR . $script)){
  146 + $sTaskUrl = $script;
  147 + break;
  148 + }
  149 + if(file_exists(KT_DIR . $script.'.bin')){
  150 + $sTaskUrl = $script.'.bin';
  151 + break;
  152 + }
  153 + // File doesn't exist - log error
  154 + $default->log->error("Scheduler: Task script can't be found at ".KT_DIR."{$script} or ".KT_DIR."{$script}.bin");
  155 + continue;
  156 + break;
131 157 }
132 158 }
133   - */
134   -
135   - // Run the script as php
136   - //include(KT_DIR . $sTaskUrl);
137   -
  159 +
  160 + $iTime = time();
  161 + $iStart = explode(' ', microtime());
  162 +
138 163 // Run the script
139 164 $file = KT_DIR . escapeshellcmd($sTaskUrl);
140 165 system("{$file} {$sParameters} >> /dev/null", $retval);
... ...