Convert Horde_Scheduler to H4.
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 9 Mar 2010 21:58:48 +0000 (14:58 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 11 Mar 2010 06:17:28 +0000 (23:17 -0700)
framework/Scheduler/lib/Horde/Scheduler.php
framework/Scheduler/lib/Horde/Scheduler/Cron.php [new file with mode: 0644]
framework/Scheduler/lib/Horde/Scheduler/Cron/Date.php [new file with mode: 0644]
framework/Scheduler/lib/Horde/Scheduler/cron.php [deleted file]
framework/Scheduler/package.xml
framework/Scheduler/scripts/Horde/Scheduler/horde-crond.php
whups/lib/Scheduler/Whups.php [new file with mode: 0644]
whups/lib/Scheduler/whups.php [deleted file]
whups/scripts/reminders.php

index 793c74b..d88d0a7 100644 (file)
@@ -4,21 +4,43 @@
  *
  * @package Horde_Scheduler
  */
-class Horde_Scheduler {
-
+class Horde_Scheduler
+{
     /**
      * Name of the sleep function.
      *
      * @var string
      */
-    var $_sleep;
+    protected $_sleep;
 
     /**
      * Adjustment factor to sleep in microseconds.
      *
      * @var integer
      */
-    var $_sleep_adj;
+    protected $_sleep_adj;
+
+    /**
+     * Attempts to return a concrete Horde_Scheduler instance based on $driver.
+     *
+     * @param string $driver The type of concrete subclass to return.
+     * @param array $params  A hash containing any additional configuration or
+     *                       connection parameters a subclass might need.
+     *
+     * @return Horde_Scheduler  The newly created concrete instance.
+     * @throws Horde_Scheduler_Exception
+     */
+    static public function factory($driver, $params = null)
+    {
+        $driver = basename($driver);
+        $class = 'Horde_Scheduler_' . $driver;
+
+        if (class_exists($class)) {
+            return new $class($params);
+        }
+
+        throw new Horde_Scheduler_Exception('Class definition of ' . $class . ' not found.');
+    }
 
     /**
      * Constructor.
@@ -26,7 +48,7 @@ class Horde_Scheduler {
      * Figures out how we can best sleep with microsecond precision
      * based on what platform we're running on.
      */
-    function Horde_Scheduler()
+    public function __construct()
     {
         if (!strncasecmp(PHP_OS, 'WIN', 3)) {
             $this->_sleep = 'sleep';
@@ -39,10 +61,8 @@ class Horde_Scheduler {
 
     /**
      * Main loop/action function.
-     *
-     * @abstract
      */
-    function run()
+    public function run()
     {
     }
 
@@ -54,10 +74,12 @@ class Horde_Scheduler {
      * serialization or deserialization - handling database
      * connections, etc.
      *
-     * @param string  $id  An id to uniquely identify this scheduler from
-     *                     others of the same class.
+     * @param string $id  An id to uniquely identify this scheduler from
+     *                    others of the same class.
+     *
+     * @return boolean  Success result.
      */
-    function serialize($id = '')
+    public function serialize($id = '')
     {
         try {
             $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'],
@@ -73,15 +95,15 @@ class Horde_Scheduler {
     /**
      * Restore a Horde_Scheduler object from the cache.
      *
-     * @param string  $class     The name of the Horde_Scheduler object to restore.
-     * @param string  $id        An id to uniquely identify this
+     * @param string $class      The name of the object to restore.
+     * @param string $id         An id to uniquely identify this
      *                           scheduler from others of the same class.
      * @param boolean $autosave  Automatically store (serialize) the returned
      *                           object at script shutdown.
      *
      * @see Horde_Scheduler::serialize()
      */
-    function &unserialize($class, $id = '', $autosave = true)
+    public function unserialize($class, $id = '', $autosave = true)
     {
         // Need a lowercase version of the classname, and a default
         // instance of the scheduler object in case we can't retrieve
@@ -112,35 +134,9 @@ class Horde_Scheduler {
      *
      * @param integer $msec  Microseconds to sleep.
      */
-    function sleep($msec)
+    public function sleep($msec)
     {
         call_user_func($this->_sleep, $msec / $this->_sleep_adj);
     }
 
-    /**
-     * Attempts to return a concrete Horde_Scheduler instance based on $driver.
-     *
-     * @param string $driver The type of concrete Horde_Scheduler subclass to
-     *                       return.
-     * @param array $params  A hash containing any additional configuration or
-     *                       connection parameters a subclass might need.
-     *
-     * @return Horde_Scheduler  The newly created concrete Horde_Scheduler
-     *                          instance, or an error object.
-     */
-    function factory($driver, $params = null)
-    {
-        $driver = basename($driver);
-        $class = 'Horde_Scheduler_' . $driver;
-        if (!class_exists($class)) {
-            include 'Horde/Scheduler/' . $driver . '.php';
-        }
-
-        if (class_exists($class)) {
-            return new $class($params);
-        } else {
-            return PEAR::raiseError('Class definition of ' . $class . ' not found.');
-        }
-    }
-
 }
diff --git a/framework/Scheduler/lib/Horde/Scheduler/Cron.php b/framework/Scheduler/lib/Horde/Scheduler/Cron.php
new file mode 100644 (file)
index 0000000..6cea928
--- /dev/null
@@ -0,0 +1,126 @@
+<?php
+/**
+ * Horde_Scheduler_cron:: Sort of a cron replacement in a PHP cli
+ * script.
+ *
+ * Date Syntax Examples.
+ *
+ * Remember:
+ *   - Whitespace (space, tab, newline) delimited fields
+ *   - Single values, sets, ranges, wildcards
+ *
+ * SECOND   MINUTE              HOUR        DAY     MONTH
+ * *        *                   *           *       *       (every second)
+ * 0,30     *                   *           *       *       (every 30 seconds)
+ * 0        0,10,20,30,40,50    *           *       *       (every 10 minutes)
+ * 0        0                   *           *       *       (beginning of every hour)
+ * 0        0                   0,6,12,18   *       *       (at midnight, 6am, noon, 6pm)
+ * 0        0                   0           1-7&Fri *       (midnight, first Fri of the month)
+ * 0        0                   0           1-7!Fri *       (midnight, first Mon-Thu,Sat-Sun of the month)
+ *
+ *
+ * Example usage:
+ *
+ * @set_time_limit(0);
+ * $cron = Horde_Scheduler::factory('Cron');
+ *
+ * // Run this command every 5 minutes.
+ * $cron->addTask('perl somescript.pl', '0 0,5,10,15,20,25,30,35,40,45,50,55 * * *');
+ *
+ * // Run this command midnight of the first Friday of odd numbered months.
+ * $cron->addTask('php -q somescript.php', '0 0 0 1-7&Fri 1,3,5,7,9,11');
+ *
+ * // Also run this command midnight of the second Thursday and Saturday of the even numbered months.
+ * $cron->addTask('php -q somescript.php', '0 0 0 8-15&Thu,8-15&Sat 2,4,6,8,10,12');
+ *
+ * $cron->run();
+ *
+ * @author  Ryan Flynn <ryan@ryanflynn.com>
+ * @author  Chuck Hagenbuch <chuck@horde.org>
+ * @package Horde_Scheduler
+ */
+class Horde_Scheduler_Cron extends Horde_Scheduler
+{
+    /**
+     * TODO
+     *
+     * @var array
+     */
+    protected $_tasks = array();
+
+    /**
+     * Every time a task is added it will get a fresh uid even if
+     * immediately removed.
+     *
+     * @var integer
+     */
+    var $_counter = 1;
+
+    /**
+     */
+    public function addTask($cmd, $rules)
+    {
+        $ds = new Horde_Scheduler_Cron_Date($rules);
+
+        $this->_counter++;
+
+        $this->_tasks[] =
+            array(
+                'uid' => $this->_counter,
+                'rules' => $ds,
+                'cmd' => $cmd
+            );
+
+        return $this->_counter;
+    }
+
+    /**
+     */
+    public function removeTask($uid)
+    {
+        $count = count($this->_tasks);
+        for ($i = 0; $i < $count; $i++) {
+            if ($this->_tasks['uid'] == $uid) {
+                $found = $i;
+                array_splice($this->_tasks, $i);
+                return $i;
+            }
+        }
+
+        return 0;
+    }
+
+    /**
+     */
+    public function run()
+    {
+        if (!count($this->_tasks)) {
+            exit("crond: Nothing to schedule; exiting.\n");
+        }
+
+        while (true) {
+            $t = time();
+
+            // Check each task.
+            foreach ($this->_tasks as $task) {
+                if ($task['rules']->nowMatches()) {
+                    $this->runcmd($task);
+                }
+            }
+
+            // Wait until the next second.
+            while (time() == $t) {
+                $this->sleep(100000);
+            }
+        }
+    }
+
+    /**
+     */
+    public function runcmd(&$task)
+    {
+        Horde::logMessage('runcmd(): ' . $task['cmd'] . ' run by ' . $task['uid'], __FILE__, __LINE__, PEAR_LOG_INFO);
+        return shell_exec($task['cmd']);
+    }
+
+}
diff --git a/framework/Scheduler/lib/Horde/Scheduler/Cron/Date.php b/framework/Scheduler/lib/Horde/Scheduler/Cron/Date.php
new file mode 100644 (file)
index 0000000..678b859
--- /dev/null
@@ -0,0 +1,307 @@
+<?php
+/**
+ * @author  Ryan Flynn <ryan@ryanflynn.com>
+ * @author  Chuck Hagenbuch <chuck@horde.org>
+ * @package Horde_Scheduler
+ */
+class Horde_Scheduler_Cron_Date
+{
+    public $legalDays = array('MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN');
+
+    public $sec;
+    public $min;
+    public $hour;
+    public $day;
+    public $month;
+
+    public function __construct($raw)
+    {
+        $this->parse(Horde_String::upper($raw));
+    }
+
+    public function nowMatches()
+    {
+        return $this->scheduledAt(time());
+    }
+
+    public function scheduledAt($ts = null)
+    {
+        if ($ts === null) {
+            $ts = time();
+        }
+        return ($this->monthMatches($ts) &&
+                $this->monthMatches($ts) &&
+                $this->dayMatches($ts) &&
+                $this->hourMatches($ts) &&
+                $this->minMatches($ts) &&
+                $this->secMatches($ts));
+    }
+
+    public function monthMatches($ts)
+    {
+        if ($this->month == '*') {
+            return true;
+        }
+
+        $currentmonth = '-' . date('n', $ts) . '-';
+
+        return (bool)strpos($this->month, $currentmonth);
+    }
+
+    public function dayMatches($ts)
+    {
+        if (!empty($this->day['value']) && $this->day['value'] == '*') {
+            return true;
+        }
+
+        $currentdaynum = '-' . date('j', $ts) . '-';
+        $currentdaytxt = Horde_String::upper(date('D'));
+
+        foreach ($this->day as $day) {
+            if (@strpos($day['not'], $currentdaytxt) === false) {
+                $v1 = (@strpos($day['value'], $currentdaynum) !== false);
+                $v2 = (@strpos($day['and'], $currentdaytxt) !== false);
+
+                if (!empty($day['and']) && ($v1 && $v2)) {
+                    return true;
+                } elseif (empty($day['and']) && $v1) {
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
+
+    public function hourMatches($ts)
+    {
+        if ($this->hour == '*') {
+            return true;
+        }
+
+        $currenthour = '-' . date('G', $ts) . '-';
+
+        return (strpos($this->hour, $currenthour) !== false);
+    }
+
+    public function minMatches($ts)
+    {
+        if ($this->min == '*') {
+            return true;
+        }
+
+        $currentmin = '-' . intval(date('i', $ts)) . '-';
+
+        return (strpos($this->min, $currentmin) !== false);
+    }
+
+    public function secMatches($ts)
+    {
+        if ($this->sec == '*') {
+            return true;
+        }
+
+        $currentsec = '-' . intval(date('s', $ts)) . '-';
+
+        return (strpos($this->sec, $currentsec) !== false);
+    }
+
+    public function parse($str)
+    {
+        $s = array();
+
+        list($s['sec'], $s['min'], $s['hour'], $s['day'], $s['month']) = preg_split('|[\n\t ]+|', $str);
+
+        foreach ($s as $k => $v) {
+            if (strpos($v, '*') !== false) {
+                $s[$k] = array('*');
+            } elseif (!$this->generallyDecentSyntax($v)) {
+                die("Illegal syntax in '$v'\n");
+            } else {
+                $s[$k] = explode(',', $s[$k]);
+            }
+        }
+
+        if ($s['sec'][0] == '*') {
+            $this->sec = '*';
+        } else {
+            for ($i = 0; $i < sizeof($s['sec']); $i++) {
+                if ($this->isRange($s['sec'][$i])) {
+                    $s['sec'][$i] = $this->expandRange($this->rangeVals($s['sec'][$i]));
+                }
+            }
+            $this->sec = '-' . join('-', $s['sec']) . '-';
+        }
+
+        if ($s['min'][0] == '*') {
+            $this->min = '*';
+        } else {
+            for ($i = 0; $i < sizeof($s['min']); $i++) {
+                if ($this->isRange($s['min'][$i])) {
+                    $s['min'][$i] = $this->expandRange($this->rangeVals($s['min'][$i]));
+                }
+            }
+            $this->min = '-' . join('-', $s['min']) . '-';
+        }
+
+        if ($s['hour'][0] == '*') {
+            $this->hour = '*';
+        } else {
+            for ($i = 0; $i < sizeof($s['hour']); $i++) {
+                if ($this->isRange($s['hour'][$i])) {
+                    $s['hour'][$i] = $this->expandRange($this->rangeVals($s['hour'][$i]));
+                }
+            }
+            $this->hour = '-' . join('-', $s['hour']) . '-';
+        }
+
+        if ($s['day'][0] == '*') {
+            $this->day = '*';
+        } else {
+            for ($i = 0; $i < sizeof($s['day']); $i++) {
+                $tmp = array();
+                if (($char = $this->isCond($s['day'][$i])) !== false) {
+                    if ($char == '&') {
+                        list($tmp['value'], $tmp['and']) = explode($char, $s['day'][$i]);
+                        if ($this->isRange($tmp['and'])) {
+                            $tmp['and'] = $this->expandRange($this->rangeVals($tmp['and']));
+                        }
+                    } else {
+                        list($tmp['value'], $tmp['not']) = explode($char, $s['day'][$i]);
+                        if ($this->isRange($tmp['not'])) {
+                            $tmp['not'] = $this->expandRange($this->rangeVals($tmp['not']));
+                        }
+                    }
+                } else {
+                    $tmp = array('value' => $s['day'][$i]);
+                }
+
+                $s['day'][$i] = $tmp;
+
+                if ($this->isRange($s['day'][$i]['value'])) {
+                    $s['day'][$i]['value'] = $this->expandRange($this->rangeVals($s['day'][$i]['value']));
+                }
+            }
+
+            $this->day = $s['day'];
+        }
+
+        if ($s['month'][0] == '*') {
+            $this->month = '*';
+        } else {
+            for ($i = 0; $i < sizeof($s['month']); $i++) {
+                if ($this->isRange($s['month'][$i])) {
+                    $s['month'][$i] = $this->expandRange($this->rangeVals($s['month'][$i]));
+                }
+            }
+            $this->month = '-' . join('-', $s['month']) . '-';
+        }
+    }
+
+    public function isCond($s)
+    {
+        if (strpos($s, '&') !== false) {
+            return '&';
+        } elseif (strpos($s, '!') !== false) {
+            return '!';
+        } else {
+            return false;
+        }
+    }
+
+    public function isRange($s)
+    {
+        return preg_match('/^\w+\-\w+/', $s);
+    }
+
+    public function isCondRange($s)
+    {
+        return ($this->isCond($s) && $this->isRange($s));
+    }
+
+    public function isCondVal($s)
+    {
+        return ($this->isCond($s) && !$this->isRange($s));
+    }
+
+    public function rangeVals($s)
+    {
+        return explode('-', $s);
+    }
+
+    public function expandRange($l, $h = '')
+    {
+        // Expand range from 1-5 -> '-1-2-3-4-5-'.
+        if (is_array($l)) {
+            $h = $l[1];
+            $l = $l[0];
+        }
+
+        if ($this->isDigit($l)) {
+            if (!$this->isDigit($h)) {
+                die("Invalid value '$h' in range '$l-$h'");
+            }
+
+            // Currently there is no possible reason to need to do a
+            // range beyond 0-59 for anything.
+            if ($l < 0) {
+                $l = 0;
+            } elseif ($l > 59) {
+                $l = 59;
+            }
+
+            if ($h < 0) {
+                $h = 0;
+            } elseif ($h > 59) {
+                $h = 59;
+            }
+
+            if ($l > $h) {
+                $tmp = $l;
+                $l = $h;
+                $h = $tmp;
+                unset($tmp);
+            }
+
+            // For some reason range() doesn't work w/o the explicit
+            // intval() calls.
+            return '-' . join('-', range(intval($l), intval($h))) . '-';
+        } else {
+            // Invalid.
+            die("Invalid value '$l' in range '$l-$h'");
+        }
+    }
+
+    public function dayValue($s)
+    {
+        for ($i = 0; $i < count($this->legalDays); $i++) {
+            if ($this->legalDays[$i] == $s) {
+                return $i;
+            }
+        }
+
+        return -1;
+    }
+
+    public function isDigit($s)
+    {
+        return preg_match('/^\d+$/', $s);
+    }
+
+    public function isAlpha($s)
+    {
+        return $this->isLegalDay($s);
+    }
+
+    public function isLegalDay($s)
+    {
+        return in_array($s, $this->legalDays);
+    }
+
+    public function generallyDecentSyntax($s)
+    {
+        return ($s == '*' ||
+                preg_match('/^\d+(-\d+)?([!&][A-Z\*]+(-[A-Z\*]+)?)?(,\d+(-\d+)?([!&][A-Z\*]+(-[A-Z\*]+)?)?)*$/', $s));
+    }
+
+}
diff --git a/framework/Scheduler/lib/Horde/Scheduler/cron.php b/framework/Scheduler/lib/Horde/Scheduler/cron.php
deleted file mode 100644 (file)
index ea780da..0000000
+++ /dev/null
@@ -1,417 +0,0 @@
-<?php
-/**
- * Horde_Scheduler_cron:: Sort of a cron replacement in a PHP cli
- * script.
- *
- * Date Syntax Examples.
- *
- * Remember:
- *   - Whitespace (space, tab, newline) delimited fields
- *   - Single values, sets, ranges, wildcards
- *
- * SECOND   MINUTE              HOUR        DAY     MONTH
- * *        *                   *           *       *       (every second)
- * 0,30     *                   *           *       *       (every 30 seconds)
- * 0        0,10,20,30,40,50    *           *       *       (every 10 minutes)
- * 0        0                   *           *       *       (beginning of every hour)
- * 0        0                   0,6,12,18   *       *       (at midnight, 6am, noon, 6pm)
- * 0        0                   0           1-7&Fri *       (midnight, first Fri of the month)
- * 0        0                   0           1-7!Fri *       (midnight, first Mon-Thu,Sat-Sun of the month)
- *
- *
- * Example usage:
- *
- * @set_time_limit(0);
- * require_once 'Horde/Scheduler.php';
- * $cron = Horde_Scheduler::factory('cron');
- *
- * // Run this command every 5 minutes.
- * $cron->addTask('perl somescript.pl', '0 0,5,10,15,20,25,30,35,40,45,50,55 * * *');
- *
- * // Run this command midnight of the first Friday of odd numbered months.
- * $cron->addTask('php -q somescript.php', '0 0 0 1-7&Fri 1,3,5,7,9,11');
- *
- * // Also run this command midnight of the second Thursday and Saturday of the even numbered months.
- * $cron->addTask('php -q somescript.php', '0 0 0 8-15&Thu,8-15&Sat 2,4,6,8,10,12');
- *
- * $cron->run();
- *
- * @author  Ryan Flynn <ryan@ryanflynn.com>
- * @author  Chuck Hagenbuch <chuck@horde.org>
- * @package Horde_Scheduler
- */
-class Horde_Scheduler_cron extends Horde_Scheduler {
-
-    var $_tasks = array();
-
-    /**
-     * Every time a task is added it will get a fresh uid even if
-     * immediately removed.
-     */
-    var $_counter = 1;
-
-    function addTask($cmd, $rules)
-    {
-        $ds = new Horde_Scheduler_cronDate($rules);
-
-        $this->_counter++;
-
-        $this->_tasks[] =
-            array(
-                'uid' => $this->_counter,
-                'rules' => $ds,
-                'cmd' => $cmd
-            );
-
-        return $this->_counter;
-    }
-
-    function removeTask($uid)
-    {
-        $count = count($this->_tasks);
-        for ($i = 0; $i < $count; $i++) {
-            if ($this->_tasks['uid'] == $uid) {
-                $found = $i;
-                array_splice($this->_tasks, $i);
-                return $i;
-            }
-        }
-
-        return 0;
-    }
-
-    function run()
-    {
-        if (!count($this->_tasks)) {
-            exit("crond: Nothing to schedule; exiting.\n");
-        }
-
-        while (true) {
-            $t = time();
-
-            // Check each task.
-            foreach ($this->_tasks as $task) {
-                if ($task['rules']->nowMatches()) {
-                    $this->runcmd($task);
-                }
-            }
-
-            // Wait until the next second.
-            while (time() == $t) {
-                $this->sleep(100000);
-            }
-        }
-    }
-
-    function runcmd(&$task)
-    {
-        Horde::logMessage('Horde_Scheduler_Cron::runcmd(): ' . $task['cmd'] . ' run by ' . $task['uid'], __FILE__, __LINE__, PEAR_LOG_INFO);
-        return shell_exec($task['cmd']);
-    }
-
-}
-
-/**
- * @package Horde_Scheduler
- */
-class Horde_Scheduler_cronDate {
-
-    var $legalDays = array('MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN');
-
-    var $sec;
-    var $min;
-    var $hour;
-    var $day;
-    var $month;
-
-    function Horde_Scheduler_cronDate($raw)
-    {
-        $this->parse(Horde_String::upper($raw));
-    }
-
-    function nowMatches()
-    {
-        return $this->scheduledAt(time());
-    }
-
-    function scheduledAt($ts = null)
-    {
-        if ($ts === null) {
-            $ts = time();
-        }
-        return ($this->monthMatches($ts) &&
-                $this->monthMatches($ts) &&
-                $this->dayMatches($ts) &&
-                $this->hourMatches($ts) &&
-                $this->minMatches($ts) &&
-                $this->secMatches($ts));
-    }
-
-    function monthMatches($ts)
-    {
-        if ($this->month == '*') {
-            return true;
-        }
-
-        $currentmonth = '-' . date('n', $ts) . '-';
-
-        return (bool)strpos($this->month, $currentmonth);
-    }
-
-    function dayMatches($ts)
-    {
-        if (!empty($this->day['value']) && $this->day['value'] == '*') {
-            return true;
-        }
-
-        $currentdaynum = '-' . date('j', $ts) . '-';
-        $currentdaytxt = Horde_String::upper(date('D'));
-
-        foreach ($this->day as $day) {
-            if (@strpos($day['not'], $currentdaytxt) === false) {
-                $v1 = (@strpos($day['value'], $currentdaynum) !== false);
-                $v2 = (@strpos($day['and'], $currentdaytxt) !== false);
-
-                if (!empty($day['and']) && ($v1 && $v2)) {
-                    return true;
-                } elseif (empty($day['and']) && $v1) {
-                    return true;
-                }
-            }
-        }
-
-        return false;
-    }
-
-    function hourMatches($ts)
-    {
-        if ($this->hour == '*') {
-            return true;
-        }
-
-        $currenthour = '-' . date('G', $ts) . '-';
-
-        return (strpos($this->hour, $currenthour) !== false);
-    }
-
-    function minMatches($ts)
-    {
-        if ($this->min == '*') {
-            return true;
-        }
-
-        $currentmin = '-' . intval(date('i', $ts)) . '-';
-
-        return (strpos($this->min, $currentmin) !== false);
-    }
-
-    function secMatches($ts)
-    {
-        if ($this->sec == '*') {
-            return true;
-        }
-
-        $currentsec = '-' . intval(date('s', $ts)) . '-';
-
-        return (strpos($this->sec, $currentsec) !== false);
-    }
-
-    function parse($str)
-    {
-        $s = array();
-
-        list($s['sec'], $s['min'], $s['hour'], $s['day'], $s['month']) = preg_split('|[\n\t ]+|', $str);
-
-        foreach ($s as $k => $v) {
-            if (strpos($v, '*') !== false) {
-                $s[$k] = array('*');
-            } elseif (!$this->generallyDecentSyntax($v)) {
-                die("Illegal syntax in '$v'\n");
-            } else {
-                $s[$k] = explode(',', $s[$k]);
-            }
-        }
-
-        if ($s['sec'][0] == '*') {
-            $this->sec = '*';
-        } else {
-            for ($i = 0; $i < sizeof($s['sec']); $i++) {
-                if ($this->isRange($s['sec'][$i])) {
-                    $s['sec'][$i] = $this->expandRange($this->rangeVals($s['sec'][$i]));
-                }
-            }
-            $this->sec = '-' . join('-', $s['sec']) . '-';
-        }
-
-        if ($s['min'][0] == '*') {
-            $this->min = '*';
-        } else {
-            for ($i = 0; $i < sizeof($s['min']); $i++) {
-                if ($this->isRange($s['min'][$i])) {
-                    $s['min'][$i] = $this->expandRange($this->rangeVals($s['min'][$i]));
-                }
-            }
-            $this->min = '-' . join('-', $s['min']) . '-';
-        }
-
-        if ($s['hour'][0] == '*') {
-            $this->hour = '*';
-        } else {
-            for ($i = 0; $i < sizeof($s['hour']); $i++) {
-                if ($this->isRange($s['hour'][$i])) {
-                    $s['hour'][$i] = $this->expandRange($this->rangeVals($s['hour'][$i]));
-                }
-            }
-            $this->hour = '-' . join('-', $s['hour']) . '-';
-        }
-
-        if ($s['day'][0] == '*') {
-            $this->day = '*';
-        } else {
-            for ($i = 0; $i < sizeof($s['day']); $i++) {
-                $tmp = array();
-                if (($char = $this->isCond($s['day'][$i])) !== false) {
-                    if ($char == '&') {
-                        list($tmp['value'], $tmp['and']) = explode($char, $s['day'][$i]);
-                        if ($this->isRange($tmp['and'])) {
-                            $tmp['and'] = $this->expandRange($this->rangeVals($tmp['and']));
-                        }
-                    } else {
-                        list($tmp['value'], $tmp['not']) = explode($char, $s['day'][$i]);
-                        if ($this->isRange($tmp['not'])) {
-                            $tmp['not'] = $this->expandRange($this->rangeVals($tmp['not']));
-                        }
-                    }
-                } else {
-                    $tmp = array('value' => $s['day'][$i]);
-                }
-
-                $s['day'][$i] = $tmp;
-
-                if ($this->isRange($s['day'][$i]['value'])) {
-                    $s['day'][$i]['value'] = $this->expandRange($this->rangeVals($s['day'][$i]['value']));
-                }
-            }
-
-            $this->day = $s['day'];
-        }
-
-        if ($s['month'][0] == '*') {
-            $this->month = '*';
-        } else {
-            for ($i = 0; $i < sizeof($s['month']); $i++) {
-                if ($this->isRange($s['month'][$i])) {
-                    $s['month'][$i] = $this->expandRange($this->rangeVals($s['month'][$i]));
-                }
-            }
-            $this->month = '-' . join('-', $s['month']) . '-';
-        }
-    }
-
-    function isCond($s)
-    {
-        if (strpos($s, '&') !== false) {
-            return '&';
-        } elseif (strpos($s, '!') !== false) {
-            return '!';
-        } else {
-            return false;
-        }
-    }
-
-    function isRange($s)
-    {
-        return preg_match('/^\w+\-\w+/', $s);
-    }
-
-    function isCondRange($s)
-    {
-        return (isCond($s) && isRange($s));
-    }
-
-    function isCondVal($s)
-    {
-        return (isCond($s) && !isRange($s));
-    }
-
-    function rangeVals($s)
-    {
-        return explode('-', $s);
-    }
-
-    function expandRange($l, $h = '')
-    {
-        // Expand range from 1-5 -> '-1-2-3-4-5-'.
-        if (is_array($l)) {
-            $h = $l[1];
-            $l = $l[0];
-        }
-
-        if ($this->isDigit($l)) {
-            if (!$this->isDigit($h)) {
-                die("Invalid value '$h' in range '$l-$h'");
-            }
-
-            // Currently there is no possible reason to need to do a
-            // range beyond 0-59 for anything.
-            if ($l < 0) {
-                $l = 0;
-            } elseif ($l > 59) {
-                $l = 59;
-            }
-
-            if ($h < 0) {
-                $h = 0;
-            } elseif ($h > 59) {
-                $h = 59;
-            }
-
-            if ($l > $h) {
-                $tmp = $l;
-                $l = $h;
-                $h = $tmp;
-                unset($tmp);
-            }
-
-            // For some reason range() doesn't work w/o the explicit
-            // intval() calls.
-            return '-' . join('-', range(intval($l), intval($h))) . '-';
-        } else {
-            // Invalid.
-            die("Invalid value '$l' in range '$l-$h'");
-        }
-    }
-
-    function dayValue($s)
-    {
-        for ($i = 0; $i < count($this->legalDays); $i++) {
-            if ($this->legalDays[$i] == $s) {
-                return $i;
-            }
-        }
-
-        return -1;
-    }
-
-    function isDigit($s)
-    {
-        return preg_match('/^\d+$/', $s);
-    }
-
-    function isAlpha($s)
-    {
-        return $this->isLegalDay($s);
-    }
-
-    function isLegalDay($s)
-    {
-        return in_array($s, $this->legalDays);
-    }
-
-    function generallyDecentSyntax($s)
-    {
-        return ($s == '*' ||
-                preg_match('/^\d+(-\d+)?([!&][A-Z\*]+(-[A-Z\*]+)?)?(,\d+(-\d+)?([!&][A-Z\*]+(-[A-Z\*]+)?)?)*$/', $s));
-    }
-
-}
index c73fe7c..0f7dad1 100644 (file)
@@ -14,18 +14,17 @@ http://pear.php.net/dtd/package-2.0.xsd">
   <email>chuck@horde.org</email>
   <active>yes</active>
  </lead>
- <date>2006-05-08</date>
- <time>23:07:47</time>
+ <date>2010-03-09</date>
  <version>
-  <release>0.0.2</release>
-  <api>0.0.2</api>
+  <release>0.1.0</release>
+  <api>0.1.0</api>
  </version>
  <stability>
-  <release>alpha</release>
-  <api>alpha</api>
+  <release>beta</release>
+  <api>beta</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>Converted to package.xml 2.0 for pear.horde.org
+ <notes>* Initial Horde 4 package.
  </notes>
  <contents>
   <dir name="/">
@@ -41,7 +40,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <dir name="lib">
     <dir name="Horde">
      <dir name="Scheduler">
-      <file name="cron.php" role="php" />
+      <file name="Cron.php" role="php" />
+      <dir name="Cron">
+       <file name="Date.php" role="php" />
+      </dir> <!-- /lib/Horde/Scheduler/Cron -->
      </dir> <!-- /lib/Horde/Scheduler -->
      <file name="Scheduler.php" role="php" />
     </dir> <!-- /lib/Horde -->
@@ -51,13 +53,13 @@ http://pear.php.net/dtd/package-2.0.xsd">
  <dependencies>
   <required>
    <php>
-    <min>4.0.0</min>
+    <min>5.2.0</min>
    </php>
    <pearinstaller>
-    <min>1.4.0b1</min>
+    <min>1.7.0</min>
    </pearinstaller>
    <package>
-    <name>Horde_Framework</name>
+    <name>Core</name>
     <channel>pear.horde.org</channel>
    </package>
    <package>
@@ -73,12 +75,28 @@ http://pear.php.net/dtd/package-2.0.xsd">
  <phprelease>
   <filelist>
    <install name="scripts/Horde/Scheduler/horde-crond.php" as="horde-crond" />
-   <install name="lib/Horde/Scheduler/cron.php" as="Horde/Scheduler/cron.php" />
+   <install name="lib/Horde/Scheduler/Cron/Date.php" as="Horde/Scheduler/Cron/Date.php" />
+   <install name="lib/Horde/Scheduler/Cron.php" as="Horde/Scheduler/Cron.php" />
    <install name="lib/Horde/Scheduler.php" as="Horde/Scheduler.php" />
   </filelist>
  </phprelease>
  <changelog>
   <release>
+   <date>2006-05-08</date>
+   <time>23:07:47</time>
+   <version>
+    <release>0.0.2</release>
+    <api>0.0.2</api>
+   </version>
+   <stability>
+    <release>alpha</release>
+    <api>alpha</api>
+   </stability>
+   <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
+   <notes>Converted to package.xml 2.0 for pear.horde.org
+   </notes>
+  </release>
+  <release>
    <version>
     <release>0.0.1</release>
     <api>0.0.1</api>
index b5fa87e..e778799 100755 (executable)
@@ -9,20 +9,14 @@
  * @package Horde_Scheduler
  */
 
-require_once 'Horde/Cli.php';
-require_once 'Horde/Scheduler.php';
+// The base file path of horde.
+$horde_base = '/path/to/horde';
 
-// Make sure no one runs this from the web.
-if (!Horde_Cli::runningFromCLI()) {
-    exit("Must be run from the command line\n");
-}
-
-// Load the CLI environment - make sure there's no time limit, init
-// some variables, etc.
-Horde_Cli::init();
+require_once $horde_base . '/lib/Application.php';
+Horde_Registry::appInit('horde', array('authentication' => 'none', 'cli' => true));
 
 // Get an instance of the cron scheduler.
-$daemon = Horde_Scheduler::factory('cron');
+$daemon = Horde_Scheduler::factory('Cron');
 
 // Now add some cron jobs to do, or add parsing to read a config file.
 // $daemon->addTask('ls', '0,5,10,15,20,30,40 * * * *');
diff --git a/whups/lib/Scheduler/Whups.php b/whups/lib/Scheduler/Whups.php
new file mode 100644 (file)
index 0000000..da9d392
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+/**
+ * Horde_Scheduler_whups:: Send reminders for tickets based on the
+ * reminders configuration file.
+ *
+ * @package Horde_Scheduler
+ */
+class Horde_Scheduler_Whups extends Horde_Scheduler
+{
+    protected $_reminders;
+    protected $_runtime;
+    protected $_filestamp = 0;
+
+    public function run()
+    {
+        $this->_runtime = time();
+
+        // See if we need to include the reminders config file.
+        if (filemtime(WHUPS_BASE . '/config/reminders.php') > $this->_filestamp) {
+            $this->_filestamp = $this->_runtime;
+            include WHUPS_BASE . '/config/reminders.php';
+            $this->_reminders = $reminders;
+        }
+
+        foreach ($this->_reminders as $reminder) {
+            $ds = new Horde_Scheduler_Cron_Date($reminder['frequency']);
+            if ($ds->scheduledAt($this->_runtime)) {
+                if (!empty($reminder['server_name'])) {
+                    $GLOBALS['conf']['server']['name'] = $reminder['server_name'];
+                }
+                $vars = new Horde_Variables($reminder);
+                Whups::sendReminders($vars);
+            }
+        }
+    }
+
+}
diff --git a/whups/lib/Scheduler/whups.php b/whups/lib/Scheduler/whups.php
deleted file mode 100644 (file)
index 913e859..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-
-require_once 'Horde/Scheduler/cron.php';
-
-/**
- * Horde_Scheduler_whups:: Send reminders for tickets based on the
- * reminders configuration file.
- *
- * @package Horde_Scheduler
- */
-class Horde_Scheduler_whups extends Horde_Scheduler {
-
-    var $_reminders;
-    var $_runtime;
-    var $_filestamp = 0;
-
-    function Horde_Scheduler_whups($params = array())
-    {
-        parent::Horde_Scheduler($params);
-    }
-
-    function run()
-    {
-        $this->_runtime = time();
-
-        // See if we need to include the reminders config file.
-        if (filemtime(WHUPS_BASE . '/config/reminders.php') > $this->_filestamp) {
-            $this->_filestamp = $this->_runtime;
-            include WHUPS_BASE . '/config/reminders.php';
-            $this->_reminders = $reminders;
-        }
-
-        foreach ($this->_reminders as $reminder) {
-            $ds = new Horde_Scheduler_cronDate($reminder['frequency']);
-            if ($ds->scheduledAt($this->_runtime)) {
-                if (!empty($reminder['server_name'])) {
-                    $GLOBALS['conf']['server']['name'] = $reminder['server_name'];
-                }
-                $vars = new Horde_Variables($reminder);
-                Whups::sendReminders($vars);
-            }
-        }
-    }
-
-}
index 26b6033..a34a9c5 100755 (executable)
@@ -13,8 +13,7 @@ require_once dirname(__FILE__) . '/../lib/Application.php';
 Horde_Registry::appInit('whups', array('authentication' => 'none'));
 
 // Get an instance of the Whups scheduler.
-require_once WHUPS_BASE . '/lib/Scheduler/whups.php';
-$reminder = Horde_Scheduler::unserialize('Horde_Scheduler_whups');
+$reminder = Horde_Scheduler::unserialize('Horde_Scheduler_Whups');
 
 // Check for and send reminders.
 $reminder->run();