19declare(strict_types=1);
53 $this->
logger = TestDIC::dic()[
'logging.logger'];
54 $this->
lng = $DIC[
'lng'];
55 $this->
user = $DIC[
'ilUser'];
56 $this->
lng->loadLanguageModule(
'assessment');
57 $this->db =
$DIC->database();
58 $this->obj_data_cache =
$DIC[
'ilObjDataCache'];
60 $this->unfinished_passes = [];
62 $this->test_ending_times = [];
70 $this->test_result_repository = TestDic::dic()[
'results.data.repository'];
75 return 'finish_unfinished_passes';
80 return $this->
lng->txt(
'finish_unfinished_passes');
85 return $this->
lng->txt(
'finish_unfinished_passes_desc');
90 return JobScheduleType::DAILY;
115 $this->
logger->info(
'start inf cronjob...');
120 if (count($this->unfinished_passes) > 0) {
121 $this->
logger->info(
'found ' . count($this->unfinished_passes) .
' unfinished passes starting analyses.');
125 $this->
logger->info(
'No unfinished passes found.');
128 $result->setStatus(JobResult::STATUS_OK);
130 $this->
logger->info(
' ...finishing cronjob.');
138 SELECT tst_active.active_id,
140 tst_active.user_fi usr_id,
141 tst_active.test_fi test_fi,
145 tst_active.submitted test_finished,
146 usr_data.matriculation,
148 tst_active.lastindex,
149 tst_active.last_started_pass last_started
152 ON tst_active.user_fi = usr_data.usr_id
153 WHERE IFNULL(tst_active.last_finished_pass, -1) <> tst_active.last_started_pass
155 $result = $this->db->query($query);
156 while ($row = $this->db->fetchAssoc($result)) {
157 $this->unfinished_passes[] = $row;
158 $this->test_ids[] = $row[
'test_fi'];
164 $query =
"SELECT test_id, obj_fi,
165 tst_set.ending_time, tst_set.ending_time_enabled, tst_set.processing_time, tst_set.enable_processing_time
166 FROM tst_tests INNER JOIN tst_test_settings AS tst_set ON tst_tests.settings_id = tst_set.id WHERE " .
169 $result = $this->db->query($query);
170 while ($row = $this->db->fetchAssoc($result)) {
171 $this->test_ending_times[$row[
'test_id']] = $row;
173 $this->
logger->info(
'Gathered data for ' . count($this->test_ids) .
' test id(s) => (' . implode(
',', $this->test_ids) .
')');
178 foreach ($this->unfinished_passes as
$data) {
179 $test_id =
$data[
'test_fi'];
180 if (!array_key_exists($test_id, $this->test_ending_times)) {
190 $this->
logger->info(
'Test session with active id ('
191 . $data[
'active_id'] .
') can not be finished by this cron job.');
200 if ($this->test_ending_times[$test_id][
'ending_time_enabled'] !== 1) {
201 $this->
logger->info(
'Test (' . $test_id .
') has no ending time.');
205 $this->
logger->info(
'Test (' . $test_id .
') has ending time ('
206 . $this->test_ending_times[$test_id][
'ending_time'] .
')');
207 $ending_time = $this->test_ending_times[$test_id][
'ending_time'];
208 if ($ending_time >=
$now) {
209 $this->
logger->info(
'Test (' . $test_id .
') ending time ('
210 . $this->test_ending_times[$test_id][
'ending_time']
211 .
') > now (' .
$now .
') is not reached.');
215 $this->
finishPassForUser($active_id, $this->test_ending_times[$test_id][
'obj_fi']);
224 if ($this->test_ending_times[$test_id][
'enable_processing_time'] !== 1) {
225 $this->
logger->info(
'Test (' . $test_id .
') has no processing time.');
229 $this->
logger->info(
'Test (' . $test_id .
') has processing time (' . $this->test_ending_times[$test_id][
'processing_time'] .
')');
230 $obj_id = $this->test_ending_times[$test_id][
'obj_fi'];
233 $this->
logger->info(
'Test object with id (' . $obj_id .
') does not exist.');
237 $test_obj =
new ilObjTest($obj_id,
false);
238 $startingTime = $test_obj->getStartingTimeOfUser($active_id);
239 $max_processing_time = $test_obj->isMaxProcessingTimeReached($startingTime, $active_id);
240 if (!$max_processing_time) {
241 $this->
logger->info(
'Max Processing time not reached for user id ('
242 . $usr_id .
') in test with active id ('
243 . $active_id .
'). Starting time: ' . $startingTime
244 .
' Processing time: ' . $test_obj->getProcessingTime() .
' / '
245 . $test_obj->getProcessingTimeInSeconds() .
's');
249 $this->
logger->info(
'Max Processing time reached for user id ('
250 . $usr_id .
') so test with active id ('
251 . $active_id .
') will be finished.');
252 $this->
finishPassForUser($active_id, $this->test_ending_times[$test_id][
'obj_fi']);
258 $processLocker = $this->processLockerFactory->withContextId((
int) $active_id)->getLocker();
261 $test_session->loadFromDb($active_id);
264 $this->test_result_repository->updateTestAttemptResult(
266 $test_session->getPass(),
274 $this->test_result_repository
275 ))->performFinishTasks($processLocker, StatusOfAttempt::FINISHED_BY_CRONJOB);
276 $this->
logger->info(
'Test session with active id (' . $active_id .
') and obj_id (' . $obj_id .
') is now finished.');
278 $this->
logger->info(
'Test object with id (' . $obj_id .
') does not exist.');
Class ilCronFinishUnfinishedTestPasses.
readonly ilObjectDataCache $obj_data_cache
gatherUsersWithUnfinishedPasses()
getDefaultScheduleValue()
ilTestProcessLockerFactory $processLockerFactory
TestResultRepository $test_result_repository
readonly ilDBInterface $db
finishPassOnProcessingTime(int $test_id, int $usr_id, int $active_id)
getTestsFinishAndProcessingTime()
readonly TestLogger $logger
finishPassForUser($active_id, $obj_id)
finishPassOnEndingTime(int $test_id, int $active_id)
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
Class ilTestPassFinishTasks.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
if(!file_exists('../ilias.ini.php'))