ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCertificateQueueRepository.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
8{
12 private $database;
13
17 private $logger;
18
24 {
25 $this->database = $database;
26 $this->logger = $logger;
27 }
28
32 public function addToQueue(ilCertificateQueueEntry $certificateQueueEntry)
33 {
34 $this->logger->info('START - Add new entry to certificate cron job queue');
35
36 $id = $this->database->nextId('il_cert_cron_queue');
37
38 $row = array(
39 'id' => array('integer', $id),
40 'obj_id' => array('integer', $certificateQueueEntry->getObjId()),
41 'usr_id' => array('integer', $certificateQueueEntry->getUserId()),
42 'adapter_class' => array('text', $certificateQueueEntry->getAdapterClass()),
43 'state' => array('text', $certificateQueueEntry->getState()),
44 'started_timestamp' => array('integer', $certificateQueueEntry->getStartedTimestamp()),
45 'template_id' => array('integer', $certificateQueueEntry->getTemplateId()),
46
47 );
48
49 $this->logger->debug(sprintf('Save queue entry with following values: %s', json_encode($row, JSON_PRETTY_PRINT)));
50 $this->logger->info(sprintf('END - Added entry to queue'));
51
52 $this->database->insert('il_cert_cron_queue', $row);
53 }
54
59 public function removeFromQueue($id)
60 {
61 $this->logger->info(sprintf('START - Remove entry(id: "%s") from queue', $id));
62
63 $sql = 'DELETE FROM il_cert_cron_queue WHERE id = ' . $this->database->quote($id, 'integer');
64
65 $this->database->manipulate($sql);
66
67 $this->logger->info(sprintf('END - Entry(id: "%s") deleted from queue', $id));
68 }
69
73 public function getAllEntriesFromQueue()
74 {
75 $this->logger->info('START - Fetch all entries from queue');
76
77 $sql = 'SELECT * FROM il_cert_cron_queue';
78 $query = $this->database->query($sql);
79
80 $result = array();
81 while ($row = $this->database->fetchAssoc($query)) {
82 $this->logger->debug(sprintf('Queue entry found: "%s"', json_encode($row, JSON_PRETTY_PRINT)));
83
85 $row['obj_id'],
86 $row['usr_id'],
87 $row['adapter_class'],
88 $row['state'],
89 $row['template_id'],
90 $row['started_timestamp'],
91 $row['id']
92 );
93 }
94
95 $this->logger->info(sprintf('END - All queue entries fetched(Total: "%s")', count($result)));
96
97 return $result;
98 }
99
103 public function removeFromQueueByUserId(int $user_id)
104 {
105 $this->logger->info(sprintf('START - Remove entries for user(user_id: "%s") from queue', $user_id));
106
107 $sql = 'DELETE FROM il_cert_cron_queue WHERE usr_id = ' . $this->database->quote($user_id, 'integer');
108
109 $this->database->manipulate($sql);
110
111 $this->logger->info(sprintf('END - Entries for user(user_id: "%s") deleted from queue', $user_id));
112 }
113}
$result
An exception for terminatinating execution or to throw for unit testing.
addToQueue(ilCertificateQueueEntry $certificateQueueEntry)
__construct(\ilDBInterface $database, ilLogger $logger)
Component logger with individual log levels by component id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$query