19 declare(strict_types=1);
39 if (str_starts_with($id,
'pl__')) {
40 $parts = explode(
'__', $id);
44 foreach ($this->componentRepository->getPlugins() as $pl) {
45 if ($pl->getName() !== $pl_name || !$pl->isActive()) {
49 $plugin = $this->componentFactory->getPlugin($pl->getId());
55 $job =
$plugin->getCronJobInstance($job_id);
59 if ($jobs_data === []) {
72 if ($jobs_data !== [] && $jobs_data[0][
'job_id'] === $id) {
74 $jobs_data[0][
'job_id'],
75 $jobs_data[0][
'component'],
76 $jobs_data[0][
'class']
81 $this->
logger->info(
'CRON - job ' . $id .
' seems invalid or is inactive');
90 bool $isCreationContext =
false 92 if (class_exists($a_class)) {
93 if ($isCreationContext) {
95 $job = $refl->newInstanceWithoutConstructor();
97 $job =
new $a_class();
112 if (
$id && !is_array(
$id)) {
116 $query =
"SELECT * FROM cron_job";
123 if (!$withInactiveJobsIncluded) {
127 $query .=
' WHERE ' . implode(
' AND ', $where);
130 $query .=
' ORDER BY job_id';
132 $res = $this->db->query($query);
133 while ($row = $this->db->fetchAssoc(
$res)) {
146 if (!$this->db->tableExists(
'cron_job')) {
150 $job = $this->
getJobInstance($a_id, $a_component, $a_class,
true);
156 public function unregisterJob(
string $a_component, array $a_xml_job_ids): void
158 if (!$this->db->tableExists(
'cron_job')) {
163 $query =
'SELECT job_id FROM cron_job WHERE component = ' . $this->db->quote($a_component,
'text');
164 $res = $this->db->query($query);
165 while ($row = $this->db->fetchAssoc(
$res)) {
166 $jobs[] = $row[
'job_id'];
170 if ($a_xml_job_ids !== []) {
171 foreach ($jobs as $job_id) {
172 if (!in_array($job_id, $a_xml_job_ids,
true)) {
173 $this->db->manipulate(
174 'DELETE FROM cron_job' .
175 ' WHERE component = ' . $this->db->quote($a_component,
'text') .
176 ' AND job_id = ' . $this->db->quote($job_id,
'text')
181 $this->db->manipulate(
182 'DELETE FROM cron_job WHERE component = ' . $this->db->quote($a_component,
'text')
194 $query =
"SELECT job_id, schedule_type, component, class, path FROM cron_job" .
195 " WHERE job_id = " . $this->db->quote($job->
getId(),
"text");
196 $res = $this->db->query($query);
197 $row = $this->db->fetchAssoc(
$res);
198 $job_id = $row[
'job_id'] ?? null;
199 $job_exists = ($job_id === $job->
getId());
200 $schedule_type_value = $row[
'schedule_type'] ?? null;
201 $schedule_type = is_numeric($schedule_type_value) ? CronJobScheduleType::tryFrom((
int) $schedule_type_value) : null;
205 $row[
'component'] !== $component ||
206 $row[
'class'] !== $class ||
207 $row[
'path'] !== $path
210 $this->db->manipulateF(
211 'UPDATE cron_job SET component = %s, class = %s, path = %s WHERE job_id = %s',
212 [
'text',
'text',
'text',
'text'],
213 [$component, $class, $path, $job->
getId()]
219 $query =
'INSERT INTO cron_job (job_id, component, class, path)' .
220 ' VALUES (' . $this->db->quote($job->
getId(),
'text') .
', ' .
221 $this->db->quote($component,
'text') .
', ' .
222 $this->db->quote($class,
'text') .
', ' .
223 $this->db->quote($path,
'text') .
')';
224 $this->db->manipulate($query);
226 $this->
logger->info(
'Cron XML - Job ' . $job->
getId() .
' in class ' . $class .
' added.');
261 foreach ($this->componentRepository->getPlugins() as $pl) {
262 if (!$pl->isActive()) {
266 $plugin = $this->componentFactory->getPlugin($pl->getId());
272 foreach (
$plugin->getCronJobInstances() as $job) {
274 $job_data = $jobs_data[0] ?? null;
275 if (!is_array($job_data) || $job_data === []) {
281 $job_data = $jobs_data[0];
284 if (!$withOnlyActive || (
int) $job_data[
'job_status'] === 1) {
285 $res[$job->getId()] = [$job, $job_data];
295 $this->db->manipulate(
297 ' SET running_ts = ' . $this->db->quote(0,
'integer') .
298 ' , alive_ts = ' . $this->db->quote(0,
'integer') .
299 ' , job_result_ts = ' . $this->db->quote(0,
'integer') .
300 ' WHERE job_id = ' . $this->db->quote($job->
getId(),
'text')
309 bool $wasManualExecution =
false 311 $user_id = $wasManualExecution ? $actor->
getId() : 0;
313 $query =
'UPDATE cron_job SET ' .
314 ' job_result_status = ' . $this->db->quote($result->
getStatus(),
'integer') .
315 ' , job_result_user_id = ' . $this->db->quote($user_id,
'integer') .
316 ' , job_result_code = ' . $this->db->quote($result->
getCode(),
'text') .
317 ' , job_result_message = ' . $this->db->quote($result->
getMessage(),
'text') .
318 ' , job_result_type = ' . $this->db->quote((
int) $wasManualExecution,
'integer') .
319 ' , job_result_ts = ' . $this->db->quote($when->getTimestamp(),
'integer') .
320 ' , job_result_dur = ' . $this->db->quote($result->
getDuration() * 1000,
'integer') .
321 ' WHERE job_id = ' . $this->db->quote($job->
getId(),
'text');
322 $this->db->manipulate($query);
327 $this->db->manipulate(
328 'UPDATE cron_job SET' .
329 ' running_ts = ' . $this->db->quote($runningTimestamp,
'integer') .
330 ' , alive_ts = ' . $this->db->quote($aliveTimestamp,
'integer') .
331 ' WHERE job_id = ' . $this->db->quote($jobId,
'text')
338 $scheduleType === null ||
341 $query =
'UPDATE cron_job SET ' .
342 ' schedule_type = ' . $this->db->quote($scheduleType?->value,
'integer') .
343 ' , schedule_value = ' . $this->db->quote($scheduleValue,
'integer') .
344 ' WHERE job_id = ' . $this->db->quote($job->
getId(),
'text');
345 $this->db->manipulate($query);
353 bool $wasManuallyExecuted =
false 356 if ($wasManuallyExecuted && $actor instanceof
ilObjUser) {
357 $usrId = $actor->getId();
360 $query =
'UPDATE cron_job SET ' .
361 ' job_status = ' . $this->db->quote(1,
'integer') .
362 ' , job_status_user_id = ' . $this->db->quote($usrId,
'integer') .
363 ' , job_status_type = ' . $this->db->quote($wasManuallyExecuted,
'integer') .
364 ' , job_status_ts = ' . $this->db->quote($when->getTimestamp(),
'integer') .
365 ' WHERE job_id = ' . $this->db->quote($job->
getId(),
'text');
366 $this->db->manipulate($query);
373 bool $wasManuallyExecuted =
false 375 $usrId = $wasManuallyExecuted ? $actor->
getId() : 0;
377 $query =
'UPDATE cron_job SET ' .
378 ' job_status = ' . $this->db->quote(0,
'integer') .
379 ' , job_result_status = ' . $this->db->quote(null,
'text') .
380 ' , job_result_message = ' . $this->db->quote(null,
'text') .
381 ' , job_result_type = ' . $this->db->quote(null,
'text') .
382 ' , job_result_code = ' . $this->db->quote(null,
'text') .
383 ' , job_status_user_id = ' . $this->db->quote($usrId,
'integer') .
384 ' , job_status_type = ' . $this->db->quote($wasManuallyExecuted,
'integer') .
385 ' , job_status_ts = ' . $this->db->quote($when->getTimestamp(),
'integer') .
386 ' WHERE job_id = ' . $this->db->quote($job->
getId(),
'text');
387 $this->db->manipulate($query);
Readable part of repository interface to ilComponentDataDB.
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
updateJobSchedule(ilCronJob $job, ?CronJobScheduleType $scheduleType, ?int $scheduleValue)
updateJobResult(ilCronJob $job, DateTimeImmutable $when, ilObjUser $actor, ilCronJobResult $result, bool $wasManualExecution=false)
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
unregisterJob(string $a_component, array $a_xml_job_ids)
getPluginJobs(bool $withOnlyActive=false)
getCronJobData($id=null, bool $withInactiveJobsIncluded=true)
Get cron job configuration/execution data.
activateJob(ilCronJob $job, DateTimeImmutable $when, ?ilObjUser $actor=null, bool $wasManuallyExecuted=false)
registerJob(string $a_component, string $a_id, string $a_class, ?string $a_path)
__construct(private readonly ilDBInterface $db, private readonly ilSetting $setting, private readonly ilLogger $logger, private readonly ilComponentRepository $componentRepository, private readonly ilComponentFactory $componentFactory)
deactivateJob(ilCronJob $job, DateTimeImmutable $when, ilObjUser $actor, bool $wasManuallyExecuted=false)
updateRunInformation(string $jobId, int $runningTimestamp, int $aliveTimestamp)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
getDefaultScheduleValue()
getJobInstance(string $a_id, string $a_component, string $a_class, bool $isCreationContext=false)
getJobInstanceById(string $id)
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
createDefaultEntry(ilCronJob $job, string $component, string $class, ?string $path)