ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ILIAS\ResourceStorage\Manager\BaseManager Class Reference
+ Inheritance diagram for ILIAS\ResourceStorage\Manager\BaseManager:
+ Collaboration diagram for ILIAS\ResourceStorage\Manager\BaseManager:

Public Member Functions

 __construct (protected ResourceBuilder $resource_builder, protected CollectionBuilder $collection_builder, protected 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)
 

Detailed Description

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

Definition at line 41 of file BaseManager.php.

Constructor & Destructor Documentation

◆ __construct()

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

Manager constructor.

Definition at line 46 of file BaseManager.php.

47  {
48  }

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 146 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().

152  : Revision {
153  if ($result->isOK()) {
154  if (!$this->resource_builder->has($identification)) {
155  throw new \LogicException(
156  "Resource not found, can't append new version in: " . $identification->serialize()
157  );
158  }
159  $resource = $this->resource_builder->get($identification);
160  if ($resource->getType() === ResourceType::CONTAINER) {
161  $this->checkZIP($result->getMimeType());
162  }
163 
164  $info_resolver = new UploadInfoResolver(
165  $result,
166  $resource->getMaxRevision(true) + 1,
167  $stakeholder->getOwnerOfNewResources(),
168  $revision_title ?? $result->getName()
169  );
170 
171  $this->resource_builder->append(
172  $resource,
173  $result,
174  $info_resolver,
175  $draft ? RevisionStatus::DRAFT : RevisionStatus::PUBLISHED
176  );
177  $resource->addStakeholder($stakeholder);
178 
179  $this->resource_builder->store($resource);
180 
181  return $resource->getCurrentRevisionIncludingDraft();
182  }
183  throw new \LogicException("Can't handle UploadResult: " . $result->getStatus()->getMessage());
184  }
+ 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 239 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().

245  : Revision {
246  if (!$this->resource_builder->has($identification)) {
247  throw new \LogicException(
248  "Resource not found, can't append new version in: " . $identification->serialize()
249  );
250  }
251 
252  $resource = $this->resource_builder->get($identification);
253  if ($resource->getType() === ResourceType::CONTAINER) {
254  $this->checkZIP(mime_content_type($stream->getMetadata()['uri']));
255  }
256  $info_resolver = new StreamInfoResolver(
257  $stream,
258  $resource->getMaxRevision(true) + 1,
259  $stakeholder->getOwnerOfNewResources(),
260  $revision_title ?? $stream->getMetadata()['uri']
261  );
262 
263  $this->resource_builder->appendFromStream(
264  $resource,
265  $stream,
266  $info_resolver,
267  $draft ? RevisionStatus::DRAFT : RevisionStatus::PUBLISHED,
268  true
269  );
270 
271  $resource->addStakeholder($stakeholder);
272 
273  $this->resource_builder->store($resource);
274 
275  return $resource->getCurrentRevisionIncludingDraft();
276  }
+ 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 54 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().

54  : void
55  {
56  if (!in_array($mimetype, ['application/zip', 'application/x-zip-compressed'])) {
57  throw new \LogicException("Cant create container resource since stream is not a ZIP");
58  }
59  }
+ Here is the caller graph for this function:

◆ clone()

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

Definition at line 131 of file BaseManager.php.

131  : ResourceIdentification
132  {
133  $resource = $this->resource_builder->clone($this->resource_builder->get($identification));
134 
135  return $resource->getIdentification();
136  }

◆ find()

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

Definition at line 104 of file BaseManager.php.

References null.

