ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilCronFinishUnfinishedTestPasses Class Reference

Class ilCronFinishUnfinishedTestPasses. More...

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

Public Member Functions

 getId ()
 
 getTitle ()
 
 getDescription ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 hasAutoActivation ()
 
 hasFlexibleSchedule ()
 
 hasCustomSettings ()
 
 run ()
 
- Public Member Functions inherited from ilCronJob
 setDateTimeProvider (?Closure $date_time_provider)
 
 isDue (?DateTimeImmutable $last_run, ?CronJobScheduleType $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 (?CronJobScheduleType $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 ()
 
 addCustomSettingsToForm (ilPropertyFormGUI $a_form)
 
 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_pass_result_repository
 
- Protected Attributes inherited from ilCronJob
CronJobScheduleType $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 250 of file class.ilCronFinishUnfinishedTestPasses.php.

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

Referenced by finishPassOnEndingTime(), and finishPassOnProcessingTime().

250  : void
251  {
252  $processLocker = $this->processLockerFactory->withContextId((int) $active_id)->getLocker();
253 
254  $test_session = new ilTestSession($this->db, $this->user);
255  $test_session->loadFromDb($active_id);
256 
257  if (ilObject::_exists($obj_id)) {
258  $test = new ilObjTest($obj_id, false);
259 
260  $test->updateTestPassResults(
261  $active_id,
262  $test_session->getPass(),
263  null,
264  $obj_id
265  );
266 
268  $test_session,
269  $test,
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.');
273  } else {
274  $this->logger->info('Test object with id (' . $obj_id . ') does not exist.');
275  }
276  }
Class ilTestPassFinishTasks.
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
+ 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 191 of file class.ilCronFinishUnfinishedTestPasses.php.

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

Referenced by processPasses().

191  : bool
192  {
193  $now = time();
194  if ($this->test_ending_times[$test_id]['ending_time_enabled'] !== 1) {
195  $this->logger->info('Test (' . $test_id . ') has no ending time.');
196  return false;
197  }
198 
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.');
206  return false;
207  }
208 
209  $this->finishPassForUser($active_id, $this->test_ending_times[$test_id]['obj_fi']);
210  return true;
211  }
+ 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 213 of file class.ilCronFinishUnfinishedTestPasses.php.

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

Referenced by processPasses().

217  : bool {
218  if ($this->test_ending_times[$test_id]['enable_processing_time'] !== 1) {
219  $this->logger->info('Test (' . $test_id . ') has no processing time.');
220  return false;
221  }
222 
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'];
225 
226  if (!ilObject::_exists($obj_id)) {
227  $this->logger->info('Test object with id (' . $obj_id . ') does not exist.');
228  return false;
229  }
230 
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');
240  return false;
241  }
242 
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']);
247  return true;
248  }
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gatherUsersWithUnfinishedPasses()

ilCronFinishUnfinishedTestPasses::gatherUsersWithUnfinishedPasses ( )
protected

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

Referenced by run().

132  : void
133  {
134  $query = '
135  SELECT tst_active.active_id,
136  tst_active.tries,
137  tst_active.user_fi usr_id,
138  tst_active.test_fi test_fi,
139  usr_data.login,
140  usr_data.lastname,
141  usr_data.firstname,
142  tst_active.submitted test_finished,
143  usr_data.matriculation,
144  usr_data.active,
145  tst_active.lastindex,
146  tst_active.last_started_pass last_started
147  FROM tst_active
148  LEFT JOIN usr_data
149  ON tst_active.user_fi = usr_data.usr_id
150  WHERE IFNULL(tst_active.last_finished_pass, -1) <> tst_active.last_started_pass
151  ';
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'];
156  }
157  }
+ Here is the caller graph for this function:

◆ getDefaultScheduleType()

ilCronFinishUnfinishedTestPasses::getDefaultScheduleType ( )

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

