ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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
42 public function __construct(protected \ilDBInterface $db)
43 {
44 }
45
49 public function getNamesForLocking(): array
50 {
51 return [self::TABLE_NAME];
52 }
53
57 public function blank(): Information
58 {
59 return new FileInformation();
60 }
61
65 public function store(Information $information, Revision $revision): void
66 {
67 $rid = $revision->getIdentification()->serialize();
68 $version = $revision->getVersionNumber();
69
70 $this->db->replace(
71 self::TABLE_NAME,
72 [
73 self::IDENTIFICATION => ['text', $rid],
74 'version_number' => ['integer', $version]
75 ],
76 [
77 'title' => ['text', $information->getTitle()],
78 'mime_type' => ['text', $information->getMimeType()],
79 'suffix' => ['text', $information->getSuffix()],
80 'size' => ['integer', $information->getSize()],
81 'creation_date' => ['integer', $information->getCreationDate()->getTimestamp()]
82 ]
83 );
84
85 $this->cache[$rid][$version] = $information;
86 }
87
91 public function get(Revision $revision): Information
92 {
93 $rid = $revision->getIdentification()->serialize();
94 if (isset($this->cache[$rid][$revision->getVersionNumber()])) {
95 return $this->cache[$rid][$revision->getVersionNumber()];
96 }
97 $r = $this->db->queryF(
98 "SELECT * FROM " . self::TABLE_NAME . " WHERE " . self::IDENTIFICATION . " = %s AND version_number = %s",
99 [
100 'text',
101 'integer'
102 ],
103 [
104 $rid,
105 $revision->getVersionNumber()
106 ]
107 );
108
109 $d = $this->db->fetchAssoc($r);
110 $i = $this->getFileInfoFromArrayData($d);
111
112 $this->cache[$rid][$revision->getVersionNumber()] = $i;
113
114 return $i;
115 }
116
117 public function delete(Information $information, Revision $revision): void
118 {
119 $rid = $revision->getIdentification()->serialize();
120 $this->db->manipulateF(
121 "DELETE FROM " . self::TABLE_NAME . " WHERE " . self::IDENTIFICATION . " = %s AND version_number = %s",
122 [
123 'text',
124 'integer'
125 ],
126 [
127 $rid,
128 $revision->getVersionNumber()
129 ]
130 );
131 unset($this->cache[$rid][$revision->getVersionNumber()]);
132 }
133
134 public function preload(array $identification_strings): void
135 {
136 $r = $this->db->query(
137 "SELECT * FROM " . self::TABLE_NAME . " WHERE " . $this->db->in(
138 self::IDENTIFICATION,
139 $identification_strings,
140 false,
141 'text'
142 )
143 );
144
145 while ($d = $this->db->fetchAssoc($r)) {
146 $this->populateFromArray($d);
147 }
148 }
149
150 public function populateFromArray(array $data): void
151 {
152 $this->cache[$data['rid']][$data['version_number']] = $this->getFileInfoFromArrayData($data);
153 }
154
156 {
157 $i = new FileInformation();
158 $i->setTitle((string) $data['title']);
159 $i->setSize((int) $data['size']);
160 $i->setMimeType((string) $data['mime_type']);
161 $i->setSuffix((string) $data['suffix']);
162 $i->setCreationDate((new \DateTimeImmutable())->setTimestamp((int) ($data['creation_date'] ?? 0)));
163
164 return $i;
165 }
166}
$version
Definition: plugin.php:24
store(Information $information, Revision $revision)
@inheritDoc
Interface ilDBInterface.