104  : ?ResourceIdentification
105  {
106  $resource_identification = new ResourceIdentification($identification);
107 
108  if ($this->resource_builder->has($resource_identification)) {
109  return $resource_identification;
110  }
111 
112  return null;
113  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ getCurrentRevision()

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

Definition at line 325 of file BaseManager.php.

327  : Revision {
328  return $this->resource_builder->get($identification)->getCurrentRevision();
329  }

◆ getCurrentRevisionIncludingDraft()

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

Definition at line 331 of file BaseManager.php.

333  : Revision {
334  return $this->resource_builder->get($identification)->getCurrentRevisionIncludingDraft();
335  }

◆ getResource()

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

Definition at line 117 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().

117  : StorableResource
118  {
119  $this->preloader->preload([$i->serialize()]);
120  return $this->resource_builder->get($i);
121  }
+ 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 79 of file BaseManager.php.

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

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

84  : ResourceIdentification {
85  $info_resolver = new StreamInfoResolver(
86  $stream,
87  1,
88  $stakeholder->getOwnerOfNewResources(),
89  $revision_title ?? $stream->getMetadata()['uri']
90  );
91 
92  $resource = $this->resource_builder->newFromStream(
93  $stream,
94  $info_resolver,
95  true,
96  $type
97  );
98  $resource->addStakeholder($stakeholder);
99  $this->resource_builder->store($resource);
100 
101  return $resource->getIdentification();
102  }
+ 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 65 of file BaseManager.php.

65  : void
66  {
67  $this->resource_builder->publish($this->resource_builder->get($rid));
68  }

◆ remove()

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

Definition at line 123 of file BaseManager.php.

123  : void
124  {
125  $this->resource_builder->remove($this->resource_builder->get($identification), $stakeholder);
126  if (!$this->resource_builder->has($identification)) {
127  $this->collection_builder->notififyResourceDeletion($identification);
128  }
129  }

◆ removeRevision()

ILIAS\ResourceStorage\Manager\BaseManager::removeRevision ( 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->removeRevision($resource, $revision_number);
357  $this->resource_builder->store($resource);
358 
359  return true;
360  }

◆ replaceWithStream()

ILIAS\ResourceStorage\Manager\BaseManager::replaceWithStream ( ResourceIdentification  $identification,
FileStream  $stream,
ResourceStakeholder  $stakeholder,
?string  $revision_title = null 
)
Exceptions
FileNamePolicyExceptionif the filename is not allowed

Definition at line 284 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().

289  : Revision {
290  if (!$this->resource_builder->has($identification)) {
291  throw new \LogicException(
292  "Resource not found, can't append new version in: " . $identification->serialize()
293  );
294  }
295 
296  $resource = $this->resource_builder->get($identification);
297  if ($resource->getCurrentRevisionIncludingDraft()->getStatus() === RevisionStatus::DRAFT) {
298  throw new \LogicException(
299  "Can't replace DRAFT revision, use appendNewRevisionFromStream instead to update the DRAFT"
300  );
301  }
302  if ($resource->getType() === ResourceType::CONTAINER) {
303  $this->checkZIP(mime_content_type($stream->getMetadata()['uri']));
304  }
305  $info_resolver = new StreamInfoResolver(
306  $stream,
307  $resource->getMaxRevision(true) + 1,
308  $stakeholder->getOwnerOfNewResources(),
309  $revision_title ?? $stream->getMetadata()['uri']
310  );
311 
312  $this->resource_builder->replaceWithStream(
313  $resource,
314  $stream,
315  $info_resolver,
316  true
317  );
318  $resource->addStakeholder($stakeholder);
319 
320  $this->resource_builder->store($resource);
321 
322  return $resource->getCurrentRevisionIncludingDraft();
323  }
+ 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
FileNamePolicyExceptionif the filename is not allowed

Definition at line 192 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().

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

◆ rollbackRevision()

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

Definition at line 344 of file BaseManager.php.

344  : bool
345  {
346  $resource = $this->resource_builder->get($identification);
347  $this->resource_builder->appendFromRevision($resource, $revision_number);
348  $this->resource_builder->store($resource);
349 
350  return true;
351  }

◆ 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 74 of file BaseManager.php.

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

◆ updateRevision()

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

Definition at line 337 of file BaseManager.php.

337  : bool
338  {
339  $this->resource_builder->storeRevision($revision);
340 
341  return true;
342  }

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