Skip to content

Commit

Permalink
[FIX] 0043180: Failed test: Literaturliste exportieren
Browse files Browse the repository at this point in the history
  • Loading branch information
chfsx committed Jan 28, 2025
1 parent 83d6762 commit 4c195e8
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@
*
*********************************************************************/

use ILIAS\Filesystem\Provider\FlySystem\FlySystemFilesystemFactory;
use ILIAS\ResourceStorage\Resource\ResourceBuilder;
use ILIAS\ResourceStorage\StorageHandler\FileSystemStorageHandler;
use ILIAS\Filesystem\Provider\Configuration\LocalConfig;
use ILIAS\FileUpload\Location;
use ILIAS\ResourceStorage\Revision\Repository\RevisionARRepository;
use ILIAS\ResourceStorage\Resource\Repository\ResourceARRepository;
use ILIAS\ResourceStorage\Information\Repository\InformationARRepository;
use ILIAS\ResourceStorage\Stakeholder\Repository\StakeholderARRepository;
use ILIAS\ResourceStorage\Lock\LockHandlerilDB;
use ILIAS\ResourceStorage\Services;
use ILIAS\Filesystem\Stream\Streams;

/**
Expand All @@ -35,8 +26,10 @@
*/
class ilBibliographicDataSet extends ilDataSet
{
private const EXP_DIRECTORY = "/Modules/Bibliographic/set_1/expDir_1/";
private const EXP_DIRECTORY_NEW = "/components/ILIAS/Bibliographic/set_1/expDir_1/";
/**
* @var \ILIAS\ResourceStorage\Services
* @var Services
*/
protected $storage;
protected \ilObjBibliographicStakeholder $stakeholder;
Expand All @@ -48,8 +41,8 @@ class ilBibliographicDataSet extends ilDataSet
* @var ilObjUser
*/
protected $user;
protected array $import_temp_refs = array();
protected array $import_temp_refs_props = array();
protected array $import_temp_refs = [];
protected array $import_temp_refs_props = [];


public function __construct()
Expand All @@ -66,9 +59,10 @@ public function __construct()
}



public function getSupportedVersions(): array
{
return array('4.5.0');
return ['4.5.0'];
}


Expand All @@ -85,30 +79,28 @@ public function importRecord(
ilImportMapping $a_mapping,
string $a_schema_version
): void {
switch ($a_entity) {
case 'bibl':
if ($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'objs', $a_rec['id'])) {
// container content
$new_obj = ilObjectFactory::getInstanceByObjId($new_id, false);
} else {
$new_obj = new ilObjBibliographic();
}
/**
* @var $new_obj ilObjBibliographic
*/
$new_obj->setTitle($a_rec['title']);
$new_obj->setDescription($a_rec['description']);
$new_obj->setFilename($a_rec['fileName']);
if (!$new_obj->getId()) {
$new_obj->create();
}
$new_obj->getObjectProperties()->storePropertyIsOnline(
new ilObjectPropertyIsOnline(false)
);
$this->import_bib_object = $new_obj;
$a_mapping->addMapping('components/ILIAS/Bibliographic', 'bibl', $a_rec['id'], $new_obj->getId());
$this->importLibraryFile($a_mapping);
break;
if ($a_entity === 'bibl') {
if ($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'objs', $a_rec['id'])) {
// container content
$new_obj = ilObjectFactory::getInstanceByObjId($new_id, false);
} else {
$new_obj = new ilObjBibliographic();
}
/**
* @var $new_obj ilObjBibliographic
*/
$new_obj->setTitle($a_rec['title']);
$new_obj->setDescription($a_rec['description']);
$new_obj->setFilename($a_rec['fileName']);
if ($new_obj->getId() === 0) {
$new_obj->create();
}
$new_obj->getObjectProperties()->storePropertyIsOnline(
new ilObjectPropertyIsOnline(false)
);
$this->import_bib_object = $new_obj;
$a_mapping->addMapping('components/ILIAS/Bibliographic', 'bibl', $a_rec['id'], $new_obj->getId());
$this->importLibraryFile($a_mapping);
}
}

