Skip to content

Commit

Permalink
42637: Export and Import of a group -> error
Browse files Browse the repository at this point in the history
  • Loading branch information
alex40724 committed Jan 20, 2025
1 parent b222e85 commit 55361db
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\Dataset;

use ILIAS\ResourceStorage\Resource\StorableResource;

class IRSSContainerExportConfig
{
public function __construct(
protected StorableResource $source_container,
protected string $source_path,
protected string $target_path
) {
}

public function getSourceContainer(): StorableResource
{
return $this->source_container;
}

public function getSourcePath(): string
{
return $this->source_path;
}

public function getTargetPath(): string
{
return $this->target_path;
}
}
45 changes: 29 additions & 16 deletions components/ILIAS/DataSet/classes/class.ilDataSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
use ILIAS\ResourceStorage\Collection\ResourceCollection;
use ILIAS\ResourceStorage\Resource\StorableContainerResource;
use ILIAS\ResourceStorage\Identification\ResourceIdentification;
use ILIAS\ResourceStorage\Resource\StorableResource;
use ILIAS\Dataset\IRSSContainerExportConfig;

/**
* A dataset contains in data in a common structure that can be
Expand Down Expand Up @@ -311,21 +313,20 @@ public function addRecordsXml(

$c = $path_in_container;
$this->dircnt++;

if (($types[$f] ?? "") === "rscontainer") {
/* todo
$tdir = $this->absolute_export_dir . "/dsDir_" . $this->dircnt;
ilFileUtils::makeDirParents($tdir);
$tdir = realpath($tdir);
if ($rid = $this->getContainerRid($rec, $a_entity, $a_schema_version, $f, $c)) {
$stream = $this->irss->consume()->stream($rid);
$name = $tdir . "/rscontainer.zip";
file_put_contents($name, $stream->getStream()->getContents());
}
$c = $this->relative_export_dir . "/dsDir_" . $this->dircnt;
$this->dircnt++;
*/
}
if (isset($this->export) and ($types[$f] ?? "") === "rscontainer") {
$path_in_container = $this->export->getExportDirInContainer() . "/dsDir_" . $this->dircnt;
if ($config = $this->getContainerExportConfig($rec, $a_entity, $a_schema_version, $f, $c)) {
$this->export->getExportWriter()->writeFilesByResourceContainer(
$this->getIRSSContainerExportConfig(
$config->getSourceContainer(),
$config->getSourcePath(),
$path_in_container
)
);
}
$c = $path_in_container;
$this->dircnt++;
}
// this changes schema/dtd
//$a_writer->xmlElement($a_prefixes[$a_entity].":".$f,
Expand All @@ -352,6 +353,18 @@ public function addRecordsXml(
}
}

protected function getIRSSContainerExportConfig(
StorableResource $source_container,
string $source_path,
string $target_path = ""
): IRSSContainerExportConfig {
return new IRSSContainerExportConfig(
$source_container,
$source_path,
$target_path
);
}

