75            if (isset(
$dic[
'lng'])) {
 
   77                $language->loadLanguageModule(
'certificate');
 
   89        return $this->lng->txt(
'cert_cron_task_title');
 
   97        return $this->lng->txt(
'cert_cron_task_desc');
 
  102        if (
null === $this->dic) {
 
  107        $database = $this->dic->database();
 
  109        if (
null === $this->logger) {
 
  110            $this->logger = $this->dic->logger()->cert();
 
  113        if (
null === $this->queueRepository) {
 
  117        if (
null === $this->templateRepository) {
 
  121        if (
null === $this->userRepository) {
 
  125        if (
null === $this->valueReplacement) {
 
  129        if (
null === $this->objectHelper) {
 
  149        $currentMode = $this->
settings->get(
'persistent_certificate_mode', 
'persistent_certificate_mode_cron');
 
  150        if ($currentMode !== 
'persistent_certificate_mode_cron') {
 
  151            $this->logger->warning(sprintf(
'Will not start cron job, because the mode is not set as cron job. Current Mode in settings: "%s"', $currentMode));
 
  155        $this->logger->info(
'START - Begin with cron job to create user certificates from templates');
 
  157        $entries = $this->queueRepository->getAllEntriesFromQueue();
 
  162        $succeededGenerations = [];
 
  163        foreach ($entries as $entry) {
 
  165                $succeededGenerations = $this->processEntry(
 
  168                    $succeededGenerations
 
  173                $this->logger->warning($exception->getMessage());
 
  174                $this->logger->warning(
'The user MAY not be able to achieve the certificate based on the adapters settings');
 
  175                $this->logger->warning(
'Due the error, the entry will now be removed from the queue.');
 
  177                $this->queueRepository->removeFromQueue($entry->getId());
 
  181                $this->logger->warning($exception->getMessage());
 
  182                $this->logger->warning(
'Due the error, the entry will now be removed from the queue.');
 
  184                $this->queueRepository->removeFromQueue($entry->getId());
 
  190        if (count($succeededGenerations) > 0) {
 
  192                'Generated %s certificate(s) in run. Result: %s',
 
  193                count($succeededGenerations),
 
  194                implode(
' | ', $succeededGenerations)
 
  197            $result->setMessage(
'0 certificates generated in current run.');
 
  208        return 'certificate';
 
  252    public function processEntry(
int $entryCounter, 
ilCertificateQueueEntry $entry, array $succeededGenerations) : array
 
  254        if ($entryCounter > 0 && $entryCounter % 10 === 0) {
 
  258        $this->logger->debug(
'Entry found will start of processing the entry');
 
  262        $this->logger->debug(
'Adapter class to be executed "' . $class . 
'"');
 
  264        $placeholderValueObject = 
new $class();
 
  266            throw new ilException(
'The given class ' . $class . 
' MUST be an instance of ilCertificateCronAdapter and MUST have an accessible namespace. The class map MAY be reloader.');
 
  273        $this->logger->debug(sprintf(
 
  274            'Fetch certificate template for user id: "%s" and object id: "%s" and template id: "%s"',
 
  280        $template = $this->templateRepository->fetchTemplate($templateId);
 
  282        $object = $this->objectHelper->getInstanceByObjId($objId, 
false);
 
  284            throw new ilException(sprintf(
'The given object id: "%s"  could not be referred to an actual object', $objId));
 
  287        $type = $object->getType();
 
  289        $userObject = $this->objectHelper->getInstanceByObjId($userId, 
false);
 
  290        if (!$userObject || !($userObject instanceof \
ilObjUser)) {
 
  291            throw new ilException(
'The given user id"' . $userId . 
'" could not be referred to an actual user');
 
  294        $this->logger->debug(sprintf(
 
  299        $certificateContent = 
$template->getCertificateContent();
 
  301        $placeholderValues = $placeholderValueObject->getPlaceholderValues($userId, $objId);
 
  303        $this->logger->debug(sprintf(
 
  304            'Values for placeholders: "%s"',
 
  305            json_encode($placeholderValues)
 
  308        $certificateContent = $this->valueReplacement->replace(
 
  313        $thumbnailImagePath = (string) 
$template->getThumbnailImagePath();
 
  319            $userObject->getFullname(),
 
  322            json_encode($placeholderValues),
 
  331        $persistedUserCertificate = $this->userRepository->save($userCertificate);
 
  333        $succeededGenerations[] = implode(
'/', [
 
  338        $this->queueRepository->removeFromQueue($entry->
getId());
 
  340        $this->dic->event()->raise(
 
  341            'Services/Certificate',
 
  343            [
'certificate' => $persistedUserCertificate]
 
  346        return $succeededGenerations;
 
An exception for terminatinating execution or to throw for unit testing.
getDefaultScheduleType()
Get schedule type.int
getDescription()
Get description.string
getDefaultScheduleValue()
Get schedule value.int|array
getTitle()
Get title.string
hasAutoActivation()
Is to be activated on "installation".boolean
$queueRepository
@var ilCertificateQueueRepository
const DEFAULT_SCHEDULE_HOURS
hasFlexibleSchedule()
Can the schedule be configured?boolean
__construct(ilCertificateQueueRepository $queueRepository=null, ilCertificateTemplateRepository $templateRepository=null, ilUserCertificateRepository $userRepository=null, ilCertificateValueReplacement $valueReplacement=null, ilLogger $logger=null, \ILIAS\DI\Container $dic=null, ilLanguage $language=null, ilCertificateObjectHelper $objectHelper=null, ilSetting $setting=null)
Cron job result data container.
Cron job application base class.
const SCHEDULE_TYPE_IN_MINUTES
static ping($a_job_id)
Keep cron job alive.
Base class for ILIAS Exception handling.
Component logger with individual log levels by component id.
Class ilObject Basic functions for all objects.
const ILIAS_VERSION_NUMERIC