ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ilCronFinishUnfinishedTestPasses Class Reference

Class ilCronFinishUnfinishedTestPasses. More...

+ Inheritance diagram for ilCronFinishUnfinishedTestPasses:
+ Collaboration diagram for ilCronFinishUnfinishedTestPasses:

Public Member Functions

 getId ()
 
 getTitle ()
 
 getDescription ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 hasAutoActivation ()
 Is to be activated on "installation", does only work for ILIAS core cron jobs. More...
 
 hasFlexibleSchedule ()
 
 hasCustomSettings ()
 
 run ()
 
- Public Member Functions inherited from ILIAS\Cron\CronJob
 setDateTimeProvider (?\Closure $date_time_provider)
 
 isDue (?\DateTimeImmutable $last_run, ?JobScheduleType $schedule_type, ?int $schedule_value, bool $is_manually_executed=false)
 
 getScheduleType ()
 Get current schedule type (if flexible) More...
 
 getScheduleValue ()
 Get current schedule value (if flexible) More...
 
 setSchedule (?JobScheduleType $a_type, ?int $a_value)
 Update current schedule (if flexible) More...
 
 getAllScheduleTypes ()
 Get all available schedule types. More...
 
 getScheduleTypesWithValues ()
 
 getValidScheduleTypes ()
 Returns a collection of all valid schedule types for a specific job. More...
 
 isManuallyExecutable ()
 
 hasCustomSettings ()
 
 usesLegacyForms ()
 
 getCustomConfigurationInput (\ILIAS\UI\Factory $ui_factory, \ILIAS\Refinery\Factory $factory, \ilLanguage $lng)
 
 addCustomSettingsToForm (\ilPropertyFormGUI $a_form)
 
 saveCustomConfiguration (mixed $form_data)
 
 saveCustomSettings (\ilPropertyFormGUI $a_form)
 
 addToExternalSettingsForm (int $a_form_id, array &$a_fields, bool $a_is_active)
 
 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 ist NOT executed. More...
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 hasAutoActivation ()
 Is to be activated on "installation", does only work for ILIAS core cron jobs. More...
 
 hasFlexibleSchedule ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 run ()
 

Protected Member Functions

 gatherUsersWithUnfinishedPasses ()
 
 getTestsFinishAndProcessingTime ()
 
 processPasses ()
 
 finishPassForUser ($active_id, $obj_id)
 

Protected Attributes

readonly TestLogger $logger
 
readonly ilLanguage $lng
 
readonly ilDBInterface $db
 
readonly ilObjUser $user
 
readonly ilObjectDataCache $obj_data_cache
 
int $now
 
array $unfinished_passes
 
array $test_ids
 
array $test_ending_times
 
ilTestProcessLockerFactory $processLockerFactory
 
TestResultRepository $test_result_repository
 
- Protected Attributes inherited from ILIAS\Cron\CronJob
JobScheduleType $schedule_type = null
 
int $schedule_value = null
 
Closure $date_time_provider = null
 

Private Member Functions

 finishPassOnEndingTime (int $test_id, int $active_id)
 
 finishPassOnProcessingTime (int $test_id, int $usr_id, int $active_id)
 

Detailed Description

Member Function Documentation

◆ finishPassForUser()

ilCronFinishUnfinishedTestPasses::finishPassForUser (   $active_id,
  $obj_id 
)
protected

Definition at line 256 of file class.ilCronFinishUnfinishedTestPasses.php.

256 : void
257 {
258 $processLocker = $this->processLockerFactory->withContextId((int) $active_id)->getLocker();
259
260 $test_session = new ilTestSession($this->db, $this->user);
261 $test_session->loadFromDb($active_id);
262
263 if (ilObject::_exists($obj_id)) {
264 $this->test_result_repository->updateTestAttemptResult(
265 $active_id,
266 $test_session->getPass(),
267 null,
268 $obj_id
269 );
270
272 $test_session,
273 $obj_id,
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.');
277 } else {
278 $this->logger->info('Test object with id (' . $obj_id . ') does not exist.');
279 }
280 }
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
Class ilTestPassFinishTasks.
Test session handler.

References ilObject\_exists(), ILIAS\Repository\logger(), and ILIAS\Repository\user().

Referenced by finishPassOnEndingTime().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ finishPassOnEndingTime()

ilCronFinishUnfinishedTestPasses::finishPassOnEndingTime ( int  $test_id,
int  $active_id 
)
private

Definition at line 197 of file class.ilCronFinishUnfinishedTestPasses.php.

197 : bool
198 {
199 $now = time();
200 if ($this->test_ending_times[$test_id]['ending_time_enabled'] !== 1) {
201 $this->logger->info('Test (' . $test_id . ') has no ending time.');
202 return false;
203 }
204
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.');
212 return false;
213 }
214
215 $this->finishPassForUser($active_id, $this->test_ending_times[$test_id]['obj_fi']);
216 return true;
217 }

