ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ILIAS\ResourceStorage\Manager\BaseManager Class Reference
+ Inheritance diagram for ILIAS\ResourceStorage\Manager\BaseManager:
+ Collaboration diagram for ILIAS\ResourceStorage\Manager\BaseManager:

Public Member Functions

 __construct (ResourceBuilder $resource_builder, CollectionBuilder $collection_builder, RepositoryPreloader $preloader)
 Manager constructor. More...
 
 publish (ResourceIdentification $rid)
 Publish a resource. More...
 
 unpublish (ResourceIdentification $rid)
 Unpublish a resource. More...
 
 find (string $identification)
 
 getResource (ResourceIdentification $i)
 
 remove (ResourceIdentification $identification, ResourceStakeholder $stakeholder)
 
 clone (ResourceIdentification $identification)
 
 appendNewRevision (ResourceIdentification $identification, UploadResult $result, ResourceStakeholder $stakeholder, string $revision_title=null, bool $draft=false)
 Append a new revision from an UploadResult. More...
 
 replaceWithUpload (ResourceIdentification $identification, UploadResult $result, ResourceStakeholder $stakeholder, string $revision_title=null)
 
 appendNewRevisionFromStream (ResourceIdentification $identification, FileStream $stream, ResourceStakeholder $stakeholder, string $revision_title=null, bool $draft=false)
 Append a new revision from a stream. More...
 
 replaceWithStream (ResourceIdentification $identification, FileStream $stream, ResourceStakeholder $stakeholder, string $revision_title=null)
 
 getCurrentRevision (ResourceIdentification $identification)
 
 getCurrentRevisionIncludingDraft (ResourceIdentification $identification)
 
 updateRevision (Revision $revision)
 
 rollbackRevision (ResourceIdentification $identification, int $revision_number)
 
 removeRevision (ResourceIdentification $identification, int $revision_number)
 

Protected Member Functions

 checkZIP (bool|string $mimetype)
 
 newStreamBased (FileStream $stream, ResourceStakeholder $stakeholder, ResourceType $type, string $revision_title=null)
 

Protected Attributes

ResourceBuilder $resource_builder
 
CollectionBuilder $collection_builder
 
RepositoryPreloader $preloader
 

Detailed Description

Author
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s.ch

Definition at line 40 of file BaseManager.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\ResourceStorage\Manager\BaseManager::__construct ( ResourceBuilder  $resource_builder,
CollectionBuilder  $collection_builder,
RepositoryPreloader  $preloader 
)

Manager constructor.

Definition at line 49 of file BaseManager.php.

References ILIAS\ResourceStorage\Manager\BaseManager\$collection_builder, ILIAS\ResourceStorage\Manager\BaseManager\$preloader, and ILIAS\ResourceStorage\Manager\BaseManager\$resource_builder.

53  {
54  $this->resource_builder = $resource_builder;
55  $this->collection_builder = $collection_builder;
56  $this->preloader = $preloader;
57  }

Member Function Documentation

◆ appendNewRevision()

ILIAS\ResourceStorage\Manager\BaseManager::appendNewRevision ( ResourceIdentification  $identification,
UploadResult  $result,
ResourceStakeholder  $stakeholder,
string  $revision_title = null,
bool  $draft = false 
)

Append a new revision from an UploadResult.

By passing $draft = true, the revision will be created as a DRAFT on top of the current revision. Consumers will always use the latest published revision. Appending new Revisions is not possible if the latest revision is already a DRAFT. In this case, the DRAFT will be updated.

Definition at line 155 of file BaseManager.php.

References ILIAS\ResourceStorage\Manager\BaseManager\checkZIP(), ILIAS\ResourceStorage\Resource\CONTAINER, ILIAS\ResourceStorage\Revision\DRAFT, ILIAS\FileUpload\DTO\UploadResult\getMimeType(), ILIAS\FileUpload\DTO\UploadResult\getName(), ILIAS\ResourceStorage\Stakeholder\ResourceStakeholder\getOwnerOfNewResources(), ILIAS\FileUpload\DTO\UploadResult\getStatus(), ILIAS\FileUpload\DTO\UploadResult\isOK(), and ILIAS\ResourceStorage\Identification\AbstractIdentification\serialize().

161  : Revision {
162  if ($result->isOK()) {
163  if (!$this->resource_builder->has($identification)) {
164  throw new \LogicException(
165  "Resource not found, can't append new version in: " . $identification->serialize()
166  );
167  }
168  $resource = $this->resource_builder->get($identification);
169  if ($resource->getType() === ResourceType::CONTAINER) {
170  $this->checkZIP($result->getMimeType());
171  }
172 
173  $info_resolver = new UploadInfoResolver(
174  $result,
175  $resource->getMaxRevision(true) + 1,
176  $stakeholder->getOwnerOfNewResources(),
177  $revision_title ?? $result->getName()
178  );
179 
180  $this->resource_builder->append(
181  $resource,
182  $result,
183  $info_resolver,
184  $draft ? RevisionStatus::DRAFT : RevisionStatus::PUBLISHED
185  );
186  $resource->addStakeholder($stakeholder);
187 
188  $this->resource_builder->store($resource);
189 
190  return $resource->getCurrentRevisionIncludingDraft();
191  }
192  throw new \LogicException("Can't handle UploadResult: " . $result->getStatus()->getMessage());
193  }
+ Here is the call graph for this function:

◆ appendNewRevisionFromStream()

ILIAS\ResourceStorage\Manager\BaseManager::appendNewRevisionFromStream ( ResourceIdentification  $identification,
FileStream  $stream,
ResourceStakeholder  $stakeholder,
string  $revision_title = null,
bool  $draft = false 
)

Append a new revision from a stream.

By passing $draft = true, the revision will be created as a DRAFT on top of the current revision. Consumers will always use the latest published revision. Appending new Revisions is not possible if the latest revision is already a DRAFT. In this case, the DRAFT will be updated.

Definition at line 248 of file BaseManager.php.

References ILIAS\ResourceStorage\Manager\BaseManager\checkZIP(), ILIAS\ResourceStorage\Resource\CONTAINER, ILIAS\ResourceStorage\Revision\DRAFT, ILIAS\ResourceStorage\Stakeholder\ResourceStakeholder\getOwnerOfNewResources(), and ILIAS\ResourceStorage\Identification\AbstractIdentification\serialize().

254  : Revision {
255  if (!$this->resource_builder->has($identification)) {
256  throw new \LogicException(
257  "Resource not found, can't append new version in: " . $identification->serialize()
258  );
259  }
260 
261  $resource = $this->resource_builder->get($identification);
262  if ($resource->getType() === ResourceType::CONTAINER) {
263  $this->checkZIP(mime_content_type($stream->getMetadata()['uri']));
264  }
265  $info_resolver = new StreamInfoResolver(
266  $stream,
267  $resource->getMaxRevision(true) + 1,
268  $stakeholder->getOwnerOfNewResources(),
269  $revision_title ?? $stream->getMetadata()['uri']
270  );
271 
272  $this->resource_builder->appendFromStream(
273  $resource,
274  $stream,
275  $info_resolver,
276  $draft ? RevisionStatus::DRAFT : RevisionStatus::PUBLISHED,
277  true
278  );
279 
280  $resource->addStakeholder($stakeholder);
281 
282  $this->resource_builder->store($resource);
283 
284  return $resource->getCurrentRevisionIncludingDraft();
285  }
+ Here is the call graph for this function:

◆ checkZIP()

ILIAS\ResourceStorage\Manager\BaseManager::checkZIP ( bool|string  $mimetype)
protected
Parameters
bool | string$mimetype
Returns
void

Definition at line 63 of file BaseManager.php.

Referenced by ILIAS\ResourceStorage\Manager\BaseManager\appendNewRevision(), ILIAS\ResourceStorage\Manager\BaseManager\appendNewRevisionFromStream(), ILIAS\ResourceStorage\Manager\ContainerManager\containerFromStream(), ILIAS\ResourceStorage\Manager\ContainerManager\containerFromUpload(), ILIAS\ResourceStorage\Manager\BaseManager\replaceWithStream(), and ILIAS\ResourceStorage\Manager\BaseManager\replaceWithUpload().

63  : void
64  {
65  if (!in_array($mimetype, ['application/zip', 'application/x-zip-compressed'])) {
66  throw new \LogicException("Cant create container resource since stream is not a ZIP");
67  }
68  }
+ Here is the caller graph for this function:

◆ clone()

ILIAS\ResourceStorage\Manager\BaseManager::clone ( ResourceIdentification  $identification)

Definition at line 140 of file BaseManager.php.

140  : ResourceIdentification
141  {
142  $resource = $this->resource_builder->clone($this->resource_builder->get($identification));
143 
144  return $resource->getIdentification();
145  }

◆ find()

ILIAS\ResourceStorage\Manager\BaseManager::find ( string  $identification)

Definition at line 113 of file BaseManager.php.

113  : ?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  }

◆ getCurrentRevision()

ILIAS\ResourceStorage\Manager\BaseManager::getCurrentRevision ( ResourceIdentification  $identification)

Definition at line 334 of file BaseManager.php.

336  : Revision {
337  return $this->resource_builder->get($identification)->getCurrentRevision();
338  }