86  {
87  return CronJobScheduleType::SCHEDULE_TYPE_DAILY;
88  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ getDefaultScheduleValue()

ilCronFinishUnfinishedTestPasses::getDefaultScheduleValue ( )

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

90  : int
91  {
92  return 1;
93  }

◆ getDescription()

ilCronFinishUnfinishedTestPasses::getDescription ( )

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

References ILIAS\Repository\lng().

Referenced by ilCronFinishUnfinishedTestPassesTest\testGetDescription().

80  : string
81  {
82  return $this->lng->txt('finish_unfinished_passes_desc');
83  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getId()

ilCronFinishUnfinishedTestPasses::getId ( )

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

70  : string
71  {
72  return 'finish_unfinished_passes';
73  }

◆ getTestsFinishAndProcessingTime()

ilCronFinishUnfinishedTestPasses::getTestsFinishAndProcessingTime ( )
protected

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

References ILIAS\Repository\logger().

Referenced by run().

159  : void
160  {
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;
166  }
167  $this->logger->info('Gathered data for ' . count($this->test_ids) . ' test id(s) => (' . implode(',', $this->test_ids) . ')');
168  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTitle()

ilCronFinishUnfinishedTestPasses::getTitle ( )

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

References ILIAS\Repository\lng().

Referenced by ilCronFinishUnfinishedTestPassesTest\testGetTitle().

75  : string
76  {
77  return $this->lng->txt('finish_unfinished_passes');
78  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasAutoActivation()

ilCronFinishUnfinishedTestPasses::hasAutoActivation ( )

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

95  : bool
96  {
97  return false;
98  }

◆ hasCustomSettings()

ilCronFinishUnfinishedTestPasses::hasCustomSettings ( )

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

105  : bool
106  {
107  return true;
108  }

◆ hasFlexibleSchedule()

ilCronFinishUnfinishedTestPasses::hasFlexibleSchedule ( )

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

100  : bool
101  {
102  return true;
103  }

◆ processPasses()

ilCronFinishUnfinishedTestPasses::processPasses ( )
protected

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

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

Referenced by run().

170  : void
171  {
172  foreach ($this->unfinished_passes as $data) {
173  $test_id = $data['test_fi'];
174  if (!array_key_exists($test_id, $this->test_ending_times)) {
175  continue;
176  }
177  if (!$this->finishPassOnEndingTime($test_id, $data['active_id'])
178  && !$this->finishPassOnProcessingTime(
179  $test_id,
180  $data['usr_id'],
181  $data['active_id']
182  )
183  ) {
184  $this->logger->info('Test session with active id ('
185  . $data['active_id'] . ') can not be finished by this cron job.');
186  }
187  }
188 
189  }
finishPassOnProcessingTime(int $test_id, int $usr_id, int $active_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

ilCronFinishUnfinishedTestPasses::run ( )

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

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

111  {
112  $this->logger->info('start inf cronjob...');
113 
114  $result = new ilCronJobResult();
115 
117  if (count($this->unfinished_passes) > 0) {
118  $this->logger->info('found ' . count($this->unfinished_passes) . ' unfinished passes starting analyses.');
120  $this->processPasses();
121  } else {
122  $this->logger->info('No unfinished passes found.');
123  }
124 
125  $result->setStatus(ilCronJobResult::STATUS_OK);
126 
127  $this->logger->info(' ...finishing cronjob.');
128 
129  return $result;
130  }
+ Here is the call graph for this function:

Field Documentation

◆ $db

readonly ilDBInterface ilCronFinishUnfinishedTestPasses::$db
protected

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

◆ $lng

readonly ilLanguage ilCronFinishUnfinishedTestPasses::$lng
protected

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

◆ $logger

readonly TestLogger ilCronFinishUnfinishedTestPasses::$logger
protected

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

◆ $now

int ilCronFinishUnfinishedTestPasses::$now
protected

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

◆ $obj_data_cache

readonly ilObjectDataCache ilCronFinishUnfinishedTestPasses::$obj_data_cache
protected

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

◆ $processLockerFactory

ilTestProcessLockerFactory ilCronFinishUnfinishedTestPasses::$processLockerFactory
protected

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

◆ $test_ending_times

array ilCronFinishUnfinishedTestPasses::$test_ending_times
protected

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

◆ $test_ids

array ilCronFinishUnfinishedTestPasses::$test_ids
protected

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

◆ $test_pass_result_repository

TestResultRepository ilCronFinishUnfinishedTestPasses::$test_pass_result_repository
protected

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

◆ $unfinished_passes

array ilCronFinishUnfinishedTestPasses::$unfinished_passes
protected

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

◆ $user

readonly ilObjUser ilCronFinishUnfinishedTestPasses::$user
protected

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


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