ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
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 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 252 of file class.ilCronFinishUnfinishedTestPasses.php.

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

Referenced by finishPassOnEndingTime(), and finishPassOnProcessingTime().

252  : void
253  {
254  $processLocker = $this->processLockerFactory->withContextId((int) $active_id)->getLocker();
255 
256  $test_session = new ilTestSession($this->db, $this->user);
257  $test_session->loadFromDb($active_id);
258 
259  if (ilObject::_exists($obj_id)) {
260  $this->test_result_repository->updateTestAttemptResult(
261  $active_id,
262  $test_session->getPass(),
263  null,
264  $obj_id
265  );
266 
268  $test_session,
269  $obj_id,
270  $this->test_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.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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 193 of file class.ilCronFinishUnfinishedTestPasses.php.

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

Referenced by processPasses().

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

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

Referenced by processPasses().

219  : bool {
220  if ($this->test_ending_times[$test_id]['enable_processing_time'] !== 1) {
221  $this->logger->info('Test (' . $test_id . ') has no processing time.');
222  return false;
223  }
224 
225  $this->logger->info('Test (' . $test_id . ') has processing time (' . $this->test_ending_times[$test_id]['processing_time'] . ')');
226  $obj_id = $this->test_ending_times[$test_id]['obj_fi'];
227 
228  if (!ilObject::_exists($obj_id)) {
229  $this->logger->info('Test object with id (' . $obj_id . ') does not exist.');
230  return false;
231  }
232 
233  $test_obj = new ilObjTest($obj_id, false);
234  $startingTime = $test_obj->getStartingTimeOfUser($active_id);
235  $max_processing_time = $test_obj->isMaxProcessingTimeReached($startingTime, $active_id);
236  if (!$max_processing_time) {
237  $this->logger->info('Max Processing time not reached for user id ('
238  . $usr_id . ') in test with active id ('
239  . $active_id . '). Starting time: ' . $startingTime
240  . ' Processing time: ' . $test_obj->getProcessingTime() . ' / '
241  . $test_obj->getProcessingTimeInSeconds() . 's');
242  return false;
243  }
244 
245  $this->logger->info('Max Processing time reached for user id ('
246  . $usr_id . ') so test with active id ('
247  . $active_id . ') will be finished.');
248  $this->finishPassForUser($active_id, $this->test_ending_times[$test_id]['obj_fi']);
249  return true;
250  }
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 134 of file class.ilCronFinishUnfinishedTestPasses.php.

Referenced by run().

134  : void
135  {
136  $query = '
137  SELECT tst_active.active_id,
138  tst_active.tries,
139  tst_active.user_fi usr_id,
140  tst_active.test_fi test_fi,
141  usr_data.login,
142  usr_data.lastname,
143  usr_data.firstname,
144  tst_active.submitted test_finished,
145  usr_data.matriculation,
146  usr_data.active,
147  tst_active.lastindex,
148  tst_active.last_started_pass last_started
149  FROM tst_active
150  LEFT JOIN usr_data
151  ON tst_active.user_fi = usr_data.usr_id
152  WHERE IFNULL(tst_active.last_finished_pass, -1) <> tst_active.last_started_pass
153  ';
154  $result = $this->db->query($query);
155  while ($row = $this->db->fetchAssoc($result)) {
156  $this->unfinished_passes[] = $row;
157  $this->test_ids[] = $row['test_fi'];
158  }
159  }
+ Here is the caller graph for this function:

◆ getDefaultScheduleType()

ilCronFinishUnfinishedTestPasses::getDefaultScheduleType ( )

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

88  {
89  return JobScheduleType::DAILY;
90  }

◆ getDefaultScheduleValue()

ilCronFinishUnfinishedTestPasses::getDefaultScheduleValue ( )

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

92  : int
93  {
94  return 1;
95  }

◆ getDescription()

ilCronFinishUnfinishedTestPasses::getDescription ( )

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

References ILIAS\Repository\lng().

Referenced by ilCronFinishUnfinishedTestPassesTest\testGetDescription().

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

◆ getId()

ilCronFinishUnfinishedTestPasses::getId ( )

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

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

◆ getTestsFinishAndProcessingTime()

ilCronFinishUnfinishedTestPasses::getTestsFinishAndProcessingTime ( )
protected

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

References ILIAS\Repository\logger().

Referenced by run().

161  : void
162  {
163  $query = 'SELECT test_id, obj_fi, ending_time, ending_time_enabled, processing_time, enable_processing_time FROM tst_tests WHERE ' .
164  $this->db->in('test_id', $this->test_ids, false, 'integer');
165  $result = $this->db->query($query);
166  while ($row = $this->db->fetchAssoc($result)) {
167  $this->test_ending_times[$row['test_id']] = $row;
168  }
169  $this->logger->info('Gathered data for ' . count($this->test_ids) . ' test id(s) => (' . implode(',', $this->test_ids) . ')');
170  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTitle()

ilCronFinishUnfinishedTestPasses::getTitle ( )

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

References ILIAS\Repository\lng().

Referenced by ilCronFinishUnfinishedTestPassesTest\testGetTitle().

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

◆ hasAutoActivation()

ilCronFinishUnfinishedTestPasses::hasAutoActivation ( )

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

97  : bool
98  {
99  return false;
100  }

◆ hasCustomSettings()

ilCronFinishUnfinishedTestPasses::hasCustomSettings ( )

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

107  : bool
108  {
109  return true;
110  }

◆ hasFlexibleSchedule()

ilCronFinishUnfinishedTestPasses::hasFlexibleSchedule ( )

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

102  : bool
103  {
104  return true;
105  }

◆ processPasses()

ilCronFinishUnfinishedTestPasses::processPasses ( )
protected

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

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

Referenced by run().

172  : void
173  {
174  foreach ($this->unfinished_passes as $data) {
175  $test_id = $data['test_fi'];
176  if (!array_key_exists($test_id, $this->test_ending_times)) {
177  continue;
178  }
179  if (!$this->finishPassOnEndingTime($test_id, $data['active_id'])
180  && !$this->finishPassOnProcessingTime(
181  $test_id,
182  $data['usr_id'],
183  $data['active_id']
184  )
185  ) {
186  $this->logger->info('Test session with active id ('
187  . $data['active_id'] . ') can not be finished by this cron job.');
188  }
189  }
190 
191  }
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 112 of file class.ilCronFinishUnfinishedTestPasses.php.

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

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

◆ $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: