ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMetaDataImporter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\MetaData\XML\Reader\ReaderInterface as StandardXMLReader;
25
27{
28 protected StandardXMLReader $reader;
30 protected ilLogger $logger;
31
32 public function init(): void
33 {
34 global $DIC;
35
36 $services = new InternalServices($DIC);
37
38 $this->reader = $services->xml()->standardReader();
39 $this->repository = $services->repository()->repository();
40 $this->logger = $DIC->logger()->meta();
41 }
42
43 public function importXmlRepresentation(
44 string $a_entity,
45 string $a_id,
46 string $a_xml,
47 ilImportMapping $a_mapping
48 ): void {
49 $new_id = $a_mapping->getMapping("components/ILIAS/MetaData", "md", $a_id);
50
51 if (!is_string($new_id) || $new_id === "") {
52 $this->logger->error(
53 'Import of LOM aborted for ' . $new_id . ', ID mapping failed.'
54 );
55 return;
56 }
57
58 $id = explode(":", $new_id);
59
60 $obj_id = (int) $id[0];
61 $sub_id = (int) $id[1];
62 $type = (string) $id[2];
63
64 if ($sub_id === 0) {
65 $sub_id = $obj_id;
66 }
67
68 $version = Version::tryFrom($this->getSchemaVersion());
69 if (is_null($version)) {
70 $this->logger->error(
71 'Import of LOM aborted for ' . $new_id .
72 ', invalid schema version: ' . $this->getSchemaVersion()
73 );
74 return;
75 }
76
77 $md = $this->reader->read(
78 new SimpleXMLElement($a_xml),
80 );
81 $this->repository->transferMD($md, $obj_id, $sub_id, $type, false);
82 }
83}
$version
Definition: plugin.php:24
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Component logger with individual log levels by component id.
importXmlRepresentation(string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
RepositoryInterface $repository
Xml importer class.
global $DIC
Definition: shib_login.php:26