1<?
php declare(strict_types=1);
27use ILIAS\ResourceStorage\Preloader\SecureString;
113 $resource = $this->resource_repository->blank($this->primary_storage_handler->getIdentificationGenerator()->getUniqueResourceIdentification());
121 bool $keep_original =
false
123 $resource = $this->resource_repository->blank($this->primary_storage_handler->getIdentificationGenerator()->getUniqueResourceIdentification());
125 return $this->
appendFromStream($resource, $stream, $info_resolver, $keep_original);
130 $resource = $this->resource_repository->blank($this->primary_storage_handler->getIdentificationGenerator()->getUniqueResourceIdentification());
131 $resource->
setStorageID($this->primary_storage_handler->getID());
145 $revision = $this->revision_repository->blankFromUpload($info_resolver, $resource,
$result);
146 $revision = $this->populateRevisionInfo($revision, $info_resolver);
162 $revision = $this->revision_repository->blankFromUpload($info_resolver, $resource,
$result);
163 $revision = $this->populateRevisionInfo($revision, $info_resolver);
166 $this->deleteRevision($resource, $existing_revision);
179 bool $keep_original =
false
181 $revision = $this->revision_repository->blankFromStream($info_resolver, $resource, $stream, $keep_original);
182 $revision = $this->populateRevisionInfo($revision, $info_resolver);
194 bool $keep_original =
false
196 $revision = $this->revision_repository->blankFromStream($info_resolver, $resource, $stream, $keep_original);
197 $revision = $this->populateRevisionInfo($revision, $info_resolver);
200 $this->deleteRevision($resource, $existing_revision);
213 $existing_revision = $resource->getSpecificRevision($revision_number);
220 $cloned_revision = $this->revision_repository->blankFromClone(
226 $this->populateRevisionInfo($cloned_revision, $info_resolver);
243 return $this->resource_repository->has($identification);
254 $this->file_name_policy->check($revision->getInformation()->getSuffix());
257 $r = $this->lock_handler->lockTables(array_merge(
258 $this->resource_repository->getNamesForLocking(),
259 $this->revision_repository->getNamesForLocking(),
260 $this->information_repository->getNamesForLocking(),
261 $this->stakeholder_repository->getNamesForLocking(),
263 ), function () use ($resource) {
264 $this->resource_repository->store($resource);
267 $this->storeRevision($revision);
271 $this->stakeholder_repository->register($resource->getIdentification(), $stakeholder);
285 $new_resource = $this->newBlank();
287 $stakeholder = clone $stakeholder;
288 $new_resource->addStakeholder($stakeholder);
296 $existing_revision->getVersionNumber(),
300 $stream =
new FileStreamConsumer($resource, $this->storage_handler_factory->getHandlerForResource($resource));
301 $stream->setRevisionNumber($existing_revision->getVersionNumber());
303 $cloned_revision =
new FileStreamRevision($new_resource->getIdentification(), $stream->getStream(),
true);
304 $this->populateRevisionInfo($cloned_revision, $info_resolver);
305 $cloned_revision->setVersionNumber($existing_revision->getVersionNumber());
307 $new_resource->addRevision($cloned_revision);
309 $this->store($new_resource);
310 return $new_resource;
323 $this->file_name_policy->check($revision->
getInformation()->getSuffix());
324 $this->primary_storage_handler->storeUpload($revision);
327 $this->primary_storage_handler->storeStream($revision);
330 $this->primary_storage_handler->cloneRevision($revision);
332 $this->revision_repository->store($revision);
333 $this->information_repository->store($revision->
getInformation(), $revision);
344 if (isset($this->resource_cache[$identification->serialize()])) {
345 return $this->resource_cache[$identification->serialize()];
347 $resource = $this->resource_repository->get($identification);
349 $this->resource_cache[$identification->serialize()] = $this->populateNakedResourceWithRevisionsAndStakeholders($resource);
351 return $this->resource_cache[$identification->serialize()];
364 $this->stakeholder_repository->deregister($resource->
getIdentification(), $stakeholder);
365 $sucessful = $sucessful && $stakeholder->resourceHasBeenDeleted($resource->
getIdentification());
372 $sucessful = $sucessful && $s->resourceHasBeenDeleted($resource->
getIdentification());
376 $this->deleteRevision($resource, $revision);
379 $this->storage_handler_factory->getHandlerForResource($resource)->deleteResource($resource);
380 $this->resource_repository->delete($resource);
388 if ($reveision_to_delete) {
389 $this->deleteRevision($resource, $reveision_to_delete);
391 $this->store($resource);
397 $this->storage_handler_factory->getHandlerForResource($resource)->deleteRevision($revision);
398 }
catch (\Throwable $t) {
401 $this->information_repository->delete($revision->
getInformation(), $revision);
402 $this->revision_repository->delete($revision);
409 public function getAll() : Generator
414 foreach ($this->resource_repository->getAll() as $resource) {
415 yield $this->populateNakedResourceWithRevisionsAndStakeholders($resource);
425 $revisions = $this->revision_repository->get($resource);
429 $information = $this->information_repository->get($revision);
430 $revision->setInformation($information);
433 foreach ($this->stakeholder_repository->getStakeholders($resource->
getIdentification()) as $s) {
444 $info->setTitle($this->secure($info_resolver->
getFileName()));
446 $info->setSuffix($this->secure($info_resolver->
getSuffix()));
447 $info->setSize($info_resolver->
getSize());
452 $revision->setOwnerId($info_resolver->
getOwnerId());
An exception for terminatinating execution or to throw for unit testing.
Interface Identification.
Class NoneFileNamePolicy.
append(StorableResource $resource, UploadResult $result, InfoResolver $info_resolver)
populateRevisionInfo(Revision $revision, InfoResolver $info_resolver)
appendFromStream(StorableResource $resource, FileStream $stream, InfoResolver $info_resolver, bool $keep_original=false)
appendFromRevision(StorableResource $resource, int $revision_number)
newFromStream(FileStream $stream, InfoResolver $info_resolver, bool $keep_original=false)
populateNakedResourceWithRevisionsAndStakeholders(StorableResource $resource)
replaceWithStream(StorableResource $resource, FileStream $stream, InfoResolver $info_resolver, bool $keep_original=false)
store(StorableResource $resource)
__construct(StorageHandlerFactory $storage_handler_factory, RevisionRepository $revision_repository, ResourceRepository $resource_repository, InformationRepository $information_repository, StakeholderRepository $stakeholder_repository, LockHandler $lock_handler, FileNamePolicy $file_name_policy=null)
ResourceBuilder constructor.
has(ResourceIdentification $identification)
deleteRevision(StorableResource $resource, Revision $revision)
replaceWithUpload(StorableResource $resource, UploadResult $result, InfoResolver $info_resolver)
@inheritDoc
removeRevision(StorableResource $resource, int $revision_number)
storeRevision(Revision $revision)
@description Store one Revision
clone(StorableResource $resource)
Class UploadedFileRevision.
Class UploadedFileRevision.
Class StorageHandlerFactory.
Interface FileStream The base interface for all filesystem streams.
Interface FileNamePolicy.
Interface ResourceRepository.
Interface StorageResource.
setRevisions(RevisionCollection $collection)
addStakeholder(ResourceStakeholder $s)
addRevision(Revision $revision)
removeRevision(Revision $revision)
removeStakeholder(ResourceStakeholder $s)
setStorageID(string $storage_id)
getSpecificRevision(int $number)
Class RevisionARRepository.
setInformation(Information $information)
Interface StakeholderRepository.
Interface ResourceStakeholder.
Class FileResourceHandler.