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
457 $zip_path = $this->stream($rid)?->getMetadata(
"uri");
458 if (is_null($zip_path)) {
462 $stream = Streams::ofFileInsideZIP(
468 }
catch (\Exception
$e) {
497 string $container_id,
500 foreach ($this->irss->consume()->containerZIP(
501 $this->getResourceIdForIdString($container_id)
502 )->getZIP()->getFileStreams() as $stream) {
510 foreach ($this->irss->consume()->containerZIP(
511 $this->getResourceIdForIdString($container_id)
512 )->getZIP()->getPaths() as
$path) {
520 $rid = $this->getResourceIdForIdString($container_id);
525 $this->irss->consume()->stream($rid)->getStream()
527 return $reader->getStructure();
531 string $container_id,
534 $rid = $this->getResourceIdForIdString($container_id);
539 $this->irss->consume()->stream($rid)->getStream()
542 foreach ($reader->getStructure() as
$path => $entry) {
543 $dirname = $entry[
'dirname'] ??
'';
544 if ($dirname !== $dir_path) {
547 $entries[
$path] = $entry;
553 string $source_container_id,
554 string $target_container_id,
555 string $source_dir_path =
"",
556 string $target_dir_path =
""
559 $this->irss->consume()->stream($this->getResourceIdForIdString($source_container_id))->getStream()
562 foreach ($reader->getStructure() as
$path => $entry) {
563 if (str_starts_with($entry[
'dirname'], $source_dir_path) && !$entry[
'is_dir']) {
564 $this->addStreamToContainer(
565 $target_container_id,
566 $this->getStreamOfContainerEntry($source_container_id,
$path),
567 $target_dir_path .
"/" . substr(
$path, strlen($source_dir_path))
575 string $title =
"container.zip"
578 throw new \ilException(
"Container title missing.");
582 $this->
filesystems->temp()->createDir($tmp_dir_info->getFilename());
583 $tmp_dir = $tmp_dir_info->getRealPath();
585 ->withZipOutputName($title)
586 ->withZipOutputPath($tmp_dir);
587 $empty_zip = $this->archives->zip(
591 $rid = $this->irss->manageContainer()->containerFromStream(
597 return $rid->serialize();
601 string $local_zip_path,
604 $stream = fopen($local_zip_path,
'r');
605 $fs =
new Stream($stream);
607 $rid = $this->irss->manageContainer()->containerFromStream(
611 return $rid->serialize();
615 string $local_dir_path,
617 string $container_path =
"",
618 bool $recursive =
true,
619 string $title =
"container.zip"
621 $real_dir_path = realpath($local_dir_path);
622 $rid = $this->createContainer($stakeholder, $title);
624 $iterator = new \RecursiveIteratorIterator(
625 new \RecursiveDirectoryIterator(
627 \RecursiveDirectoryIterator::SKIP_DOTS | \RecursiveDirectoryIterator::CURRENT_AS_SELF
629 \RecursiveIteratorIterator::SELF_FIRST
632 $iterator = new \DirectoryIterator($local_dir_path);
634 if ($container_path !==
"") {
635 $container_path = $container_path .
"/";
637 foreach ($iterator as $file) {
638 if (!$file->isDir() && !$file->isDot()) {
639 $file->getRealPath();
640 $this->addLocalFileToContainer(
642 $file->getRealPath(),
643 $container_path . substr($file->getRealPath(), strlen($real_dir_path) + 1)
655 $id = $this->getResourceIdForIdString($rid);
656 $stream = fopen($fullpath,
'r');
657 $fs =
new Stream($stream);
658 $this->irss->manageContainer()->removePathInsideContainer(
$id,
$path);
659 $this->irss->manageContainer()->addStreamToContainer(
672 $id = $this->getResourceIdForIdString($rid);
673 $stream = fopen(
'php://memory',
'r+');
674 fwrite($stream, $content);
676 $fs =
new Stream($stream);
677 $this->irss->manageContainer()->removePathInsideContainer(
$id,
$path);
678 $this->irss->manageContainer()->addStreamToContainer(
689 string $target_path =
""
691 $source_dir = realpath($source_dir);
692 $directoryIterator = new \RecursiveDirectoryIterator(
694 \FilesystemIterator::SKIP_DOTS
697 $recursiveIterator = new \RecursiveIteratorIterator(
699 \RecursiveIteratorIterator::LEAVES_ONLY
702 foreach ($recursiveIterator as $fileInfo) {
703 if ($fileInfo->isFile()) {
704 $fullPath = $fileInfo->getPathname();
705 $relativePath = substr($fullPath, strlen($source_dir) + 1);
706 $files[] = $relativePath;
707 $this->addLocalFileToContainer(
710 $target_path .
"/" . $relativePath
720 $id = $this->getResourceIdForIdString($rid);
721 $this->irss->manageContainer()->addUploadToContainer(
732 $id = $this->getResourceIdForIdString($rid);
733 $uri = $this->irss->consume()->containerURI(
739 $uri = str_replace(
"%2F",
"/", (
string) $uri);
740 return (
string) $uri;
746 $id = $this->getResourceIdForIdString($rid);
747 return $this->irss->consume()->containerZIP(
761 if (!$upload->hasBeenProcessed()) {
764 foreach ($upload->getResults() as $name => $result) {
766 if ($name !== $tmp_name) {
770 if (!$result->
isOK()) {
774 $id = $this->getResourceIdForIdString($rid);
779 if ($target_path ===
"" || str_ends_with($target_path,
"/")) {
780 $this->irss->manageContainer()->addUploadToContainer(
788 $this->addLocalFileToContainer(
804 if (!$result->isOK()) {
808 $id = $this->getResourceIdForIdString($rid);
811 $this->irss->manageContainer()->addUploadToContainer(
824 $id = $this->getResourceIdForIdString($rid);
827 $this->irss->manageContainer()->addStreamToContainer(
839 $id = $this->getResourceIdForIdString($rid);
841 $this->irss->manageContainer()->removePathInsideContainer(
$id,
$path);
850 $id = $this->getResourceIdForIdString($rid);
851 $rev = $this->irss->manageContainer()->getCurrentRevision(
$id);
852 $info = $rev->getInformation();
853 $info->setTitle($title);
854 $rev->setInformation(
$info);
855 $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'))