19 declare(strict_types=1);
34 if ($last_run > $now) {
40 return $last_run->format(
'o-W') !== $now->format(
'o-W');
48 if (
null === $schedule_type) {
52 if (
null === $last_run) {
56 if ($this->date_time_provider ===
null) {
57 $now = new \DateTimeImmutable(
'@' . time(),
new \
DateTimeZone(date_default_timezone_get()));
62 switch ($schedule_type) {
63 case JobScheduleType::DAILY:
64 $last = $last_run->format(
'Y-m-d');
65 $ref = $now->format(
'Y-m-d');
66 return ($last !== $ref);
68 case JobScheduleType::WEEKLY:
71 case JobScheduleType::MONTHLY:
72 $last = $last_run->format(
'Y-n');
73 $ref = $now->format(
'Y-n');
74 return ($last !== $ref);
76 case JobScheduleType::QUARTERLY:
77 $last = $last_run->format(
'Y') .
'-' . ceil(((
int) $last_run->format(
'n')) / 3);
78 $ref = $now->format(
'Y') .
'-' . ceil(((
int) $now->format(
'n')) / 3);
79 return ($last !== $ref);
82 $last = $last_run->format(
'Y');
83 $ref = $now->format(
'Y');
84 return ($last !== $ref);
86 case JobScheduleType::IN_MINUTES:
87 $diff = floor(($now->getTimestamp() - $last_run->getTimestamp()) / 60);
88 return ($diff >= $schedule_value);
90 case JobScheduleType::IN_HOURS:
91 $diff = floor(($now->getTimestamp() - $last_run->getTimestamp()) / (60 * 60));
92 return ($diff >= $schedule_value);
94 case JobScheduleType::IN_DAYS:
95 $diff = floor(($now->getTimestamp() - $last_run->getTimestamp()) / (60 * 60 * 24));
96 return ($diff >= $schedule_value);
107 if ($date_time_provider !==
null) {
108 $r = new \ReflectionFunction($date_time_provider);
109 $return_type =
$r->getReturnType();
110 if ($return_type instanceof \ReflectionNamedType) {
111 $return_type = $return_type->getName();
113 $expected_type = \DateTimeInterface::class;
114 if (!is_subclass_of($return_type, $expected_type)) {
115 throw new \InvalidArgumentException(
117 'The return type of the datetime provider must be of type %s',
123 $r = new \ReflectionFunction($date_time_provider);
124 $parameters =
$r->getParameters();
125 if ($parameters !== []) {
126 throw new \InvalidArgumentException(
127 'The datetime provider must not define any parameters',
138 ?
int $schedule_value,
139 bool $is_manually_executed =
false 141 if ($is_manually_executed) {
150 return $this->
checkSchedule($last_run, $schedule_type, $schedule_value);
187 $this->schedule_type = $a_type;
188 $this->schedule_value = $a_value;
198 return JobScheduleType::cases();
207 JobScheduleType::IN_MINUTES,
208 JobScheduleType::IN_HOURS,
209 JobScheduleType::IN_DAYS,
235 #[\Deprecated('Will be removed without any alternative, KS/UI forms will be expected', since: '13.0')] 246 throw new \RuntimeException(
'Not implemented');
252 #[\Deprecated('Will be removed without any alternative, KS/UI forms will be expected', since: '13.0')] 264 throw new \RuntimeException(
'Not implemented');
270 #[\Deprecated('Will be removed without any alternative, KS/UI forms will be expected', since: '13.0')] 291 abstract public function getId(): string;
293 abstract public function getTitle(): string;
308 abstract public function run(): JobResult;
JobScheduleType $schedule_type
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...
getScheduleType()
Get current schedule type (if flexible)
checkWeeklySchedule(\DateTimeImmutable $last_run, \DateTimeImmutable $now)
Interface Observer Contains several chained tasks and infos about them.
isDue(?\DateTimeImmutable $last_run, ?JobScheduleType $schedule_type, ?int $schedule_value, bool $is_manually_executed=false)
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
saveCustomConfiguration(mixed $form_data)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
addToExternalSettingsForm(int $a_form_id, array &$a_fields, bool $a_is_active)
getCustomConfigurationInput(\ILIAS\UI\Factory $ui_factory, \ILIAS\Refinery\Factory $factory, \ilLanguage $lng)
setSchedule(?JobScheduleType $a_type, ?int $a_value)
Update current schedule (if flexible)
addCustomSettingsToForm(\ilPropertyFormGUI $a_form)
getDefaultScheduleValue()
getScheduleValue()
Get current schedule value (if flexible)
saveCustomSettings(\ilPropertyFormGUI $a_form)
getValidScheduleTypes()
Returns a collection of all valid schedule types for a specific job.
setDateTimeProvider(?\Closure $date_time_provider)
Closure $date_time_provider
getScheduleTypesWithValues()
getAllScheduleTypes()
Get all available schedule types.
checkSchedule(?\DateTimeImmutable $last_run, ?JobScheduleType $schedule_type, ?int $schedule_value)