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