◆ getCurrentRevisionIncludingDraft()

ILIAS\ResourceStorage\Manager\BaseManager::getCurrentRevisionIncludingDraft ( ResourceIdentification  $identification)

Definition at line 340 of file BaseManager.php.

342  : Revision {
343  return $this->resource_builder->get($identification)->getCurrentRevisionIncludingDraft();
344  }

◆ getResource()

ILIAS\ResourceStorage\Manager\BaseManager::getResource ( ResourceIdentification  $i)

Definition at line 126 of file BaseManager.php.

References ILIAS\ResourceStorage\Identification\AbstractIdentification\serialize().

Referenced by ILIAS\ResourceStorage\Manager\ContainerManager\addStreamToContainer(), ILIAS\ResourceStorage\Manager\ContainerManager\addUploadToContainer(), ILIAS\ResourceStorage\Manager\ContainerManager\createDirectoryInsideContainer(), and ILIAS\ResourceStorage\Manager\ContainerManager\removePathInsideContainer().

126  : StorableResource
127  {
128  $this->preloader->preload([$i->serialize()]);
129  return $this->resource_builder->get($i);
130  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ newStreamBased()

ILIAS\ResourceStorage\Manager\BaseManager::newStreamBased ( FileStream  $stream,
ResourceStakeholder  $stakeholder,
ResourceType  $type,
string  $revision_title = null 
)
protected

Definition at line 88 of file BaseManager.php.

References ILIAS\ResourceStorage\Stakeholder\ResourceStakeholder\getOwnerOfNewResources().

Referenced by ILIAS\ResourceStorage\Manager\ContainerManager\containerFromStream(), and ILIAS\ResourceStorage\Manager\Manager\stream().

93  : ResourceIdentification {
94  $info_resolver = new StreamInfoResolver(
95  $stream,
96  1,
97  $stakeholder->getOwnerOfNewResources(),
98  $revision_title ?? $stream->getMetadata()['uri']
99  );
100 
101  $resource = $this->resource_builder->newFromStream(
102  $stream,
103  $info_resolver,
104  true,
105  $type
106  );
107  $resource->addStakeholder($stakeholder);
108  $this->resource_builder->store($resource);
109 
110  return $resource->getIdentification();
111  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ publish()

ILIAS\ResourceStorage\Manager\BaseManager::publish ( ResourceIdentification  $rid)

Publish a resource.

A resource can contain a maximum of one revision in DRAFT on top status. This method can be used to publish this revision. If the latest revision is already published, nothing changes.

Definition at line 74 of file BaseManager.php.

74  : void
75  {
76  $this->resource_builder->publish($this->resource_builder->get($rid));
77  }

◆ remove()

ILIAS\ResourceStorage\Manager\BaseManager::remove ( ResourceIdentification  $identification,
ResourceStakeholder  $stakeholder 
)

Definition at line 132 of file BaseManager.php.

132  : 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  }

◆ removeRevision()

ILIAS\ResourceStorage\Manager\BaseManager::removeRevision ( ResourceIdentification  $identification,
int  $revision_number 
)

Definition at line 362 of file BaseManager.php.

362  : bool
363  {
364  $resource = $this->resource_builder->get($identification);
365  $this->resource_builder->removeRevision($resource, $revision_number);
366  $this->resource_builder->store($resource);
367 
368  return true;
369  }

◆ replaceWithStream()

ILIAS\ResourceStorage\Manager\BaseManager::replaceWithStream ( ResourceIdentification  $identification,
FileStream  $stream,
ResourceStakeholder  $stakeholder,
string  $revision_title = null 
)
Exceptions

Definition at line 293 of file BaseManager.php.

References ILIAS\ResourceStorage\Manager\BaseManager\checkZIP(), ILIAS\ResourceStorage\Resource\CONTAINER, ILIAS\ResourceStorage\Revision\DRAFT, ILIAS\ResourceStorage\Stakeholder\ResourceStakeholder\getOwnerOfNewResources(), and ILIAS\ResourceStorage\Identification\AbstractIdentification\serialize().

298  : Revision {
299  if (!$this->resource_builder->has($identification)) {
300  throw new \LogicException(
301  "Resource not found, can't append new version in: " . $identification->serialize()
302  );
303  }
304 
305  $resource = $this->resource_builder->get($identification);
306  if ($resource->getCurrentRevisionIncludingDraft()->getStatus() === RevisionStatus::DRAFT) {
307  throw new \LogicException(
308  "Can't replace DRAFT revision, use appendNewRevisionFromStream instead to update the DRAFT"
309  );
310  }
311  if ($resource->getType() === ResourceType::CONTAINER) {
312  $this->checkZIP(mime_content_type($stream->getMetadata()['uri']));
313  }
314  $info_resolver = new StreamInfoResolver(
315  $stream,
316  $resource->getMaxRevision(true) + 1,
317  $stakeholder->getOwnerOfNewResources(),
318  $revision_title ?? $stream->getMetadata()['uri']
319  );
320 
321  $this->resource_builder->replaceWithStream(
322  $resource,
323  $stream,
324  $info_resolver,
325  true
326  );
327  $resource->addStakeholder($stakeholder);
328 
329  $this->resource_builder->store($resource);
330 
331  return $resource->getCurrentRevisionIncludingDraft();
332  }
+ Here is the call graph for this function:

◆ replaceWithUpload()

ILIAS\ResourceStorage\Manager\BaseManager::replaceWithUpload ( ResourceIdentification  $identification,
UploadResult  $result,
ResourceStakeholder  $stakeholder,
string  $revision_title = null 
)
Exceptions

Definition at line 201 of file BaseManager.php.

References ILIAS\ResourceStorage\Manager\BaseManager\checkZIP(), ILIAS\ResourceStorage\Resource\CONTAINER, ILIAS\ResourceStorage\Revision\DRAFT, ILIAS\FileUpload\DTO\UploadResult\getMimeType(), ILIAS\FileUpload\DTO\UploadResult\getName(), ILIAS\ResourceStorage\Stakeholder\ResourceStakeholder\getOwnerOfNewResources(), ILIAS\FileUpload\DTO\UploadResult\getStatus(), ILIAS\FileUpload\DTO\UploadResult\isOK(), and ILIAS\ResourceStorage\Identification\AbstractIdentification\serialize().

206  : Revision {
207  if ($result->isOK()) {
208  if (!$this->resource_builder->has($identification)) {
209  throw new \LogicException(
210  "Resource not found, can't append new version in: " . $identification->serialize()
211  );
212  }
213  $resource = $this->resource_builder->get($identification);
214  if ($resource->getType() === ResourceType::CONTAINER) {
215  $this->checkZIP($result->getMimeType());
216  }
217  if ($resource->getCurrentRevisionIncludingDraft()->getStatus() === RevisionStatus::DRAFT) {
218  throw new \LogicException(
219  "Can't replace DRAFT revision, use appendNewRevision instead to update the DRAFT"
220  );
221  }
222  $info_resolver = new UploadInfoResolver(
223  $result,
224  $resource->getMaxRevision(true) + 1,
225  $stakeholder->getOwnerOfNewResources(),
226  $revision_title ?? $result->getName()
227  );
228  $this->resource_builder->replaceWithUpload(
229  $resource,
230  $result,
231  $info_resolver
232  );
233  $resource->addStakeholder($stakeholder);
234 
235  $this->resource_builder->store($resource);
236 
237  return $resource->getCurrentRevisionIncludingDraft();
238  }
239  throw new \LogicException("Can't handle UploadResult: " . $result->getStatus()->getMessage());
240  }
+ Here is the call graph for this function:

◆ rollbackRevision()

ILIAS\ResourceStorage\Manager\BaseManager::rollbackRevision ( ResourceIdentification  $identification,
int  $revision_number 
)

Definition at line 353 of file BaseManager.php.

353  : bool
354  {
355  $resource = $this->resource_builder->get($identification);
356  $this->resource_builder->appendFromRevision($resource, $revision_number);
357  $this->resource_builder->store($resource);
358 
359  return true;
360  }

◆ unpublish()

ILIAS\ResourceStorage\Manager\BaseManager::unpublish ( ResourceIdentification  $rid)

Unpublish a resource.

The newest revision of a resource is set to the DRAFT status. If the latest revision is already in DRAFT, nothing changes.

Definition at line 83 of file BaseManager.php.

83  : void
84  {
85  $this->resource_builder->unpublish($this->resource_builder->get($rid));
86  }

◆ updateRevision()

ILIAS\ResourceStorage\Manager\BaseManager::updateRevision ( Revision  $revision)

Definition at line 346 of file BaseManager.php.

346  : bool
347  {
348  $this->resource_builder->storeRevision($revision);
349 
350  return true;
351  }

Field Documentation

◆ $collection_builder

CollectionBuilder ILIAS\ResourceStorage\Manager\BaseManager::$collection_builder
protected

◆ $preloader

RepositoryPreloader ILIAS\ResourceStorage\Manager\BaseManager::$preloader
protected

◆ $resource_builder

ResourceBuilder ILIAS\ResourceStorage\Manager\BaseManager::$resource_builder
protected

The documentation for this class was generated from the following file: