19declare(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;
88 if (
null === $last_run) {
92 if ($this->date_time_provider ===
null) {
93 $now =
new DateTimeImmutable(
'@' . time(),
new DateTimeZone(date_default_timezone_get()));
100 $last = $last_run->format(
'Y-m-d');
101 $ref = $now->format(
'Y-m-d');
102 return ($last !== $ref);
108 $last = $last_run->format(
'Y-n');
109 $ref = $now->format(
'Y-n');
110 return ($last !== $ref);
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);
118 $last = $last_run->format(
'Y');
119 $ref = $now->format(
'Y');
120 return ($last !== $ref);
123 $diff = floor(($now->getTimestamp() - $last_run->getTimestamp()) / 60);
127 $diff = floor(($now->getTimestamp() - $last_run->getTimestamp()) / (60 * 60));
131 $diff = floor(($now->getTimestamp() - $last_run->getTimestamp()) / (60 * 60 * 24));
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)) {
151 throw new InvalidArgumentException(sprintf(
152 'The return type of the datetime provider must be of type %s',
158 $parameters = $r->getParameters();
159 if ($parameters !== []) {
160 throw new InvalidArgumentException(
161 'The datetime provider must not define any parameters',
170 ?DateTimeImmutable $last_run,
173 bool $is_manually_executed =
false
175 if ($is_manually_executed) {
193 if ($this->schedule_type && $this->hasFlexibleSchedule()) {
194 return $this->schedule_type;
206 if ($this->schedule_value && $this->hasFlexibleSchedule()) {
207 return $this->schedule_value;
222 $this->hasFlexibleSchedule() &&
223 in_array($a_type, $this->getValidScheduleTypes(),
true)
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,
266 return $this->getAllScheduleTypes();
304 abstract public function getId(): string;
getScheduleType()
Get current schedule type (if flexible)
const SCHEDULE_TYPE_IN_DAYS
@depracated This will be replaced with an ENUM in ILIAS 9
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...
setDateTimeProvider(?Closure $date_time_provider)
const SCHEDULE_TYPE_IN_HOURS
@depracated This will be replaced with an ENUM in ILIAS 9
getDefaultScheduleValue()
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
saveCustomSettings(ilPropertyFormGUI $a_form)
isDue(?DateTimeImmutable $last_run, ?int $schedule_type, ?int $schedule_value, bool $is_manually_executed=false)
getScheduleTypesWithValues()
const SCHEDULE_TYPE_IN_MINUTES
@depracated This will be replaced with an ENUM in ILIAS 9
setSchedule(?int $a_type, ?int $a_value)
Update current schedule (if flexible)
getScheduleValue()
Get current schedule value (if flexible)
const SCHEDULE_TYPE_WEEKLY
@depracated This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_YEARLY
@depracated This will be replaced with an ENUM in ILIAS 9
checkWeeklySchedule(DateTimeImmutable $last_run, DateTimeImmutable $now)
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
const SCHEDULE_TYPE_DAILY
@depracated This will be replaced with an ENUM in ILIAS 9
Closure $date_time_provider
checkSchedule(?DateTimeImmutable $last_run, ?int $schedule_type, ?int $schedule_value)
const SCHEDULE_TYPE_QUARTERLY
@depracated This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_MONTHLY
@depracated This will be replaced with an ENUM in ILIAS 9
getValidScheduleTypes()
Returns a collection of all valid schedule types for a specific job.
getAllScheduleTypes()
Get all available schedule types.
addToExternalSettingsForm(int $a_form_id, array &$a_fields, bool $a_is_active)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...