19 declare(strict_types=1);
46 $last_year = (
int) $last_run->format(
'Y');
47 $now_year = (
int) $now->format(
'Y');
49 if ($last_year > $now_year) {
54 $last_week = $last_run->format(
'W');
55 $now_week = $now->format(
'W');
57 if ($last_week !== $now_week) {
64 $last_month = (
int) $last_run->format(
'm');
65 $now_month = (
int) $now->format(
'm');
67 $is_within_same_week_in_same_year = ($last_year .
'-' . $last_week) === ($now_year .
'-' . $now_week);
68 if ($is_within_same_week_in_same_year) {
70 return $last_month !== $now_month && $now->diff($last_run)->d > 7;
73 if ($now_year - $last_year > 1) {
79 return $last_month === $now_month;
84 if (null === $schedule_type) {
88 if (null === $last_run) {
92 if ($this->date_time_provider === null) {
98 switch ($schedule_type) {
99 case self::SCHEDULE_TYPE_DAILY:
100 $last = $last_run->format(
'Y-m-d');
101 $ref = $now->format(
'Y-m-d');
102 return ($last !== $ref);
104 case self::SCHEDULE_TYPE_WEEKLY:
107 case self::SCHEDULE_TYPE_MONTHLY:
108 $last = $last_run->format(
'Y-n');
109 $ref = $now->format(
'Y-n');
110 return ($last !== $ref);
112 case self::SCHEDULE_TYPE_QUARTERLY:
113 $last = $last_run->format(
'Y') .
'-' . ceil(((
int) $last_run->format(
'n')) / 3);
114 $ref = $now->format(
'Y') .
'-' . ceil(((
int) $now->format(
'n')) / 3);
115 return ($last !== $ref);
117 case self::SCHEDULE_TYPE_YEARLY:
118 $last = $last_run->format(
'Y');
119 $ref = $now->format(
'Y');
120 return ($last !== $ref);
122 case self::SCHEDULE_TYPE_IN_MINUTES:
123 $diff = floor(($now->getTimestamp() - $last_run->getTimestamp()) / 60);
124 return ($diff >= $schedule_value);
126 case self::SCHEDULE_TYPE_IN_HOURS:
127 $diff = floor(($now->getTimestamp() - $last_run->getTimestamp()) / (60 * 60));
128 return ($diff >= $schedule_value);
130 case self::SCHEDULE_TYPE_IN_DAYS:
131 $diff = floor(($now->getTimestamp() - $last_run->getTimestamp()) / (60 * 60 * 24));
132 return ($diff >= $schedule_value);
143 if ($date_time_provider !== null) {
145 $return_type = $r->getReturnType();
146 if ($return_type !== null) {
147 $return_type = $return_type->getName();
149 $expected_type = DateTimeInterface::class;
150 if (!is_subclass_of($return_type, $expected_type)) {
152 'The return type of the datetime provider must be of type %s',
158 $parameters = $r->getParameters();
159 if ($parameters !== []) {
161 'The datetime provider must not define any parameters',
172 ?
int $schedule_value,
173 bool $is_manually_executed =
false 175 if ($is_manually_executed) {
184 return $this->
checkSchedule($last_run, $schedule_type, $schedule_value);
225 $this->schedule_type = $a_type;
226 $this->schedule_value = $a_value;
237 self::SCHEDULE_TYPE_DAILY,
238 self::SCHEDULE_TYPE_WEEKLY,
239 self::SCHEDULE_TYPE_MONTHLY,
240 self::SCHEDULE_TYPE_QUARTERLY,
241 self::SCHEDULE_TYPE_YEARLY,
242 self::SCHEDULE_TYPE_IN_MINUTES,
243 self::SCHEDULE_TYPE_IN_HOURS,
244 self::SCHEDULE_TYPE_IN_DAYS,
254 self::SCHEDULE_TYPE_IN_MINUTES,
255 self::SCHEDULE_TYPE_IN_HOURS,
256 self::SCHEDULE_TYPE_IN_DAYS,
304 abstract public function getId(): string;
306 abstract public function getTitle(): string;
activationWasToggled(ilDBInterface $db, ilSetting $setting, bool $a_currently_active)
Important: This method is (also) called from the setup process, where the constructor of an ilCronJob...
getValidScheduleTypes()
Returns a collection of all valid schedule types for a specific job.
setDateTimeProvider(?Closure $date_time_provider)
getAllScheduleTypes()
Get all available schedule types.
setSchedule(?int $a_type, ?int $a_value)
Update current schedule (if flexible)
const SCHEDULE_TYPE_IN_MINUTES
This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_MONTHLY
This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_WEEKLY
This will be replaced with an ENUM in ILIAS 9
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
const SCHEDULE_TYPE_IN_DAYS
This will be replaced with an ENUM in ILIAS 9
addToExternalSettingsForm(int $a_form_id, array &$a_fields, bool $a_is_active)
getScheduleTypesWithValues()
const SCHEDULE_TYPE_YEARLY
This will be replaced with an ENUM in ILIAS 9
Closure $date_time_provider
const SCHEDULE_TYPE_DAILY
This will be replaced with an ENUM in ILIAS 9
getDefaultScheduleValue()
saveCustomSettings(ilPropertyFormGUI $a_form)
const SCHEDULE_TYPE_QUARTERLY
This will be replaced with an ENUM in ILIAS 9
getScheduleValue()
Get current schedule value (if flexible)
const SCHEDULE_TYPE_IN_HOURS
This will be replaced with an ENUM in ILIAS 9
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
checkSchedule(?DateTimeImmutable $last_run, ?int $schedule_type, ?int $schedule_value)
getScheduleType()
Get current schedule type (if flexible)
isDue(?DateTimeImmutable $last_run, ?int $schedule_type, ?int $schedule_value, bool $is_manually_executed=false)
checkWeeklySchedule(DateTimeImmutable $last_run, DateTimeImmutable $now)