19declare(strict_types=1);
45 protected \ILIAS\FileUpload\FileUpload
$upload;
46 protected \ILIAS\ResourceStorage\Services
$irss;
54 if (!
$DIC->isDependencyAvailable(
"resourceStorage")) {
57 $this->irss =
$DIC->resourceStorage();
58 $this->archives =
$DIC->archives();
59 $this->
upload = $DIC->upload();
60 $this->archives =
$DIC->archives();
61 $this->file_delivery =
$DIC->fileDelivery();
67 return $this->irss->collection()->id();
78 $new_collection = $this->irss->collection()->get($new_id);
79 $this->irss->collection()->store($new_collection);
80 return $new_id->serialize();
85 return $this->irss->collection()->get($this->irss->collection()->id($rcid));
92 $id = $this->irss->collection()->
id($rcid);
93 $this->irss->collection()->remove(
$id, $stakeholder,
true);
119 if (is_array($file_input)) {
120 if (!$upload->hasBeenProcessed()) {
123 foreach ($upload->getResults() as $name => $result) {
125 if (!in_array($name, $file_input[
"tmp_name"] ?? [],
true)) {
129 if (!$result->isOK()) {
134 $rid = $this->irss->manage()->upload(
139 $collection->
add($rid);
142 $this->irss->collection()->store($collection);
152 $sourceDir = LegacyPathHelper::createRelativePath($directory);
155 if (!$sourceFS->hasDir($sourceDir)) {
159 $sourceList = $sourceFS->listContents($sourceDir,
false);
161 foreach ($sourceList as $item) {
162 if ($item->isDir()) {
166 $stream = $sourceFS->readStream($item->getPath());
167 $rid = $this->irss->manage()->stream(
171 $collection->
add($rid);
175 $this->irss->collection()->store($collection);
180 return $this->irss->manage()->find($rid);
189 if (is_array($file_input)) {
190 if (!$upload->hasBeenProcessed()) {
193 foreach ($upload->getResults() as $name => $result) {
195 if ($name !== ($file_input[
"tmp_name"] ??
"")) {
199 if (!$result->isOK()) {
204 $rid = $this->irss->manage()->upload(
208 return $rid->serialize();
219 if (!$result->isOK()) {
224 $rid = $this->irss->manage()->upload(
228 return $rid->serialize();
237 $sourceFile = LegacyPathHelper::createRelativePath($file);
240 $stream = $sourceFS->readStream($sourceFile);
241 $rid = $this->irss->manage()->stream(
249 return $rid->serialize();
256 $rid = $this->irss->manage()->stream(
260 return $rid->serialize();
267 $id = $this->getResourceIdForIdString($rid);
268 $rev = $this->irss->manage()->getCurrentRevision(
$id);
269 $info = $rev->getInformation();
270 $info->setTitle($title);
271 $rev->setInformation(
$info);
272 $this->irss->manage()->updateRevision($rev);
277 $id = $this->getResourceIdForIdString($rid);
279 $revision = $this->irss->manage()->getCurrentRevision(
$id);
280 $this->irss->consume()->download(
$id)->overrideFileName($revision->getTitle())->run();
286 $id = $this->getResourceIdForIdString($rid);
288 return $this->irss->consume()->stream(
$id)->getStream();
295 $stream = $this->stream($rid);
304 $id = $this->getResourceIdForIdString($rid);
306 return $this->irss->manage()->getResource(
$id);
314 foreach ($collection->getResourceIdentifications() as $rid) {
315 $info = $this->irss->manage()->getResource($rid)
316 ->getCurrentRevision()
318 $src = $this->irss->consume()->src($rid)->getSrc();
319 yield $this->data->resourceInformation(
323 $info->getCreationDate()->getTimestamp(),
324 $info->getMimeType(),
333 $rid = $this->getResourceIdForIdString($rid);
334 $info = $this->irss->manage()->getResource($rid)
335 ->getCurrentRevision()
337 $src = $this->irss->consume()->src($rid)->getSrc();
338 return $this->data->resourceInformation(
342 $info->getCreationDate()->getTimestamp(),
343 $info->getMimeType(),
351 if ($from_rc_id !==
"") {
352 $cloned_rcid = $this->irss->collection()->clone($this->irss->collection()->id($from_rc_id));
353 return $cloned_rcid->serialize();
361 if ($from_rid !==
"") {
362 $cloned_rid = $this->irss->manage()->clone($this->getResourceIdForIdString($from_rid));
363 return $cloned_rid->serialize();
371 if ($from_rid !==
"") {
372 $cloned_rid = $this->irss->manageContainer()->clone($this->getResourceIdForIdString($from_rid));
373 return $cloned_rid->serialize();
381 $res = $this->getResourceIdForIdString($rid);
383 $this->irss->manage()->remove($this->getResourceIdForIdString($rid), $stakeholder);
394 $entry_parts = explode(
"/", $entry);
395 $stream = $this->getStreamOfContainerEntry($rid, $entry);
396 $feedback_rid = $this->irss->manage()->stream(
401 $target_collection->
add($feedback_rid);
402 $this->irss->collection()->store($target_collection);
413 $zip_path = $this->stream($rid)->getMetadata(
"uri");
414 return Streams::ofFileInsideZIP(
421 string $container_id,
425 $this->irss->consume()->stream($this->getResourceIdForIdString($container_id))->getStream()
431 string $container_id,
435 $this->irss->consume()->stream($this->getResourceIdForIdString($container_id))->getStream()
439 $this->file_delivery->delivery()->deliver(
443 Disposition::ATTACHMENT
454 $zip_path = $this->stream($rid)?->getMetadata(
"uri");
456 $stream = Streams::ofFileInsideZIP(
462 }
catch (\Exception
$e) {
491 string $container_id,
494 foreach ($this->irss->consume()->containerZIP(
495 $this->getResourceIdForIdString($container_id)
496 )->getZIP()->getFileStreams() as $stream) {
504 foreach ($this->irss->consume()->containerZIP(
505 $this->getResourceIdForIdString($container_id)
506 )->getZIP()->getPaths() as
$path) {
515 $this->irss->consume()->stream($this->getResourceIdForIdString($container_id))->getStream()
521 string $container_id,
525 $this->irss->consume()->stream($this->getResourceIdForIdString($container_id))->getStream()
528 foreach ($reader->getStructure() as
$path => $entry) {
529 $dirname = $entry[
'dirname'] ??
'';
530 if ($dirname !== $dir_path) {
533 $entries[
$path] = $entry;
539 string $source_container_id,
540 string $target_container_id,
541 string $source_dir_path =
"",
542 string $target_dir_path =
""
545 $this->irss->consume()->stream($this->getResourceIdForIdString($source_container_id))->getStream()
548 foreach ($reader->getStructure() as
$path => $entry) {
549 if (str_starts_with($entry[
'dirname'], $source_dir_path) && !$entry[
'is_dir']) {
550 $this->addStreamToContainer(
551 $target_container_id,
552 $this->getStreamOfContainerEntry($source_container_id,
$path),
553 $target_dir_path .
"/" . substr(
$path, strlen($source_dir_path))
561 string $title =
"container.zip"
564 throw new \ilException(
"Container title missing.");
568 $this->
filesystems->temp()->createDir($tmp_dir_info->getFilename());
569 $tmp_dir = $tmp_dir_info->getRealPath();
571 ->withZipOutputName($title)
572 ->withZipOutputPath($tmp_dir);
573 $empty_zip = $this->archives->zip(
577 $rid = $this->irss->manageContainer()->containerFromStream(
583 return $rid->serialize();
587 string $local_zip_path,
590 $stream = fopen($local_zip_path,
'r');
591 $fs =
new Stream($stream);
593 $rid = $this->irss->manageContainer()->containerFromStream(
597 return $rid->serialize();
601 string $local_dir_path,
603 string $container_path =
"",
604 bool $recursive =
true,
605 string $title =
"container.zip"
607 $real_dir_path = realpath($local_dir_path);
608 $rid = $this->createContainer($stakeholder, $title);
610 $iterator = new \RecursiveIteratorIterator(
611 new \RecursiveDirectoryIterator(
613 \RecursiveDirectoryIterator::SKIP_DOTS | \RecursiveDirectoryIterator::CURRENT_AS_SELF
615 \RecursiveIteratorIterator::SELF_FIRST
618 $iterator = new \DirectoryIterator($local_dir_path);
620 if ($container_path !==
"") {
621 $container_path = $container_path .
"/";
623 foreach ($iterator as $file) {
624 if (!$file->isDir() && !$file->isDot()) {
625 $file->getRealPath();
626 $this->addLocalFileToContainer(
628 $file->getRealPath(),
629 $container_path . substr($file->getRealPath(), strlen($real_dir_path) + 1)
641 $id = $this->getResourceIdForIdString($rid);
642 $stream = fopen($fullpath,
'r');
643 $fs =
new Stream($stream);
644 $this->irss->manageContainer()->removePathInsideContainer(
$id,
$path);
645 $this->irss->manageContainer()->addStreamToContainer(
658 $id = $this->getResourceIdForIdString($rid);
659 $stream = fopen(
'php://memory',
'r+');
660 fwrite($stream, $content);
662 $fs =
new Stream($stream);
663 $this->irss->manageContainer()->removePathInsideContainer(
$id,
$path);
664 $this->irss->manageContainer()->addStreamToContainer(
675 string $target_path =
""
677 $source_dir = realpath($source_dir);
678 $directoryIterator = new \RecursiveDirectoryIterator(
680 \FilesystemIterator::SKIP_DOTS
683 $recursiveIterator = new \RecursiveIteratorIterator(
685 \RecursiveIteratorIterator::LEAVES_ONLY
688 foreach ($recursiveIterator as $fileInfo) {
689 if ($fileInfo->isFile()) {
690 $fullPath = $fileInfo->getPathname();
691 $relativePath = substr($fullPath, strlen($source_dir) + 1);
692 $files[] = $relativePath;
693 $this->addLocalFileToContainer(
696 $target_path .
"/" . $relativePath
706 $id = $this->getResourceIdForIdString($rid);
707 $this->irss->manageContainer()->addUploadToContainer(
718 $id = $this->getResourceIdForIdString($rid);
719 $uri = $this->irss->consume()->containerURI(
725 $uri = str_replace(
"%2F",
"/", (
string) $uri);
726 return (
string) $uri;
732 $id = $this->getResourceIdForIdString($rid);
733 return $this->irss->consume()->containerZIP(
747 if (!$upload->hasBeenProcessed()) {
750 foreach ($upload->getResults() as $name => $result) {
752 if ($name !== $tmp_name) {
756 if (!$result->
isOK()) {
760 $id = $this->getResourceIdForIdString($rid);
765 if ($target_path ===
"" || str_ends_with($target_path,
"/")) {
766 $this->irss->manageContainer()->addUploadToContainer(
774 $this->addLocalFileToContainer(
790 if (!$result->isOK()) {
794 $id = $this->getResourceIdForIdString($rid);
797 $this->irss->manageContainer()->addUploadToContainer(
810 $id = $this->getResourceIdForIdString($rid);
813 $this->irss->manageContainer()->addStreamToContainer(
825 $id = $this->getResourceIdForIdString($rid);
827 $this->irss->manageContainer()->removePathInsideContainer(
$id,
$path);
836 $id = $this->getResourceIdForIdString($rid);
837 $rev = $this->irss->manageContainer()->getCurrentRevision(
$id);
838 $info = $rev->getInformation();
839 $info->setTitle($title);
840 $rev->setInformation(
$info);
841 $this->irss->manageContainer()->updateRevision($rev);
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
getMetadata($key=null)
@inheritDoc
Stream factory which enables the user to create streams without the knowledge of the concrete class.
The legacy path helper provides convenient functions for the integration of the filesystem service wi...
Class ResourceCollection.
add(ResourceIdentification $identification)
Class ResourceCollectionIdentification.
Class ResourceIdentification.
getItem(string $path_inside_zip, ?array $structure=null)
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
The Filesystems interface defines the access methods which can be used to fetch the different filesys...
The base interface for all filesystem streams.
Interface StorageResource.
Interface ResourceStakeholder.
static filesystems()
Returns the loaded filesystems.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
if(!file_exists('../ilias.ini.php'))