protected function getDependencies(
string $a_entity,
string $a_version,
Expand Down Expand Up @@ -548,13 +561,13 @@ public function getCollection(
return null;
}

public function getContainerRid(
public function getContainerExportConfig(
array $record,
string $entity,
string $schema_version,
string $field,
string $value
): ?ResourceIdentification {
): ?IRSSContainerExportConfig {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
use ILIAS\Filesystem\Stream\FileStream;
use ILIAS\Filesystem\Stream\Streams;
use ILIAS\ResourceStorage\Collection\ResourceCollection;
use ILIAS\ResourceStorage\Resource\StorableContainerResource;
use ILIAS\ResourceStorage\Resource\StorableResource;
use ILIAS\Dataset\IRSSContainerExportConfig;

class Handler implements ilExportHandlerConsumerExportWriterInterface
{
Expand Down Expand Up @@ -157,6 +160,11 @@ public function writeFilesByResourceCollection(
$this->getElement()->getIRSS()->addResourceCollectionToContaierByCollection($collection, $path_in_container);
}

public function writeFilesByResourceContainer(
IRSSContainerExportConfig $config
): void {
$this->getElement()?->getIRSS()->addContainerToContainerByContainerResource($config);
}
public function writeFilesByResourceId(
string $resource_id_serialized,
string $path_in_container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
use ILIAS\Data\ObjectId;
use ILIAS\Filesystem\Stream\FileStream;
use ILIAS\ResourceStorage\Collection\ResourceCollection;
use ILIAS\ResourceStorage\Resource\StorableContainerResource;
use ILIAS\ResourceStorage\Resource\StorableResource;
use ILIAS\Dataset\IRSSContainerExportConfig;

interface HandlerInterface
{
Expand Down Expand Up @@ -68,6 +71,10 @@ public function writeFilesByResourceCollection(
string $path_in_container
): void;

public function writeFilesByResourceContainer(
IRSSContainerExportConfig $config
): void;

public function writeFilesByResourceId(
string $resource_id_serialized,
string $path_in_container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
use ILIAS\Filesystem\Stream\FileStream;
use ILIAS\ResourceStorage\Collection\ResourceCollection;
use ILIAS\ResourceStorage\Identification\ResourceIdentification;
use ILIAS\ResourceStorage\Resource\StorableContainerResource;
use ILIAS\ResourceStorage\Resource\StorableResource;
use ILIAS\Dataset\IRSSContainerExportConfig;

interface HandlerInterface
{
Expand Down Expand Up @@ -58,6 +61,10 @@ public function addResourceCollectionToContaierByCollection(
string $dir_path_in_container
);

public function addContainerToContainerByContainerResource(
IRSSContainerExportConfig $config
): void;

public function writeZip(
FileStream $zip_stream,
string $path_in_container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
use ILIAS\ResourceStorage\Collection\ResourceCollection;
use ILIAS\ResourceStorage\Identification\ResourceIdentification;
use ILIAS\ResourceStorage\Services as ResourcesStorageService;
use ILIAS\ResourceStorage\Resource\StorableContainerResource;
use ILIAS\Filesystem\Stream\ZIPStream;
use ILIAS\Filesystem\Stream\Streams;
use ILIAS\ResourceStorage\Resource\StorableResource;
use ILIAS\Dataset\IRSSContainerExportConfig;

class Handler implements ilExportHandlerRepositoryElementIRSSWrapperInterface
{
Expand Down Expand Up @@ -122,6 +127,49 @@ public function addResourceCollectionToContaierByCollection(
}
}

public function addContainerToContainerByContainerResource(
IRSSContainerExportConfig $config
): void {
$source_container = $config->getSourceContainer();
$target_path = $config->getTargetPath();
$target_container_rid = $this->getResourceId();
if (is_null($target_container_rid)) {
return;
}
$source_container_id = $source_container->getIdentification();
$reader = new ZipReader(
$this->irss->consume()->stream($source_container_id)->getStream()
);
foreach ($reader->getStructure() as $path => $entry) {
if (!$entry['is_dir']) {
if ($config->getSourcePath() !== "" && $config->getSourcePath() !== "/") {
if (!str_starts_with($path, $config->getSourcePath())) {
continue;
}
}
$file_stream = $this->getStreamOfContainerEntry($source_container_id, $path);
$this->irss->manageContainer()->addStreamToContainer(
$target_container_rid,
$file_stream,
$target_path . "/" . substr($path, strlen($config->getSourcePath())),
);
}
}
}

public function getStreamOfContainerEntry(
ResourceIdentification $id,
string $entry
): ZIPStream {
$zip_path = $this->irss->consume()->stream($id)->getStream()->getMetadata("uri");
return Streams::ofFileInsideZIP(
$zip_path,
$entry
);
}



public function writeZip(
FileStream $zip_stream,
string $path_in_container
Expand Down
15 changes: 12 additions & 3 deletions components/ILIAS/Style/classes/class.ilStyleDataSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use ILIAS\Style\Content\Access;
use ILIAS\Style\Content;
use ILIAS\ResourceStorage\Identification\ResourceIdentification;
use ILIAS\Dataset\IRSSContainerExportConfig;

/**
* Style Data set class
Expand Down Expand Up @@ -433,15 +434,23 @@ public function readData(string $a_entity, string $a_version, array $a_ids): voi
}
}

public function getContainerRid(
public function getContainerExportConfig(
array $record,
string $entity,
string $schema_version,
string $field,
string $value
): ?ResourceIdentification {
): ?IRSSContainerExportConfig {
if ($entity === "sty" && $field === "StyleContainer") {
return $this->style_domain->style((int) $record["Id"])->getResourceIdentification();
$rid = $this->style_domain->style((int) $record["Id"])->getResourceIdentification();
if ($rid) {
$container = $this->irss->manageContainer()->getResource($rid);
return
$this->getIRSSContainerExportConfig(
$container,
"images"
);
}
}
return null;
}
Expand Down

0 comments on commit 55361db

Please sign in to comment.