/** * 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, Task::LOWEST_PRIORITY); }
/** * Returns a new Schedule 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 bool|false|int|string $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'`. * @return Hourly|Daily|Weekly|Monthly * @throws Exception * @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'."); } }