ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
BaseManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
38
42abstract class BaseManager
43{
47 public function __construct(protected ResourceBuilder $resource_builder, protected CollectionBuilder $collection_builder, protected RepositoryPreloader $preloader)
48 {
49 }
50
55 protected function checkZIP(bool|string $mimetype): void
56 {
57 if (!in_array($mimetype, ['application/zip', 'application/x-zip-compressed'])) {
58 throw new \LogicException("Cant create container resource since stream is not a ZIP");
59 }
60 }
61
66 public function publish(ResourceIdentification $rid): void
67 {
68 $this->resource_builder->publish($this->resource_builder->get($rid));
69 }
70
75 public function unpublish(ResourceIdentification $rid): void
76 {
77 $this->resource_builder->unpublish($this->resource_builder->get($rid));
78 }
79
80 protected function newStreamBased(
81 FileStream $stream,
82 ResourceStakeholder $stakeholder,
83 ResourceType $type,
84 ?string $revision_title = null
86 $info_resolver = new StreamInfoResolver(
87 $stream,
88 1,
89 $stakeholder->getOwnerOfNewResources(),
90 $revision_title ?? $stream->getMetadata()['uri']
91 );
92
93 $resource = $this->resource_builder->newFromStream(
94 $stream,
95 $info_resolver,
96 true,
97 $type
98 );
99 $resource->addStakeholder($stakeholder);
100 $this->applyConfidentiality($resource, $stakeholder);
101 $this->resource_builder->store($resource);
102
103 return $resource->getIdentification();
104 }
105
106 protected function applyConfidentiality(StorableResource $resource, ResourceStakeholder $stakeholder): void
107 {
108 if ($stakeholder instanceof ConfidentialStakeholder && $stakeholder->areNewResourcesConfidential()) {
109 $resource->setConfidential(true);
110 }
111 }
112
113 public function find(string $identification): ?ResourceIdentification
114 {
115 $resource_identification = new ResourceIdentification($identification);
116
117 if ($this->resource_builder->has($resource_identification)) {
118 return $resource_identification;
119 }
120
121 return null;
122 }
123
124 // Resources
125
127 {
128 $this->preloader->preload([$i->serialize()]);
129 return $this->resource_builder->get($i);
130 }
131
132 public function remove(ResourceIdentification $identification, ResourceStakeholder $stakeholder): void
133 {
134 $this->resource_builder->remove($this->resource_builder->get($identification), $stakeholder);
135 if (!$this->resource_builder->has($identification)) {
136 $this->collection_builder->notififyResourceDeletion($identification);
137 }
138 }
139
144 public function setConfidential(ResourceIdentification $identification, bool $confidential): void
145 {
146 $resource = $this->resource_builder->get($identification);
147 $resource->setConfidential($confidential);
148 $this->resource_builder->store($resource);
149 }
150
151 public function isConfidential(ResourceIdentification $identification): bool
152 {
153 return $this->resource_builder->get($identification)->isConfidential();
154 }
155
156 public function clone(ResourceIdentification $identification): ResourceIdentification
157 {
158 $resource = $this->resource_builder->clone($this->resource_builder->get($identification));
159
160 return $resource->getIdentification();
161 }
162
163 // Revision
164
171 public function appendNewRevision(
172 ResourceIdentification $identification,
173 UploadResult $result,
174 ResourceStakeholder $stakeholder,
175 ?string $revision_title = null,
176 bool $draft = false
177 ): Revision {
178 if ($result->isOK()) {
179 if (!$this->resource_builder->has($identification)) {
180 throw new \LogicException(
181 "Resource not found, can't append new version in: " . $identification->serialize()
182 );
183 }
184 $resource = $this->resource_builder->get($identification);
185 if ($resource->getType() === ResourceType::CONTAINER) {
186 $this->checkZIP($result->getMimeType());
187 }
188
189 $info_resolver = new UploadInfoResolver(
190 $result,
191 $resource->getMaxRevision(true) + 1,
192 $stakeholder->getOwnerOfNewResources(),
193 $revision_title ?? $result->getName()
194 );
195
196 $this->resource_builder->append(
197 $resource,
198 $result,
199 $info_resolver,
201 );
202 $resource->addStakeholder($stakeholder);
203
204 $this->resource_builder->store($resource);
205
206 return $resource->getCurrentRevisionIncludingDraft();
207 }
208 throw new \LogicException("Can't handle UploadResult: " . $result->getStatus()->getMessage());
209 }
210
217 public function replaceWithUpload(
218 ResourceIdentification $identification,
219 UploadResult $result,
220 ResourceStakeholder $stakeholder,
221 ?string $revision_title = null
222 ): Revision {
223 if ($result->isOK()) {
224 if (!$this->resource_builder->has($identification)) {
225 throw new \LogicException(
226 "Resource not found, can't append new version in: " . $identification->serialize()
227 );
228 }
229 $resource = $this->resource_builder->get($identification);
230 if ($resource->getType() === ResourceType::CONTAINER) {
231 $this->checkZIP($result->getMimeType());
232 }
233 if ($resource->getCurrentRevisionIncludingDraft()->getStatus() === RevisionStatus::DRAFT) {
234 throw new \LogicException(
235 "Can't replace DRAFT revision, use appendNewRevision instead to update the DRAFT"
236 );
237 }
238 $info_resolver = new UploadInfoResolver(
239 $result,
240 $resource->getMaxRevision(true) + 1,
241 $stakeholder->getOwnerOfNewResources(),
242 $revision_title ?? $result->getName()
243 );
244 $this->resource_builder->replaceWithUpload(
245 $resource,
246 $result,
247 $info_resolver
248 );
249 $resource->addStakeholder($stakeholder);
250
251 $this->resource_builder->store($resource);
252
253 return $resource->getCurrentRevisionIncludingDraft();
254 }
255 throw new \LogicException("Can't handle UploadResult: " . $result->getStatus()->getMessage());
256 }
257
265 ResourceIdentification $identification,
266 FileStream $stream,
267 ResourceStakeholder $stakeholder,
268 ?string $revision_title = null,
269 bool $draft = false
270 ): Revision {
271 if (!$this->resource_builder->has($identification)) {
272 throw new \LogicException(
273 "Resource not found, can't append new version in: " . $identification->serialize()
274 );
275 }
276
277 $resource = $this->resource_builder->get($identification);
278 if ($resource->getType() === ResourceType::CONTAINER) {
279 $this->checkZIP(mime_content_type($stream->getMetadata()['uri']));
280 }
281 $info_resolver = new StreamInfoResolver(
282 $stream,
283 $resource->getMaxRevision(true) + 1,
284 $stakeholder->getOwnerOfNewResources(),
285 $revision_title ?? $stream->getMetadata()['uri']
286 );
287
288 $this->resource_builder->appendFromStream(
289 $resource,
290 $stream,
291 $info_resolver,
293 true
294 );
295
296 $resource->addStakeholder($stakeholder);
297
298 $this->resource_builder->store($resource);
299
300 return $resource->getCurrentRevisionIncludingDraft();
301 }
302
309 public function replaceWithStream(
310 ResourceIdentification $identification,
311 FileStream $stream,
312 ResourceStakeholder $stakeholder,
313 ?string $revision_title = null
314 ): Revision {
315 if (!$this->resource_builder->has($identification)) {
316 throw new \LogicException(
317 "Resource not found, can't append new version in: " . $identification->serialize()
318 );
319 }
320
321 $resource = $this->resource_builder->get($identification);
322 if ($resource->getCurrentRevisionIncludingDraft()->getStatus() === RevisionStatus::DRAFT) {
323 throw new \LogicException(
324 "Can't replace DRAFT revision, use appendNewRevisionFromStream instead to update the DRAFT"
325 );
326 }
327 if ($resource->getType() === ResourceType::CONTAINER) {
328 $this->checkZIP(mime_content_type($stream->getMetadata()['uri']));
329 }
330 $info_resolver = new StreamInfoResolver(
331 $stream,
332 $resource->getMaxRevision(true) + 1,
333 $stakeholder->getOwnerOfNewResources(),
334 $revision_title ?? $stream->getMetadata()['uri']
335 );
336
337 $this->resource_builder->replaceWithStream(
338 $resource,
339 $stream,
340 $info_resolver,
341 true
342 );
343 $resource->addStakeholder($stakeholder);
344
345 $this->resource_builder->store($resource);
346
347 return $resource->getCurrentRevisionIncludingDraft();
348 }
349
350 public function getCurrentRevision(
351 ResourceIdentification $identification
352 ): Revision {
353 return $this->resource_builder->get($identification)->getCurrentRevision();
354 }
355
357 ResourceIdentification $identification
358 ): Revision {
359 return $this->resource_builder->get($identification)->getCurrentRevisionIncludingDraft();
360 }
361
362 public function updateRevision(Revision $revision): bool
363 {
364 $this->resource_builder->storeRevision($revision);
365
366 return true;
367 }
368
369 public function rollbackRevision(ResourceIdentification $identification, int $revision_number): bool
370 {
371 $resource = $this->resource_builder->get($identification);
372 $this->resource_builder->appendFromRevision($resource, $revision_number);
373 $this->resource_builder->store($resource);
374
375 return true;
376 }
377
378 public function removeRevision(ResourceIdentification $identification, int $revision_number): bool
379 {
380 $resource = $this->resource_builder->get($identification);
381 $this->resource_builder->removeRevision($resource, $revision_number);
382 $this->resource_builder->store($resource);
383
384 return true;
385 }
386}
getResource(ResourceIdentification $i)
publish(ResourceIdentification $rid)
@description Publish a resource.
Definition: BaseManager.php:66
__construct(protected ResourceBuilder $resource_builder, protected CollectionBuilder $collection_builder, protected RepositoryPreloader $preloader)
Manager constructor.
Definition: BaseManager.php:47
isConfidential(ResourceIdentification $identification)
removeRevision(ResourceIdentification $identification, int $revision_number)
setConfidential(ResourceIdentification $identification, bool $confidential)
@description Mark a resource as confidential (or remove the mark).
applyConfidentiality(StorableResource $resource, ResourceStakeholder $stakeholder)
replaceWithUpload(ResourceIdentification $identification, UploadResult $result, ResourceStakeholder $stakeholder, ?string $revision_title=null)
appendNewRevision(ResourceIdentification $identification, UploadResult $result, ResourceStakeholder $stakeholder, ?string $revision_title=null, bool $draft=false)
@description Append a new revision from an UploadResult.
newStreamBased(FileStream $stream, ResourceStakeholder $stakeholder, ResourceType $type, ?string $revision_title=null)
Definition: BaseManager.php:80
unpublish(ResourceIdentification $rid)
@description Unpublish a resource.
Definition: BaseManager.php:75
replaceWithStream(ResourceIdentification $identification, FileStream $stream, ResourceStakeholder $stakeholder, ?string $revision_title=null)
getCurrentRevision(ResourceIdentification $identification)
clone(ResourceIdentification $identification)
rollbackRevision(ResourceIdentification $identification, int $revision_number)
getCurrentRevisionIncludingDraft(ResourceIdentification $identification)
appendNewRevisionFromStream(ResourceIdentification $identification, FileStream $stream, ResourceStakeholder $stakeholder, ?string $revision_title=null, bool $draft=false)
@description Append a new revision from a stream.
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
The base interface for all filesystem streams.
Definition: FileStream.php:32
Stakeholders implementing this interface can mark the resources created for them as confidential,...
get(string $class_name)
has(string $class_name)
if(!file_exists('../ilias.ini.php'))