ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCertificateQueueRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 public function __construct(private readonly ilDBInterface $database, private readonly ilLogger $logger)
27 {
28 }
29
30 public function addToQueue(ilCertificateQueueEntry $certificateQueueEntry): void
31 {
32 $this->logger->debug('START - Add new entry to certificate cron job queue');
33
34 $id = $this->database->nextId('il_cert_cron_queue');
35
36 $row = [
37 'id' => ['integer', $id],
38 'obj_id' => ['integer', $certificateQueueEntry->getObjId()],
39 'usr_id' => ['integer', $certificateQueueEntry->getUserId()],
40 'adapter_class' => ['text', $certificateQueueEntry->getAdapterClass()],
41 'state' => ['text', $certificateQueueEntry->getState()],
42 'started_timestamp' => ['integer', $certificateQueueEntry->getStartedTimestamp()],
43 'template_id' => ['integer', $certificateQueueEntry->getTemplateId()],
44 ];
45
46 $this->logger->debug(sprintf(
47 'Save queue entry with following values: %s',
48 json_encode($row, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT)
49 ));
50 $this->logger->debug('END - Added entry to queue');
51
52 $this->database->insert('il_cert_cron_queue', $row);
53 }
54
55 public function removeFromQueue(int $id): void
56 {
57 $this->logger->debug(sprintf('START - Remove entry(id: "%s") from queue', $id));
58
59 $sql = 'DELETE FROM il_cert_cron_queue WHERE id = ' . $this->database->quote($id, 'integer');
60
61 $this->database->manipulate($sql);
62
63 $this->logger->debug(sprintf('END - Entry(id: "%s") deleted from queue', $id));
64 }
65
69 public function getAllEntriesFromQueue(): array
70 {
71 $this->logger->debug('START - Fetch all entries from queue');
72
73 $sql = 'SELECT * FROM il_cert_cron_queue';
74 $query = $this->database->query($sql);
75
76 $result = [];
77 while ($row = $this->database->fetchAssoc($query)) {
78 $this->logger->debug(sprintf(
79 'Queue entry found: "%s"',
80 json_encode($row, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT)
81 ));
82
83 $result[] = new ilCertificateQueueEntry(
84 (int) $row['obj_id'],
85 (int) $row['usr_id'],
86 $row['adapter_class'],
87 $row['state'],
88 (int) $row['template_id'],
89 (int) $row['started_timestamp'],
90 (int) $row['id']
91 );
92 }
93
94 $this->logger->debug(sprintf('END - All queue entries fetched(Total: "%s")', count($result)));
95
96 return $result;
97 }
98
99 public function removeFromQueueByUserId(int $user_id): void
100 {
101 $this->logger->debug(sprintf('START - Remove entries for user (usr_id: "%s") from queue', $user_id));
102
103 $sql = 'DELETE FROM il_cert_cron_queue WHERE usr_id = ' . $this->database->quote($user_id, 'integer');
104
105 $this->database->manipulate($sql);
106
107 $this->logger->debug(sprintf('END - Entries for user (usr_id: "%s") deleted from queue', $user_id));
108 }
109}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(private readonly ilDBInterface $database, private readonly ilLogger $logger)
addToQueue(ilCertificateQueueEntry $certificateQueueEntry)
Component logger with individual log levels by component id.
Interface ilDBInterface.