ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.ilTestImporter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26
28{
30 protected readonly TestImporter $importer;
32
33 public function __construct()
34 {
36
37 $local_dic = TestDIC::dic();
38 $this->session = $local_dic['exportimport.session'];
39 $this->importer = $local_dic['exportimport.importer'];
40
41 $this->legacy_importer = new ilTestLegacyImporter();
42 }
43
44 public function init(): void
45 {
47 $co_config = $this->imp->getConfig('components/ILIAS/COPage');
48 $co_config->setUpdateIfExists(true);
49
50 $this->legacy_importer->setImport($this->getImport());
51 $this->legacy_importer->setImportDirectory($this->getImportDirectory());
52 $this->legacy_importer->init();
53 }
54
55 public function importXmlRepresentation(
56 string $a_entity,
57 string $a_id,
58 string $a_xml,
59 ilImportMapping $a_mapping
60 ): void {
61 // Check if forward to legacy importer is needed
62 $session = $this->session->getSession();
63 if ($session->isLegacyImport()) {
64 $this->legacy_importer->setInstallId($this->getInstallId());
65 $this->legacy_importer->setInstallUrl($this->getInstallUrl());
66 $this->legacy_importer->setSchemaVersion($this->getSchemaVersion());
67 $this->legacy_importer->setSkipEntities($this->getSkipEntities());
68 $this->legacy_importer->importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping);
69 return;
70 }
71
72 $result = $this->importer->import(
73 XmlDeserializer::fromString($a_xml),
74 $a_mapping,
75 new ReferenceId($a_mapping->getTargetId()),
77 );
78 $this->session->setSession($result);
79 }
80
81 public function finalProcessing(ilImportMapping $a_mapping): void
82 {
83 // Check if forward to legacy importer is needed
84 $session = $this->session->getSession();
85 if ($session->isLegacyImport()) {
86 $this->legacy_importer->finalProcessing($a_mapping);
87 return;
88 }
89
90 $this->importer->finalize($a_mapping);
91 $this->finalizeTaxonomyUsage($a_mapping);
92 }
93
94 private function finalizeTaxonomyUsage(ilImportMapping $a_mapping): void
95 {
96 $tst_mappings = $a_mapping->getMappingsOfEntity('components/ILIAS/Test', 'tst');
97
98 foreach ($tst_mappings as $old => $new) {
99 if ($old === 'new_id' || (int) $old <= 0) {
100 continue;
101 }
102
103 $new_tax_ids = $a_mapping->getMapping(
104 'components/ILIAS/Taxonomy',
105 'tax_usage_of_obj',
106 (string) $old
107 );
108
109 if ($new_tax_ids !== null) {
110 $tax_ids = explode(':', $new_tax_ids);
111 foreach ($tax_ids as $tid) {
112 ilObjTaxonomy::saveUsage((int) $tid, (int) $new);
113 }
114 }
115 }
116 }
117}
Persists the import stage index and session across HTTP requests using \ilSession.
Orchestrates denormalization and persistence of a test import and its related resources.
getMapping(string $a_comp, string $a_entity, string $a_old_id)
getMappingsOfEntity(string $a_comp, string $a_entity)
static saveUsage(int $a_tax_id, int $a_obj_id)
readonly TestImporter $importer
finalizeTaxonomyUsage(ilImportMapping $a_mapping)
finalProcessing(ilImportMapping $a_mapping)
readonly ImportSessionRepository $session
importXmlRepresentation(string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
readonly ilTestLegacyImporter $legacy_importer
Xml importer class.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc