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