changed git call from https to git readonly
[atutor.git] / mods / wiki / tools / cron.d / run-parts.php
1 <?php
2 /*
3    The ewiki/tools/cron.d/ run-parts wrapper looks at all the files in
4    its own directory and simply includes() one after another. Scripts
5    found herein typically accomplish admistrative tasks that require no
6    human observation.
7    
8    All S** parts are run in ascending order, then Z** and any K** parts
9    get run in reverse order. The former is stopped when one of the
10    scripts sets the $HALT or $STOP variables. The latter can be prevented
11    only with $HALT >= 2.
12    There is also a $GOTO variable available, which allows to overstep a
13    few scripts by numeric id (the anacron snippets use that).
14
15    Please see the HOWTO on more notes on how to activate this.
16 */
17
18
19 #-- read in current directory
20 $dir = dirname(__FILE__);
21 $startparts = array();
22 $killparts = array();
23 if ($dh = opendir($dir)) {
24    while ($fn = readdir($dh)) {
25       if (preg_match("/^[SKZ]\d\d.+\.php$/", $fn)) {
26          if ($fn[0]=="S") {
27             $startparts[] = "$dir/$fn";
28          }
29          else {
30             $killparts[] = "$dir/$fn";
31          }
32       }
33    }
34    closedir($dh);
35    $dh = NULL;
36 }
37
38 #-- run 'S'tart-scripts
39 $STOP=$HALT=false;
40 if ($startparts) {
41    asort($startparts);
42    foreach ($startparts as $fn) { 
43
44       #-- make script id string from filename
45       $cron = strtok(substr($fn, strrpos($fn, "/") + 1), ".");
46
47       #-- overstep a few scripts, if instructed to do so
48       $num = substr($cron, 1, 2);
49       if ($GOTO && ($num<$GOTO)) {
50          continue;
51       }
52
53       #-- run current
54       include($fn);      
55
56       #-- stop processing
57       if ($STOP |= $HALT) {
58          break;
59       }
60    }
61 }
62
63 #-- reverse order for 'K'ill and 'Z'leep -scripts
64 if ($killparts && ($HALT < 2)) {
65    arsort($killparts);
66    foreach ($killparts as $fn) { 
67       $cron = strtok(substr($fn, strrpos($fn, "/") + 1), ".");
68       include($fn);      
69    }
70 }
71
72
73 #-- fin
74 $startparts=$killparts=$cron=$fn=$STOP=$HALT=NULL;
75 // something else may follow here
76
77 ?>