19 declare(strict_types=1);
63 protected function checkZIP(
bool|
string $mimetype): void
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");
76 $this->resource_builder->publish($this->resource_builder->get($rid));
85 $this->resource_builder->unpublish($this->resource_builder->get($rid));
92 string $revision_title = null
98 $revision_title ?? $stream->getMetadata()[
'uri']
101 $resource = $this->resource_builder->newFromStream(
107 $resource->addStakeholder($stakeholder);
108 $this->resource_builder->store($resource);
110 return $resource->getIdentification();
117 if ($this->resource_builder->has($resource_identification)) {
118 return $resource_identification;
128 $this->preloader->preload([$i->
serialize()]);
129 return $this->resource_builder->get($i);
134 $this->resource_builder->remove($this->resource_builder->get($identification), $stakeholder);
135 if (!$this->resource_builder->has($identification)) {
136 $this->collection_builder->notififyResourceDeletion($identification);
142 $resource = $this->resource_builder->clone($this->resource_builder->get($identification));
144 return $resource->getIdentification();
159 string $revision_title = null,
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()
168 $resource = $this->resource_builder->get($identification);
175 $resource->getMaxRevision(
true) + 1,
177 $revision_title ?? $result->
getName()
180 $this->resource_builder->append(
186 $resource->addStakeholder($stakeholder);
188 $this->resource_builder->store($resource);
190 return $resource->getCurrentRevisionIncludingDraft();
192 throw new \LogicException(
"Can't handle UploadResult: " . $result->
getStatus()->getMessage());
205 string $revision_title = null
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()
213 $resource = $this->resource_builder->get($identification);
218 throw new \LogicException(
219 "Can't replace DRAFT revision, use appendNewRevision instead to update the DRAFT" 224 $resource->getMaxRevision(
true) + 1,
226 $revision_title ?? $result->
getName()
228 $this->resource_builder->replaceWithUpload(
233 $resource->addStakeholder($stakeholder);
235 $this->resource_builder->store($resource);
237 return $resource->getCurrentRevisionIncludingDraft();
239 throw new \LogicException(
"Can't handle UploadResult: " . $result->
getStatus()->getMessage());
252 string $revision_title = null,
255 if (!$this->resource_builder->has($identification)) {
256 throw new \LogicException(
257 "Resource not found, can't append new version in: " . $identification->
serialize()
261 $resource = $this->resource_builder->get($identification);
263 $this->
checkZIP(mime_content_type($stream->getMetadata()[
'uri']));
267 $resource->getMaxRevision(
true) + 1,
269 $revision_title ?? $stream->getMetadata()[
'uri']
272 $this->resource_builder->appendFromStream(
280 $resource->addStakeholder($stakeholder);
282 $this->resource_builder->store($resource);
284 return $resource->getCurrentRevisionIncludingDraft();
297 string $revision_title = null
299 if (!$this->resource_builder->has($identification)) {
300 throw new \LogicException(
301 "Resource not found, can't append new version in: " . $identification->
serialize()
305 $resource = $this->resource_builder->get($identification);
307 throw new \LogicException(
308 "Can't replace DRAFT revision, use appendNewRevisionFromStream instead to update the DRAFT" 312 $this->
checkZIP(mime_content_type($stream->getMetadata()[
'uri']));
316 $resource->getMaxRevision(
true) + 1,
318 $revision_title ?? $stream->getMetadata()[
'uri']
321 $this->resource_builder->replaceWithStream(
327 $resource->addStakeholder($stakeholder);
329 $this->resource_builder->store($resource);
331 return $resource->getCurrentRevisionIncludingDraft();
337 return $this->resource_builder->get($identification)->getCurrentRevision();
343 return $this->resource_builder->get($identification)->getCurrentRevisionIncludingDraft();
348 $this->resource_builder->storeRevision($revision);
355 $resource = $this->resource_builder->get($identification);
356 $this->resource_builder->appendFromRevision($resource, $revision_number);
357 $this->resource_builder->store($resource);
364 $resource = $this->resource_builder->get($identification);
365 $this->resource_builder->removeRevision($resource, $revision_number);
366 $this->resource_builder->store($resource);
publish(ResourceIdentification $rid)
Publish a resource.
RepositoryPreloader $preloader
Interface StorageResource.
appendNewRevision(ResourceIdentification $identification, UploadResult $result, ResourceStakeholder $stakeholder, string $revision_title=null, bool $draft=false)
Append a new revision from an UploadResult.
replaceWithStream(ResourceIdentification $identification, FileStream $stream, ResourceStakeholder $stakeholder, string $revision_title=null)
removeRevision(ResourceIdentification $identification, int $revision_number)
getCurrentRevision(ResourceIdentification $identification)
checkZIP(bool|string $mimetype)
ResourceBuilder $resource_builder
unpublish(ResourceIdentification $rid)
Unpublish a resource.
clone(ResourceIdentification $identification)
CollectionBuilder $collection_builder
getResource(ResourceIdentification $i)
updateRevision(Revision $revision)
replaceWithUpload(ResourceIdentification $identification, UploadResult $result, ResourceStakeholder $stakeholder, string $revision_title=null)
Class ResourceIdentification.
appendNewRevisionFromStream(ResourceIdentification $identification, FileStream $stream, ResourceStakeholder $stakeholder, string $revision_title=null, bool $draft=false)
Append a new revision from a stream.
getCurrentRevisionIncludingDraft(ResourceIdentification $identification)
Interface ResourceStakeholder.
rollbackRevision(ResourceIdentification $identification, int $revision_number)
find(string $identification)
newStreamBased(FileStream $stream, ResourceStakeholder $stakeholder, ResourceType $type, string $revision_title=null)
Interface RepositoryPreloader.
The base interface for all filesystem streams.
__construct(ResourceBuilder $resource_builder, CollectionBuilder $collection_builder, RepositoryPreloader $preloader)
Manager constructor.