Exemplo n.º 1
0
 /**
  * Tests invalid call to setDay on Weekly
  */
 public function testSetDayScheduledTimeWeeklyOver7()
 {
     try {
         $weeklySchedule = new Weekly();
         $weeklySchedule->setDay(8);
     } catch (Exception $e) {
         return;
     }
     $this->fail('Expected exception not raised');
 }
 /**
  * Constructor.
  */
 public function __construct()
 {
     $schedulePeriodStr = self::getSchedulePeriod();
     // created the scheduledtime instance, also, since GeoIP updates are done on tuesdays,
     // get new DBs on Wednesday
     switch ($schedulePeriodStr) {
         case self::SCHEDULE_PERIOD_WEEKLY:
             $schedulePeriod = new Weekly();
             $schedulePeriod->setDay(3);
             break;
         case self::SCHEDULE_PERIOD_MONTHLY:
         default:
             $schedulePeriod = new Monthly();
             $schedulePeriod->setDayOfWeek(3, 0);
             break;
     }
     parent::__construct($this, 'update', null, $schedulePeriod, ScheduledTask::LOWEST_PRIORITY);
 }
Exemplo n.º 3
0
 public function setDayOfWeekFromString($day)
 {
     @(list($weekNumberString, $dayNumberString) = explode(' ', $day));
     // get day number
     $day = Weekly::getDayIntFromString($dayNumberString) % 7;
     // get week number
     $weekNumberString = strtolower($weekNumberString);
     if (isset(self::$weekNumberStringToInt[$weekNumberString])) {
         $week = self::$weekNumberStringToInt[$weekNumberString];
     } else {
         throw new Exception("Invalid week describer in ScheduledTime\\Monthly::setDayOfWeekFromString: '{$weekNumberString}'. " . "Supported values are 'first', 'second', 'third', 'fourth'.");
     }
     $this->setDayOfWeek($day, $week);
 }
Exemplo n.º 4
0
 /**
  * Returns a new ScheduledTime instance using a string description of the scheduled period type
  * and a string description of the day within the period to execute the task on.
  * 
  * @param string $periodType The scheduled period type. Can be `'hourly'`, `'daily'`, `'weekly'`, or `'monthly'`.
  * @param string|int|false $periodDay A string describing the day within the scheduled period to execute
  *                                    the task on. Only valid for week and month periods.
  *                               
  *                                    If `'weekly'` is supplied for `$periodType`, this should be a day
  *                                    of the week, for example, `'monday'` or `'tuesday'`.
  * 
  *                                    If `'monthly'` is supplied for `$periodType`, this can be a numeric
  *                                    day in the month or a day in one week of the month. For example,
  *                                    `12`, `23`, `'first sunday'` or `'fourth tuesday'`.
  * @api
  */
 public static function factory($periodType, $periodDay = false)
 {
     switch ($periodType) {
         case 'hourly':
             return new Hourly();
         case 'daily':
             return new Daily();
         case 'weekly':
             $result = new Weekly();
             if ($periodDay !== false) {
                 $result->setDay($periodDay);
             }
             return $result;
         case 'monthly':
             $result = new Monthly($periodDay);
             if ($periodDay !== false) {
                 if (is_int($periodDay)) {
                     $result->setDay($periodDay);
                 } else {
                     $result->setDayOfWeekFromString($periodDay);
                 }
             }
             return $result;
         default:
             throw new Exception("Unsupported scheduled period type: '{$periodType}'. Supported values are" . " 'hourly', 'daily', 'weekly' or 'monthly'.");
     }
 }