19 declare(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);
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();
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();
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);
279 $revision = $this->irss->manage()->getCurrentRevision(
$id);
280 $this->irss->consume()->download(
$id)->overrideFileName($revision->getTitle())->run();
288 return $this->irss->consume()->stream(
$id)->getStream();
295 $stream = $this->
stream($rid);
297 return $stream->getMetadata(
'uri') ??
'';
306 return $this->irss->manage()->getResource(
$id);
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(),
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 !==
"") {
363 return $cloned_rid->serialize();
371 if ($from_rid !==
"") {
373 return $cloned_rid->serialize();
394 $entry_parts = explode(
"/", $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");
421 string $container_id,
427 return $reader->
getItem($path)[1];
431 string $container_id,
437 [$stream, $info] = $reader->
getItem($path);
439 $this->file_delivery->delivery()->deliver(
443 Disposition::ATTACHMENT
454 $zip_path = $this->
stream($rid)?->getMetadata(
"uri");
491 string $container_id,
494 foreach ($this->irss->consume()->containerZIP(
496 )->getZIP()->getFileStreams() as $stream) {
504 foreach ($this->irss->consume()->containerZIP(
506 )->getZIP()->getPaths() as
$path) {
521 string $container_id,
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 =
"" 548 foreach ($reader->getStructure() as
$path => $entry) {
549 if (str_starts_with($entry[
'dirname'], $source_dir_path) && !$entry[
'is_dir']) {
551 $target_container_id,
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);
610 $iterator = new \RecursiveIteratorIterator(
612 \RecursiveIteratorIterator::SELF_FIRST
615 $iterator = new \DirectoryIterator($local_dir_path);
617 if ($container_path !==
"") {
618 $container_path = $container_path .
"/";
620 foreach ($iterator as $file) {
621 if (!$file->isDir() && !$file->isDot()) {
622 $file->getRealPath();
625 $file->getRealPath(),
626 $container_path . substr($file->getRealPath(), strlen($real_dir_path) + 1)
639 $stream = fopen($fullpath,
'r');
640 $fs =
new Stream($stream);
641 $this->irss->manageContainer()->removePathInsideContainer(
$id, $path);
642 $this->irss->manageContainer()->addStreamToContainer(
656 $stream = fopen(
'php://memory',
'r+');
657 fwrite($stream, $content);
659 $fs =
new Stream($stream);
660 $this->irss->manageContainer()->removePathInsideContainer(
$id, $path);
661 $this->irss->manageContainer()->addStreamToContainer(
672 string $target_path =
"" 674 $source_dir = realpath($source_dir);
675 $directoryIterator = new \RecursiveDirectoryIterator(
677 \FilesystemIterator::SKIP_DOTS
680 $recursiveIterator = new \RecursiveIteratorIterator(
682 \RecursiveIteratorIterator::LEAVES_ONLY
685 foreach ($recursiveIterator as $fileInfo) {
686 if ($fileInfo->isFile()) {
687 $fullPath = $fileInfo->getPathname();
688 $relativePath = substr($fullPath, strlen($source_dir) + 1);
689 $files[] = $relativePath;
693 $target_path .
"/" . $relativePath
704 $this->irss->manageContainer()->addUploadToContainer(
716 $uri = $this->irss->consume()->containerURI(
722 $uri = str_replace(
"%2F",
"/", (
string) $uri);
723 return (
string) $uri;
730 return $this->irss->consume()->containerZIP(
744 if (!$upload->hasBeenProcessed()) {
747 foreach ($upload->getResults() as $name => $result) {
749 if ($name !== $tmp_name) {
753 if (!$result->isOK()) {
762 if ($target_path ===
"" || str_ends_with($target_path,
"/")) {
763 $this->irss->manageContainer()->addUploadToContainer(
787 if (!$result->
isOK()) {
794 $this->irss->manageContainer()->addUploadToContainer(
810 $this->irss->manageContainer()->addStreamToContainer(
824 $this->irss->manageContainer()->removePathInsideContainer(
$id, $path);
834 $rev = $this->irss->manageContainer()->getCurrentRevision(
$id);
835 $info = $rev->getInformation();
836 $info->setTitle($title);
837 $rev->setInformation($info);
838 $this->irss->manageContainer()->updateRevision($rev);
static createRelativePath(string $absolute_path)
Creates a relative path from an absolute path which starts with a valid storage location.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface StorageResource.
Interface Observer Contains several chained tasks and infos about them.
static ofFileInsideZIP(string $path_to_zip, string $path_inside_zip)
Class ResourceCollectionIdentification.
Class ResourceCollection.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getItem(string $path_inside_zip, ?array $structure=null)
static filesystems()
Returns the loaded filesystems.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ResourceIdentification.
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
add(ResourceIdentification $identification)
getResourceIdentifications()
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static deriveFilesystemFrom(string $absolute_path)
Tries to fetch the filesystem responsible for the absolute path.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Interface ResourceStakeholder.
The base interface for all filesystem streams.