ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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: feed.php:28
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 191 of file class.ilCertificateCron.php.

192  {
193  return CronJobScheduleType::SCHEDULE_TYPE_IN_MINUTES;
194  }
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 176 of file class.ilCertificateCron.php.

Referenced by getDefaultScheduleValue().

176  : string
177  {
178  return 'certificate';
179  }
+ 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 181 of file class.ilCertificateCron.php.

181  : bool
182  {
183  return true;
184  }

◆ hasFlexibleSchedule()

ilCertificateCron::hasFlexibleSchedule ( )

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

186  : bool
187  {
188  return true;
189  }

◆ 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: feed.php:28
+ 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 $message, 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  return $result;
124  }
125 
126  $this->logger->debug('START - Begin with cron job to create user certificates from templates');
127 
128  $entries = $this->queueRepository->getAllEntriesFromQueue();
129 
130  $status = ilCronJobResult::STATUS_OK;
131 
132  $entryCounter = 0;
133  $succeededGenerations = [];
134  foreach ($entries as $entry) {
135  try {
136  $succeededGenerations = $this->processEntry(
137  $entryCounter,
138  $entry,
139  $succeededGenerations
140  );
141 
142  ++$entryCounter;
143  } catch (ilInvalidCertificateException $exception) {
144  $this->logger->warning($exception->getMessage());
145  $this->logger->warning('The user MAY not be able to achieve the certificate based on the adapters settings');
146  $this->logger->warning('Due the error, the entry will now be removed from the queue.');
147 
148  $this->queueRepository->removeFromQueue($entry->getId());
149 
150  continue;
151  } catch (ilException $exception) {
152  $this->logger->warning($exception->getMessage());
153  $this->logger->warning('Due the error, the entry will now be removed from the queue.');
154 
155  $this->queueRepository->removeFromQueue($entry->getId());
156  continue;
157  }
158  }
159 
160  $result->setStatus($status);
161  if ($succeededGenerations !== []) {
162  $message = sprintf(
163  'Generated %s certificate(s) in run. Result: %s',
164  count($succeededGenerations),
165  implode(' | ', $succeededGenerations)
166  );
167  $this->logger->info($message);
168  $result->setMessage(ilStr::subStr($message, 0, 400));
169  } else {
170  $result->setMessage('0 certificates generated in current run.');
171  }
172 
173  return $result;
174  }
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)
$message
Definition: xapiexit.php:32
+ 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: