ILIAS  release_8 Revision v8.24
InformationDBRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26
33{
34 public const TABLE_NAME = 'il_resource_info';
35 public const IDENTIFICATION = 'rid';
36
40 protected array $cache = [];
41 protected \ilDBInterface $db;
42
43 public function __construct(\ilDBInterface $db)
44 {
45 $this->db = $db;
46 }
47
51 public function getNamesForLocking(): array
52 {
53 return [self::TABLE_NAME];
54 }
55
59 public function blank(): Information
60 {
61 return new FileInformation();
62 }
63
67 public function store(Information $information, Revision $revision): void
68 {
69 $rid = $revision->getIdentification()->serialize();
70 $r = $this->db->queryF(
71 "SELECT " . self::IDENTIFICATION . " FROM " . self::TABLE_NAME . " WHERE " . self::IDENTIFICATION . " = %s AND version_number = %s",
72 [
73 'text',
74 'integer'
75 ],
76 [
77 $rid,
78 $revision->getVersionNumber()
79 ]
80 );
81
82 if ($r->numRows() > 0) {
83 // UPDATE
84 $this->db->update(
85 self::TABLE_NAME,
86 [
87 'title' => ['text', $information->getTitle()],
88 'mime_type' => ['text', $information->getMimeType()],
89 'suffix' => ['text', $information->getSuffix()],
90 'size' => ['integer', $information->getSize()],
91 'creation_date' => ['integer', $information->getCreationDate()->getTimestamp()],
92 ],
93 [
94 self::IDENTIFICATION => ['text', $rid],
95 'version_number' => ['integer', $revision->getVersionNumber()]
96 ]
97 );
98 } else {
99 // CREATE
100 $this->db->insert(
101 self::TABLE_NAME,
102 [
103 self::IDENTIFICATION => ['text', $rid],
104 'version_number' => ['integer', $revision->getVersionNumber()],
105 'title' => ['text', $information->getTitle()],
106 'mime_type' => ['text', $information->getMimeType()],
107 'suffix' => ['text', $information->getSuffix()],
108 'size' => ['integer', $information->getSize()],
109 'creation_date' => ['integer', $information->getCreationDate()->getTimestamp()],
110 ]
111 );
112 }
113 $this->cache[$rid][$revision->getVersionNumber()] = $information;
114 }
115
119 public function get(Revision $revision): Information
120 {
121 $rid = $revision->getIdentification()->serialize();
122 if (isset($this->cache[$rid][$revision->getVersionNumber()])) {
123 return $this->cache[$rid][$revision->getVersionNumber()];
124 }
125 $r = $this->db->queryF(
126 "SELECT * FROM " . self::TABLE_NAME . " WHERE " . self::IDENTIFICATION . " = %s AND version_number = %s",
127 [
128 'text',
129 'integer'
130 ],
131 [
132 $rid,
133 $revision->getVersionNumber()
134 ]
135 );
136
137 $d = $this->db->fetchAssoc($r);
139
140 $this->cache[$rid][$revision->getVersionNumber()] = $i;
141
142 return $i;
143 }
144
145 public function delete(Information $information, Revision $revision): void
146 {
147 $rid = $revision->getIdentification()->serialize();
148 $this->db->manipulateF(
149 "DELETE FROM " . self::TABLE_NAME . " WHERE " . self::IDENTIFICATION . " = %s AND version_number = %s",
150 [
151 'text',
152 'integer'
153 ],
154 [
155 $rid,
156 $revision->getVersionNumber()
157 ]
158 );
159 unset($this->cache[$rid][$revision->getVersionNumber()]);
160 }
161
162 public function preload(array $identification_strings): void
163 {
164 $r = $this->db->query(
165 "SELECT * FROM " . self::TABLE_NAME . " WHERE " . $this->db->in(
166 self::IDENTIFICATION,
167 $identification_strings,
168 false,
169 'text'
170 )
171 );
172
173 while ($d = $this->db->fetchAssoc($r)) {
174 $this->populateFromArray($d);
175 }
176 }
177
178 public function populateFromArray(array $data): void
179 {
180 $this->cache[$data['rid']][$data['version_number']] = $this->getFileInfoFromArrayData($data);
181 }
182
184 {
185 $i = new FileInformation();
186 $i->setTitle((string)$data['title']);
187 $i->setSize((int)$data['size']);
188 $i->setMimeType((string)$data['mime_type']);
189 $i->setSuffix((string)$data['suffix']);
190 $i->setCreationDate((new \DateTimeImmutable())->setTimestamp((int)$data['creation_date'] ?? 0));
191
192 return $i;
193 }
194}
store(Information $information, Revision $revision)
@inheritDoc
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
Interface ilDBInterface.
$i
Definition: metadata.php:41