ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilCertificateCron Class Reference
+ Inheritance diagram for ilCertificateCron:
+ Collaboration diagram for ilCertificateCron:

Public Member Functions

 __construct (private ?ilCertificateQueueRepository $queueRepository=null, private ?ilCertificateTemplateRepository $templateRepository=null, private ?ilUserCertificateRepository $userRepository=null, private ?ilCertificateValueReplacement $valueReplacement=null, private ?ilLogger $logger=null, ?Container $dic=null, ?ilLanguage $language=null, private ?ilCertificateObjectHelper $objectHelper=null, private ?ilSetting $settings=null, private ?ilCronManager $cronManager=null,)
 
 getTitle ()
 
 getDescription ()
 
 init ()
 
 run ()
 
 getId ()
 
 hasAutoActivation ()
 
 hasFlexibleSchedule ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
- 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 Attributes

ilLanguage $lng
 
- Protected Attributes inherited from ilCronJob
CronJobScheduleType $schedule_type = null
 
int $schedule_value = null
 
Closure $date_time_provider = null
 

Private Attributes

Container $dic
 

Detailed Description

Author
Niels Theen nthee.nosp@m.n@da.nosp@m.tabay.nosp@m..de

Definition at line 27 of file class.ilCertificateCron.php.

Constructor & Destructor Documentation

◆ __construct()

ilCertificateCron::__construct ( private ?ilCertificateQueueRepository  $queueRepository = null,
private ?ilCertificateTemplateRepository  $templateRepository = null,
private ?ilUserCertificateRepository  $userRepository = null,
private ?ilCertificateValueReplacement  $valueReplacement = null,
private ?ilLogger  $logger = null,
?Container  $dic = null,
?ilLanguage  $language = null,
private ?ilCertificateObjectHelper  $objectHelper = null,
private ?ilSetting  $settings = null,
private ?ilCronManager  $cronManager = null 
)

Definition at line 32 of file class.ilCertificateCron.php.

References $DIC, $dic, ILIAS\DI\Container\language(), and ILIAS\Repository\lng().

43  {
44  if (null === $dic) {
45  global $DIC;
46  $dic = $DIC;
47  }
48  $this->dic = $dic;
49 
50  if ($dic && isset($dic['lng'])) {
51  $language = $dic->language();
52  $language->loadLanguageModule('certificate');
53  }
54 
55  $this->lng = $language;
56  }
global $DIC
Definition: shib_login.php:25
language()
Get interface to the i18n service.
Definition: Container.php:95
+ Here is the call graph for this function:

Member Function Documentation

◆ getDefaultScheduleType()

ilCertificateCron::getDefaultScheduleType ( )

Definition at line 193 of file class.ilCertificateCron.php.

194  {
195  return CronJobScheduleType::SCHEDULE_TYPE_IN_MINUTES;
196  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ getDefaultScheduleValue()

◆ getDescription()

ilCertificateCron::getDescription ( )

Definition at line 63 of file class.ilCertificateCron.php.

References ILIAS\Repository\lng().

63  : string
64  {
65  return $this->lng->txt('cert_cron_task_desc');
66  }
+ Here is the call graph for this function:

◆ getId()

ilCertificateCron::getId ( )

Definition at line 178 of file class.ilCertificateCron.php.

Referenced by getDefaultScheduleValue().

178  : string
179  {
180  return 'certificate';
181  }
+ Here is the caller graph for this function:

◆ getTitle()

ilCertificateCron::getTitle ( )

Definition at line 58 of file class.ilCertificateCron.php.

References ILIAS\Repository\lng().

58  : string
59  {
60  return $this->lng->txt('cert_cron_task_title');
61  }
+ Here is the call graph for this function:

◆ hasAutoActivation()

ilCertificateCron::hasAutoActivation ( )

Definition at line 183 of file class.ilCertificateCron.php.

183  : bool
184  {
185  return true;
186  }

◆ hasFlexibleSchedule()

ilCertificateCron::hasFlexibleSchedule ( )

Definition at line 188 of file class.ilCertificateCron.php.

188  : bool
189  {
190  return true;
191  }

◆ init()

ilCertificateCron::init ( )

Definition at line 68 of file class.ilCertificateCron.php.

References $DIC, ILIAS\Repository\logger(), and ILIAS\Repository\settings().

Referenced by run().

68  : void
69  {
70  if (null === $this->dic) {
71  global $DIC;
72  $this->dic = $DIC;
73  }
74 
75  $database = $this->dic->database();
76 
77  if (null === $this->logger) {
78  $this->logger = $this->dic->logger()->cert();
79  }
80 
81  if (null === $this->cronManager) {
82  $this->cronManager = $this->dic->cron()->manager();
83  }
84 
85  if (null === $this->queueRepository) {
86  $this->queueRepository = new ilCertificateQueueRepository($database, $this->logger);
87  }
88 
89  if (null === $this->templateRepository) {
90  $this->templateRepository = new ilCertificateTemplateDatabaseRepository($database, $this->logger);
91  }
92 
93  if (null === $this->userRepository) {
94  $this->userRepository = new ilUserCertificateRepository($database, $this->logger);
95  }
96 
97  if (null === $this->valueReplacement) {
98  $this->valueReplacement = new ilCertificateValueReplacement();
99  }
100 
101  if (null === $this->objectHelper) {
102  $this->objectHelper = new ilCertificateObjectHelper();
103  }
104 
105  if (null === $this->settings) {
106  $this->settings = new ilSetting('certificate');
107  }
108  }
global $DIC
Definition: shib_login.php:25
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

ilCertificateCron::run ( )

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

References init(), ILIAS\Repository\logger(), processEntry(), ILIAS\Repository\settings(), ilCronJobResult\STATUS_NO_ACTION, ilCronJobResult\STATUS_OK, and ilStr\subStr().

111  {
112  $this->init();
113 
114  $result = new ilCronJobResult();
115  $result->setStatus(ilCronJobResult::STATUS_NO_ACTION);
116 
117  $currentMode = $this->settings->get('persistent_certificate_mode', 'persistent_certificate_mode_cron');
118  if ($currentMode !== 'persistent_certificate_mode_cron') {
119  $this->logger->warning(sprintf(
120  'Will not start cron job, because the mode is not set as cron job. Current Mode in settings: "%s"',
121  $currentMode
122  ));
123 
124  return $result;
125  }
126 
127  $this->logger->debug('START - Begin with cron job to create user certificates from templates');
128 
129  $entries = $this->queueRepository->getAllEntriesFromQueue();
130 
131  $status = ilCronJobResult::STATUS_OK;
132 
133  $entryCounter = 0;
134  $succeededGenerations = [];
135  foreach ($entries as $entry) {
136  try {
137  $succeededGenerations = $this->processEntry(
138  $entryCounter,
139  $entry,
140  $succeededGenerations
141  );
142 
143  ++$entryCounter;
144  } catch (ilInvalidCertificateException $exception) {
145  $this->logger->warning($exception->getMessage());
146  $this->logger->warning('The user MAY not be able to achieve the certificate based on the adapters settings');
147  $this->logger->warning('Due the error, the entry will now be removed from the queue.');
148 
149  $this->queueRepository->removeFromQueue($entry->getId());
150 
151  continue;
152  } catch (ilException $exception) {
153  $this->logger->warning($exception->getMessage());
154  $this->logger->warning('Due the error, the entry will now be removed from the queue.');
155 
156  $this->queueRepository->removeFromQueue($entry->getId());
157 
158  continue;
159  }
160  }
161 
162  $result->setStatus($status);
163  if ($succeededGenerations !== []) {
164  $message = sprintf(
165  'Generated %s certificate(s) in run. Result: %s',
166  count($succeededGenerations),
167  implode(' | ', $succeededGenerations)
168  );
169  $this->logger->info($message);
170  $result->setMessage(ilStr::subStr($message, 0, 400));
171  } else {
172  $result->setMessage('0 certificates generated in current run.');
173  }
174 
175  return $result;
176  }
static subStr(string $a_str, int $a_start, ?int $a_length=null)
Definition: class.ilStr.php:24
final const STATUS_NO_ACTION
processEntry(string $class_name, int $obj_id, int $usr_id, \ilCertificateTemplate $template)
+ Here is the call graph for this function:

Field Documentation

◆ $dic

Container ilCertificateCron::$dic
private

Definition at line 30 of file class.ilCertificateCron.php.

Referenced by __construct().

◆ $lng

ilLanguage ilCertificateCron::$lng
protected

Definition at line 29 of file class.ilCertificateCron.php.


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