References $now, finishPassForUser(), and ILIAS\Repository\logger().

Referenced by processPasses().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ finishPassOnProcessingTime()

ilCronFinishUnfinishedTestPasses::finishPassOnProcessingTime ( int  $test_id,
int  $usr_id,
int  $active_id 
)
private

Definition at line 219 of file class.ilCronFinishUnfinishedTestPasses.php.

223 : bool {
224 if ($this->test_ending_times[$test_id]['enable_processing_time'] !== 1) {
225 $this->logger->info('Test (' . $test_id . ') has no processing time.');
226 return false;
227 }
228
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'];
231
232 if (!ilObject::_exists($obj_id)) {
233 $this->logger->info('Test object with id (' . $obj_id . ') does not exist.');
234 return false;
235 }
236
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');
246 return false;
247 }
248
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']);
253 return true;
254 }

References ILIAS\Repository\logger().

Referenced by processPasses().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gatherUsersWithUnfinishedPasses()

ilCronFinishUnfinishedTestPasses::gatherUsersWithUnfinishedPasses ( )
protected

Definition at line 135 of file class.ilCronFinishUnfinishedTestPasses.php.

135 : void
136 {
137 $query = '
138 SELECT tst_active.active_id,
139 tst_active.tries,
140 tst_active.user_fi usr_id,
141 tst_active.test_fi test_fi,
142 usr_data.login,
143 usr_data.lastname,
144 usr_data.firstname,
145 tst_active.submitted test_finished,
146 usr_data.matriculation,
147 usr_data.active,
148 tst_active.lastindex,
149 tst_active.last_started_pass last_started
150 FROM tst_active
151 LEFT JOIN usr_data
152 ON tst_active.user_fi = usr_data.usr_id
153 WHERE IFNULL(tst_active.last_finished_pass, -1) <> tst_active.last_started_pass
154 ';
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'];
159 }
160 }

Referenced by run().

+ Here is the caller graph for this function:

◆ getDefaultScheduleType()

ilCronFinishUnfinishedTestPasses::getDefaultScheduleType ( )

Reimplemented from ILIAS\Cron\CronJob.

Definition at line 88 of file class.ilCronFinishUnfinishedTestPasses.php.

89 {
90 return JobScheduleType::DAILY;
91 }

◆ getDefaultScheduleValue()

ilCronFinishUnfinishedTestPasses::getDefaultScheduleValue ( )

Reimplemented from ILIAS\Cron\CronJob.

Definition at line 93 of file class.ilCronFinishUnfinishedTestPasses.php.

93 : int
94 {
95 return 1;
96 }

◆ getDescription()

ilCronFinishUnfinishedTestPasses::getDescription ( )

Reimplemented from ILIAS\Cron\CronJob.

Definition at line 83 of file class.ilCronFinishUnfinishedTestPasses.php.

83 : string
84 {
85 return $this->lng->txt('finish_unfinished_passes_desc');
86 }

References ILIAS\Repository\lng().

Referenced by ilCronFinishUnfinishedTestPassesTest\testGetDescription().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getId()

ilCronFinishUnfinishedTestPasses::getId ( )

Reimplemented from ILIAS\Cron\CronJob.

Definition at line 73 of file class.ilCronFinishUnfinishedTestPasses.php.

73 : string
74 {
75 return 'finish_unfinished_passes';
76 }

◆ getTestsFinishAndProcessingTime()

ilCronFinishUnfinishedTestPasses::getTestsFinishAndProcessingTime ( )
protected

Definition at line 162 of file class.ilCronFinishUnfinishedTestPasses.php.

162 : void
163 {
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 " .
167 $this->db->in('test_id', $this->test_ids, false, ilDBConstants::T_INTEGER);
168
169 $result = $this->db->query($query);
170 while ($row = $this->db->fetchAssoc($result)) {
171 $this->test_ending_times[$row['test_id']] = $row;
172 }
173 $this->logger->info('Gathered data for ' . count($this->test_ids) . ' test id(s) => (' . implode(',', $this->test_ids) . ')');
174 }

References ILIAS\Repository\logger(), and ilDBConstants\T_INTEGER.

Referenced by run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTitle()

ilCronFinishUnfinishedTestPasses::getTitle ( )

Reimplemented from ILIAS\Cron\CronJob.

Definition at line 78 of file class.ilCronFinishUnfinishedTestPasses.php.

78 : string
79 {
80 return $this->lng->txt('finish_unfinished_passes');
81 }

References ILIAS\Repository\lng().

Referenced by ilCronFinishUnfinishedTestPassesTest\testGetTitle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasAutoActivation()

ilCronFinishUnfinishedTestPasses::hasAutoActivation ( )

Is to be activated on "installation", does only work for ILIAS core cron jobs.

Reimplemented from ILIAS\Cron\CronJob.

Definition at line 98 of file class.ilCronFinishUnfinishedTestPasses.php.

98 : bool
99 {
100 return false;
101 }

◆ hasCustomSettings()

ilCronFinishUnfinishedTestPasses::hasCustomSettings ( )

Reimplemented from ILIAS\Cron\CronJob.

Definition at line 108 of file class.ilCronFinishUnfinishedTestPasses.php.

108 : bool
109 {
110 return true;
111 }

◆ hasFlexibleSchedule()

ilCronFinishUnfinishedTestPasses::hasFlexibleSchedule ( )

Reimplemented from ILIAS\Cron\CronJob.

Definition at line 103 of file class.ilCronFinishUnfinishedTestPasses.php.

103 : bool
104 {
105 return true;
106 }

◆ processPasses()

ilCronFinishUnfinishedTestPasses::processPasses ( )
protected

Definition at line 176 of file class.ilCronFinishUnfinishedTestPasses.php.

176 : void
177 {
178 foreach ($this->unfinished_passes as $data) {
179 $test_id = $data['test_fi'];
180 if (!array_key_exists($test_id, $this->test_ending_times)) {
181 continue;
182 }
183 if (!$this->finishPassOnEndingTime($test_id, $data['active_id'])
185 $test_id,
186 $data['usr_id'],
187 $data['active_id']
188 )
189 ) {
190 $this->logger->info('Test session with active id ('
191 . $data['active_id'] . ') can not be finished by this cron job.');
192 }
193 }
194
195 }
finishPassOnProcessingTime(int $test_id, int $usr_id, int $active_id)

References $data, finishPassOnEndingTime(), finishPassOnProcessingTime(), and ILIAS\Repository\logger().

Referenced by run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

ilCronFinishUnfinishedTestPasses::run ( )

Reimplemented from ILIAS\Cron\CronJob.

Definition at line 113 of file class.ilCronFinishUnfinishedTestPasses.php.

113 : JobResult
114 {
115 $this->logger->info('start inf cronjob...');
116
117 $result = new JobResult();
118
120 if (count($this->unfinished_passes) > 0) {
121 $this->logger->info('found ' . count($this->unfinished_passes) . ' unfinished passes starting analyses.');
123 $this->processPasses();
124 } else {
125 $this->logger->info('No unfinished passes found.');
126 }
127
128 $result->setStatus(JobResult::STATUS_OK);
129
130 $this->logger->info(' ...finishing cronjob.');
131
132 return $result;
133 }

References gatherUsersWithUnfinishedPasses(), getTestsFinishAndProcessingTime(), ILIAS\Repository\logger(), and processPasses().

+ Here is the call graph for this function:

Field Documentation

◆ $db

readonly ilDBInterface ilCronFinishUnfinishedTestPasses::$db
protected

Definition at line 38 of file class.ilCronFinishUnfinishedTestPasses.php.

◆ $lng

readonly ilLanguage ilCronFinishUnfinishedTestPasses::$lng
protected

Definition at line 37 of file class.ilCronFinishUnfinishedTestPasses.php.

◆ $logger

readonly TestLogger ilCronFinishUnfinishedTestPasses::$logger
protected

Definition at line 35 of file class.ilCronFinishUnfinishedTestPasses.php.

◆ $now

int ilCronFinishUnfinishedTestPasses::$now
protected

Definition at line 41 of file class.ilCronFinishUnfinishedTestPasses.php.

Referenced by finishPassOnEndingTime().

◆ $obj_data_cache

readonly ilObjectDataCache ilCronFinishUnfinishedTestPasses::$obj_data_cache
protected

Definition at line 40 of file class.ilCronFinishUnfinishedTestPasses.php.

◆ $processLockerFactory

ilTestProcessLockerFactory ilCronFinishUnfinishedTestPasses::$processLockerFactory
protected

Definition at line 45 of file class.ilCronFinishUnfinishedTestPasses.php.

◆ $test_ending_times

array ilCronFinishUnfinishedTestPasses::$test_ending_times
protected

Definition at line 44 of file class.ilCronFinishUnfinishedTestPasses.php.

◆ $test_ids

array ilCronFinishUnfinishedTestPasses::$test_ids
protected

Definition at line 43 of file class.ilCronFinishUnfinishedTestPasses.php.

◆ $test_result_repository

TestResultRepository ilCronFinishUnfinishedTestPasses::$test_result_repository
protected

Definition at line 46 of file class.ilCronFinishUnfinishedTestPasses.php.

◆ $unfinished_passes

array ilCronFinishUnfinishedTestPasses::$unfinished_passes
protected

Definition at line 42 of file class.ilCronFinishUnfinishedTestPasses.php.

◆ $user

readonly ilObjUser ilCronFinishUnfinishedTestPasses::$user
protected

Definition at line 39 of file class.ilCronFinishUnfinishedTestPasses.php.


The documentation for this class was generated from the following file: