ILIAS  release_8 Revision v8.24
class.ilPrgUserNotRestartedCronJob.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
25{
26 private const ID = 'prg_user_not_restarted';
27
29 protected ilLanguage $lng;
32
33 public function __construct()
34 {
35 global $DIC;
36 $this->log = $DIC['ilLog'];
37 $this->lng = $DIC['lng'];
38 $this->lng->loadLanguageModule('prg');
39
41 $this->assignment_repo = $dic['repo.assignment'];
42 $this->adapter = $dic['cron.notRestarted'];
43 }
44
45 public function getTitle(): string
46 {
47 return $this->lng->txt('prg_user_not_restarted_title');
48 }
49
50 public function getDescription(): string
51 {
52 return $this->lng->txt('prg_user_not_restarted_desc');
53 }
54
55 public function getId(): string
56 {
57 return self::ID;
58 }
59
60 public function hasAutoActivation(): bool
61 {
62 return true;
63 }
64
65 public function hasFlexibleSchedule(): bool
66 {
67 return true;
68 }
69
70 public function getDefaultScheduleType(): int
71 {
73 }
74
75 public function getDefaultScheduleValue(): ?int
76 {
77 return 1;
78 }
79
80 public function run(): ilCronJobResult
81 {
82 $result = new ilCronJobResult();
83 $result->setStatus(ilCronJobResult::STATUS_NO_ACTION);
84
85 $programmes_to_send = $this->adapter->getRelevantProgrammeIds();
86 if (count($programmes_to_send) == 0) {
87 return $result;
88 }
89
90 $today = $this->getNow();
91 $programmes_and_due = [];
92 foreach ($programmes_to_send as $programme_obj_id => $days_offset_mail) {
93 $interval = new DateInterval('P' . $days_offset_mail . 'D');
94 $due = $today->add($interval);
95 $programmes_and_due[$programme_obj_id] = $due;
96 }
97
98 $assignments = $this->assignment_repo->getAboutToExpire($programmes_and_due, true);
99
100 if (count($assignments) == 0) {
101 return $result;
102 }
103 foreach ($assignments as $ass) {
104 $pgs = $ass->getProgressTree();
105 $this->log(
106 sprintf(
107 'PRG, UserNotRestarted: user %s\'s qualification is about to expire at assignment %s (prg obj_id %s)',
108 $ass->getUserId(),
109 $ass->getId(),
110 $pgs->getNodeId()
111 )
112 );
113 $this->adapter->actOnSingleAssignment($ass);
114 $this->assignment_repo->storeExpiryInfoSentFor($ass);
115 }
116 $result->setStatus(ilCronJobResult::STATUS_OK);
117 return $result;
118 }
119
120 protected function getNow(): DateTimeImmutable
121 {
122 return new DateTimeImmutable();
123 }
124
125 protected function log(string $msg): void
126 {
127 $this->log->write($msg);
128 }
129}
Component logger with individual log levels by component id.
const SCHEDULE_TYPE_IN_DAYS
@depracated This will be replaced with an ENUM in ILIAS 9
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$dic
Definition: result.php:32