ILIAS  release_8 Revision v8.24
Manager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
34
40{
44
48 public function __construct(
52 ) {
53 $this->resource_builder = $resource_builder;
54 $this->collection_builder = $collection_builder;
55 $this->preloader = $preloader;
56 }
57
58 public function upload(
59 UploadResult $result,
60 ResourceStakeholder $stakeholder,
61 string $revision_title = null
63 if ($result->isOK()) {
64 $info_resolver = new UploadInfoResolver(
65 $result,
66 1,
67 $stakeholder->getOwnerOfNewResources(),
68 $revision_title ?? $result->getName()
69 );
70
71 $resource = $this->resource_builder->new(
72 $result,
73 $info_resolver
74 );
75 $resource->addStakeholder($stakeholder);
76 $this->resource_builder->store($resource);
77
78 return $resource->getIdentification();
79 }
80 throw new \LogicException("Can't handle UploadResult: " . $result->getStatus()->getMessage());
81 }
82
83 public function stream(
84 FileStream $stream,
85 ResourceStakeholder $stakeholder,
86 string $revision_title = null
88 $info_resolver = new StreamInfoResolver(
89 $stream,
90 1,
91 $stakeholder->getOwnerOfNewResources(),
92 $revision_title ?? $stream->getMetadata()['uri']
93 );
94
95 $resource = $this->resource_builder->newFromStream(
96 $stream,
97 $info_resolver,
98 true
99 );
100 $resource->addStakeholder($stakeholder);
101 $this->resource_builder->store($resource);
102
103 return $resource->getIdentification();
104 }
105
106 public function find(string $identification): ?ResourceIdentification
107 {
108 $resource_identification = new ResourceIdentification($identification);
109
110 if ($this->resource_builder->has($resource_identification)) {
111 return $resource_identification;
112 }
113
114 return null;
115 }
116
117 // Resources
118
120 {
121 $this->preloader->preload([$i->serialize()]);
122 return $this->resource_builder->get($i);
123 }
124
125
126 public function remove(ResourceIdentification $identification, ResourceStakeholder $stakeholder): void
127 {
128 $this->resource_builder->remove($this->resource_builder->get($identification), $stakeholder);
129 if (!$this->resource_builder->has($identification)) {
130 $this->collection_builder->notififyResourceDeletion($identification);
131 }
132 }
133
134 public function clone(ResourceIdentification $identification): ResourceIdentification
135 {
136 $resource = $this->resource_builder->clone($this->resource_builder->get($identification));
137
138 return $resource->getIdentification();
139 }
140
141 // Revision
142
143 public function appendNewRevision(
144 ResourceIdentification $identification,
145 UploadResult $result,
146 ResourceStakeholder $stakeholder,
147 string $revision_title = null
148 ): Revision {
149 if ($result->isOK()) {
150 if (!$this->resource_builder->has($identification)) {
151 throw new \LogicException(
152 "Resource not found, can't append new version in: " . $identification->serialize()
153 );
154 }
155 $resource = $this->resource_builder->get($identification);
156 $info_resolver = new UploadInfoResolver(
157 $result,
158 $resource->getMaxRevision() + 1,
159 $stakeholder->getOwnerOfNewResources(),
160 $revision_title ?? $result->getName()
161 );
162
163 $this->resource_builder->append(
164 $resource,
165 $result,
166 $info_resolver
167 );
168 $resource->addStakeholder($stakeholder);
169
170 $this->resource_builder->store($resource);
171
172 return $resource->getCurrentRevision();
173 }
174 throw new \LogicException("Can't handle UploadResult: " . $result->getStatus()->getMessage());
175 }
176
177 public function replaceWithUpload(
178 ResourceIdentification $identification,
179 UploadResult $result,
180 ResourceStakeholder $stakeholder,
181 string $revision_title = null
182 ): Revision {
183 if ($result->isOK()) {
184 if (!$this->resource_builder->has($identification)) {
185 throw new \LogicException(
186 "Resource not found, can't append new version in: " . $identification->serialize()
187 );
188 }
189 $resource = $this->resource_builder->get($identification);
190 $info_resolver = new UploadInfoResolver(
191 $result,
192 $resource->getMaxRevision() + 1,
193 $stakeholder->getOwnerOfNewResources(),
194 $revision_title ?? $result->getName()
195 );
196 $this->resource_builder->replaceWithUpload(
197 $resource,
198 $result,
199 $info_resolver
200 );
201 $resource->addStakeholder($stakeholder);
202
203 $this->resource_builder->store($resource);
204
205 return $resource->getCurrentRevision();
206 }
207 throw new \LogicException("Can't handle UploadResult: " . $result->getStatus()->getMessage());
208 }
209
211 ResourceIdentification $identification,
212 FileStream $stream,
213 ResourceStakeholder $stakeholder,
214 string $revision_title = null
215 ): Revision {
216 if (!$this->resource_builder->has($identification)) {
217 throw new \LogicException(
218 "Resource not found, can't append new version in: " . $identification->serialize()
219 );
220 }
221
222 $resource = $this->resource_builder->get($identification);
223 $info_resolver = new StreamInfoResolver(
224 $stream,
225 $resource->getMaxRevision() + 1,
226 $stakeholder->getOwnerOfNewResources(),
227 $revision_title ?? $stream->getMetadata()['uri']
228 );
229
230 $this->resource_builder->appendFromStream(
231 $resource,
232 $stream,
233 $info_resolver,
234 true
235 );
236 $resource->addStakeholder($stakeholder);
237
238 $this->resource_builder->store($resource);
239
240 return $resource->getCurrentRevision();
241 }
242
243 public function replaceWithStream(
244 ResourceIdentification $identification,
245 FileStream $stream,
246 ResourceStakeholder $stakeholder,
247 string $revision_title = null
248 ): Revision {
249 if (!$this->resource_builder->has($identification)) {
250 throw new \LogicException(
251 "Resource not found, can't append new version in: " . $identification->serialize()
252 );
253 }
254
255 $resource = $this->resource_builder->get($identification);
256 $info_resolver = new StreamInfoResolver(
257 $stream,
258 $resource->getMaxRevision() + 1,
259 $stakeholder->getOwnerOfNewResources(),
260 $revision_title ?? $stream->getMetadata()['uri']
261 );
262
263 $this->resource_builder->replaceWithStream(
264 $resource,
265 $stream,
266 $info_resolver,
267 true
268 );
269 $resource->addStakeholder($stakeholder);
270
271 $this->resource_builder->store($resource);
272
273 return $resource->getCurrentRevision();
274 }
275
276 public function getCurrentRevision(ResourceIdentification $identification): Revision
277 {
278 return $this->resource_builder->get($identification)->getCurrentRevision();
279 }
280
281 public function updateRevision(Revision $revision): bool
282 {
283 $this->resource_builder->storeRevision($revision);
284
285 return true;
286 }
287
288 public function rollbackRevision(ResourceIdentification $identification, int $revision_number): bool
289 {
290 $resource = $this->resource_builder->get($identification);
291 $this->resource_builder->appendFromRevision($resource, $revision_number);
292 $this->resource_builder->store($resource);
293
294 return true;
295 }
296
297 public function removeRevision(ResourceIdentification $identification, int $revision_number): bool
298 {
299 $resource = $this->resource_builder->get($identification);
300 $this->resource_builder->removeRevision($resource, $revision_number);
301 $this->resource_builder->store($resource);
302
303 return true;
304 }
305}
clone(ResourceIdentification $identification)
Definition: Manager.php:134
rollbackRevision(ResourceIdentification $identification, int $revision_number)
Definition: Manager.php:288
find(string $identification)
Definition: Manager.php:106
getCurrentRevision(ResourceIdentification $identification)
Definition: Manager.php:276
appendNewRevision(ResourceIdentification $identification, UploadResult $result, ResourceStakeholder $stakeholder, string $revision_title=null)
Definition: Manager.php:143
replaceWithStream(ResourceIdentification $identification, FileStream $stream, ResourceStakeholder $stakeholder, string $revision_title=null)
Definition: Manager.php:243
removeRevision(ResourceIdentification $identification, int $revision_number)
Definition: Manager.php:297
CollectionBuilder $collection_builder
Definition: Manager.php:42
getResource(ResourceIdentification $i)
Definition: Manager.php:119
__construct(ResourceBuilder $resource_builder, CollectionBuilder $collection_builder, RepositoryPreloader $preloader)
Manager constructor.
Definition: Manager.php:48
RepositoryPreloader $preloader
Definition: Manager.php:43
stream(FileStream $stream, ResourceStakeholder $stakeholder, string $revision_title=null)
Definition: Manager.php:83
appendNewRevisionFromStream(ResourceIdentification $identification, FileStream $stream, ResourceStakeholder $stakeholder, string $revision_title=null)
Definition: Manager.php:210
upload(UploadResult $result, ResourceStakeholder $stakeholder, string $revision_title=null)
Definition: Manager.php:58
updateRevision(Revision $revision)
Definition: Manager.php:281
replaceWithUpload(ResourceIdentification $identification, UploadResult $result, ResourceStakeholder $stakeholder, string $revision_title=null)
Definition: Manager.php:177
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
$i
Definition: metadata.php:41
has(string $class_name)