Expand All @@ -118,17 +110,10 @@ public function importRecord(
*/
protected function getTypes(string $a_entity, string $a_version): array
{
switch ($a_entity) {
case 'bibl':
return array(
"id" => "integer",
"title" => "text",
"description" => "text",
"filename" => "text"
);
default:
return array();
}
return match ($a_entity) {
'bibl' => ["id" => "integer", "title" => "text", "description" => "text", "filename" => "text"],
default => [],
};
}


Expand All @@ -148,9 +133,9 @@ protected function getDependencies(

public function readData(string $a_entity, string $a_version, array $a_ids): void
{
$this->data = array();
$this->data = [];
if (!is_array($a_ids)) {
$a_ids = array($a_ids);
$a_ids = [$a_ids];
}
$this->_readData($a_entity, $a_ids);
}
Expand All @@ -166,12 +151,7 @@ protected function _readData(string $a_entity, array $a_ids): void
foreach ($a_ids as $bibl_id) {
if (ilObject::_lookupType($bibl_id) === 'bibl') {
$obj = new ilObjBibliographic($bibl_id);
$data = array(
'id' => $bibl_id,
'title' => $obj->getTitle(),
'description' => $obj->getDescription(),
'fileName' => $obj->getFilename()
);
$data = ['id' => $bibl_id, 'title' => $obj->getTitle(), 'description' => $obj->getDescription(), 'fileName' => $obj->getFilename()];
$this->data[] = $data;
}
}
Expand All @@ -181,11 +161,15 @@ protected function _readData(string $a_entity, array $a_ids): void
}


public function exportLibraryFile(int $a_id): void
public function exportLibraryFile(int $a_id, string $absolute_export_dir): void
{
$obj = new ilObjBibliographic($a_id);
$fileAbsolutePath = $obj->getLegacyAbsolutePath();
copy($fileAbsolutePath, $this->absolute_export_dir . "/" . $obj->getFilename());
if (($rid = $obj->getResourceId()) === null) {
return;
}
$fileAbsolutePath = $this->irss->consume()->stream($rid)->getStream()->getMetadata()['uri'] ?? null;
ilFileUtils::makeDirParents($absolute_export_dir . self::EXP_DIRECTORY_NEW);
copy($fileAbsolutePath, $absolute_export_dir . self::EXP_DIRECTORY_NEW . $obj->getFilename());
}


Expand All @@ -196,10 +180,20 @@ public function importLibraryFile(\ilImportMapping $a_mapping): void
{
$bib_id = $this->import_bib_object->getId();
$filename = $this->import_bib_object->getFilename();
$import_path = $this->getImportDirectory() . "/Modules/Bibliographic/set_1/expDir_1/" . $filename;
$import_path_legacy = $this->getImportDirectory() . self::EXP_DIRECTORY . $filename;
$import_path_new = $this->getImportDirectory() . self::EXP_DIRECTORY_NEW . $filename;
if (file_exists($import_path_legacy)) {
$import_path = $import_path_legacy;
} elseif (file_exists($import_path_new)) {
$import_path = $import_path_new;
} else {
return;
}

// create new resource from stream
$stream = Streams::ofResource(@fopen($import_path, 'rb'));
$resource = @fopen($import_path, 'rb');

$stream = Streams::ofResource($resource);
$identification = $this->storage->manage()->stream($stream, $this->stakeholder, $filename);

// insert rid of the new resource into the data table
Expand All @@ -211,5 +205,9 @@ public function importLibraryFile(\ilImportMapping $a_mapping): void
$bib_id,
]
);
$this->import_bib_object->setResourceId($identification);
$this->import_bib_object->setMigrated(true);
$this->import_bib_object->update();
$this->import_bib_object->parseFileToDatabase();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,15 @@ public function init(): void

public function getValidSchemaVersions(string $a_entity): array
{
return array(
'4.5.0' => array(
'namespace' => 'http://www.ilias.de/Modules/DataCollection/dcl/4_5',
'xsd_file" => "ilias_dcl_4_5.xsd',
'uses_dataset' => true,
'min' => '4.5.0',
'max' => '',
),
);
return ['4.5.0' => ['namespace' => 'http://www.ilias.de/Modules/DataCollection/dcl/4_5', 'xsd_file" => "ilias_dcl_4_5.xsd', 'uses_dataset' => true, 'min' => '4.5.0', 'max' => '']];
}


public function getXmlRepresentation(string $a_entity, string $a_schema_version, string $a_id): string
{
ilFileUtils::makeDirParents($this->getAbsoluteExportDirectory());
$this->ds->initByExporter($this);
$this->ds->exportLibraryFile($a_id);
$this->ds->exportLibraryFile($a_id, $this->getAbsoluteExportDirectory());

return $this->ds->getXmlRepresentation($a_entity, $a_schema_version, [$a_id], '', true, true);
}
Expand All @@ -73,7 +65,7 @@ public function getXmlExportTailDependencies(
array $a_ids
): array {
$res = [];
if ($a_entity == "bibl") {
if ($a_entity === "bibl") {
$res[] = [
"component" => "components/ILIAS/ILIASObject",
"entity" => "common",
Expand Down

0 comments on commit 4c195e8

Please sign in to comment.