19 declare(strict_types=1);
51 $this->
logger = TestDIC::dic()[
'logging.logger'];
52 $this->
lng = $DIC[
'lng'];
53 $this->
user = $DIC[
'ilUser'];
54 $this->
lng->loadLanguageModule(
'assessment');
55 $this->db = $DIC->database();
56 $this->obj_data_cache = $DIC[
'ilObjDataCache'];
58 $this->unfinished_passes = [];
60 $this->test_ending_times = [];
67 $this->test_pass_result_repository = TestDic::dic()[
'results.data.test_result_repository'];
72 return 'finish_unfinished_passes';
77 return $this->
lng->txt(
'finish_unfinished_passes');
82 return $this->
lng->txt(
'finish_unfinished_passes_desc');
87 return CronJobScheduleType::SCHEDULE_TYPE_DAILY;
112 $this->
logger->info(
'start inf cronjob...');
117 if (count($this->unfinished_passes) > 0) {
118 $this->
logger->info(
'found ' . count($this->unfinished_passes) .
' unfinished passes starting analyses.');
122 $this->
logger->info(
'No unfinished passes found.');
127 $this->
logger->info(
' ...finishing cronjob.');
135 SELECT tst_active.active_id, 137 tst_active.user_fi usr_id, 138 tst_active.test_fi test_fi, 142 tst_active.submitted test_finished, 143 usr_data.matriculation, 145 tst_active.lastindex, 146 tst_active.last_started_pass last_started 149 ON tst_active.user_fi = usr_data.usr_id 150 WHERE IFNULL(tst_active.last_finished_pass, -1) <> tst_active.last_started_pass 152 $result = $this->db->query($query);
153 while ($row = $this->db->fetchAssoc($result)) {
154 $this->unfinished_passes[] = $row;
155 $this->test_ids[] = $row[
'test_fi'];
161 $query =
'SELECT test_id, obj_fi, ending_time, ending_time_enabled, processing_time, enable_processing_time FROM tst_tests WHERE ' .
162 $this->db->in(
'test_id', $this->test_ids,
false,
'integer');
163 $result = $this->db->query($query);
164 while ($row = $this->db->fetchAssoc($result)) {
165 $this->test_ending_times[$row[
'test_id']] = $row;
167 $this->
logger->info(
'Gathered data for ' . count($this->test_ids) .
' test id(s) => (' . implode(
',', $this->test_ids) .
')');
172 foreach ($this->unfinished_passes as
$data) {
173 $test_id = $data[
'test_fi'];
174 if (!array_key_exists($test_id, $this->test_ending_times)) {
184 $this->
logger->info(
'Test session with active id (' 185 . $data[
'active_id'] .
') can not be finished by this cron job.');
194 if ($this->test_ending_times[$test_id][
'ending_time_enabled'] !== 1) {
195 $this->
logger->info(
'Test (' . $test_id .
') has no ending time.');
199 $this->
logger->info(
'Test (' . $test_id .
') has ending time (' 200 . $this->test_ending_times[$test_id][
'ending_time'] .
')');
201 $ending_time = $this->test_ending_times[$test_id][
'ending_time'];
202 if ($ending_time >= $now) {
203 $this->
logger->info(
'Test (' . $test_id .
') ending time (' 204 . $this->test_ending_times[$test_id][
'ending_time']
205 .
') > now (' . $now .
') is not reached.');
209 $this->
finishPassForUser($active_id, $this->test_ending_times[$test_id][
'obj_fi']);
218 if ($this->test_ending_times[$test_id][
'enable_processing_time'] !== 1) {
219 $this->
logger->info(
'Test (' . $test_id .
') has no processing time.');
223 $this->
logger->info(
'Test (' . $test_id .
') has processing time (' . $this->test_ending_times[$test_id][
'processing_time'] .
')');
224 $obj_id = $this->test_ending_times[$test_id][
'obj_fi'];
227 $this->
logger->info(
'Test object with id (' . $obj_id .
') does not exist.');
231 $test_obj =
new ilObjTest($obj_id,
false);
232 $startingTime = $test_obj->getStartingTimeOfUser($active_id);
233 $max_processing_time = $test_obj->isMaxProcessingTimeReached($startingTime, $active_id);
234 if (!$max_processing_time) {
235 $this->
logger->info(
'Max Processing time not reached for user id (' 236 . $usr_id .
') in test with active id (' 237 . $active_id .
'). Starting time: ' . $startingTime
238 .
' Processing time: ' . $test_obj->getProcessingTime() .
' / ' 239 . $test_obj->getProcessingTimeInSeconds() .
's');
243 $this->
logger->info(
'Max Processing time reached for user id (' 244 . $usr_id .
') so test with active id (' 245 . $active_id .
') will be finished.');
246 $this->
finishPassForUser($active_id, $this->test_ending_times[$test_id][
'obj_fi']);
252 $processLocker = $this->processLockerFactory->withContextId((
int) $active_id)->getLocker();
255 $test_session->loadFromDb($active_id);
260 $test->updateTestPassResults(
262 $test_session->getPass(),
270 $this->test_pass_result_repository
271 ))->performFinishTasks($processLocker, StatusOfAttempt::FINISHED_BY_CRONJOB);
272 $this->
logger->info(
'Test session with active id (' . $active_id .
') and obj_id (' . $obj_id .
') is now finished.');
274 $this->
logger->info(
'Test object with id (' . $obj_id .
') does not exist.');
readonly ilObjectDataCache $obj_data_cache
Class ilTestPassFinishTasks.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
TestResultRepository $test_pass_result_repository
finishPassOnEndingTime(int $test_id, int $active_id)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
gatherUsersWithUnfinishedPasses()
readonly TestLogger $logger
getDefaultScheduleValue()
Class ilCronFinishUnfinishedTestPasses.
finishPassForUser($active_id, $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
readonly ilDBInterface $db
finishPassOnProcessingTime(int $test_id, int $usr_id, int $active_id)
getTestsFinishAndProcessingTime()
ilTestProcessLockerFactory $processLockerFactory