ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilContainerImporter.php
Go to the documentation of this file.
1<?php
2
25{
26 private string $structure_xml;
28 protected \ILIAS\Skill\Service\SkillProfileService $skill_profile_service;
29
30 public function init(): void
31 {
32 global $DIC;
33
34 $this->cont_log = ilLoggerFactory::getLogger('cont');
35 $this->skill_profile_service = $DIC->skills()->profile();
36 }
37
43 public function importXmlRepresentation(string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping): void
44 {
45 $this->structure_xml = $a_xml;
46 $this->cont_log->debug('Import xml: ' . $a_xml);
47 $this->cont_log->debug('Using id: ' . $a_id);
48
49 $parser = new ilContainerXmlParser($a_mapping, trim($a_xml));
50 $parser->parse($a_id);
51 }
52
56 public function finalProcessing(ilImportMapping $a_mapping): void
57 {
58 $this->handleOfflineStatus($this->structure_xml, $a_mapping);
59 // pages
60 $page_map = $a_mapping->getMappingsOfEntity('components/ILIAS/COPage', 'pg');
61 foreach ($page_map as $old_pg_id => $new_pg_id) {
62 $parts = explode(':', $old_pg_id);
63 $pg_type = $parts[0];
64 $old_obj_id = $parts[1];
65 $parts = explode(':', $new_pg_id);
66 $new_pg_id = array_pop($parts);
67 $new_obj_id = $a_mapping->getMapping('components/ILIAS/Container', 'objs', $old_obj_id);
68 // see bug #22718, this missed a check for the pg type
69 if ($new_obj_id > 0 && in_array($pg_type, ["crs", "grp", "fold", "cont"], true)) {
70 ilPageObject::_writeParentId($pg_type, (int) $new_pg_id, (int) $new_obj_id);
71 $this->cont_log->debug('write parent id, type: ' . $pg_type . ", page id: " . $new_pg_id . ", parent id: " . $new_obj_id);
72 }
73 }
74
75 // style
76 $sty_map = $a_mapping->getMappingsOfEntity('components/ILIAS/Style', 'sty');
77 foreach ($sty_map as $old_sty_id => $new_sty_id) {
78 if (isset(ilContainerXmlParser::$style_map[$old_sty_id])) {
79 foreach (ilContainerXmlParser::$style_map[$old_sty_id] as $obj_id) {
80 ilObjStyleSheet::writeStyleUsage((int) $obj_id, (int) $new_sty_id);
81 }
82 }
83 }
84
85 // skills
86 $crs_map = $a_mapping->getMappingsOfEntity('components/ILIAS/Course', 'crs');
87 $new_crs_obj_id = end($crs_map);
88 $new_crs_ref_ids = ilObject::_getAllReferences((int) $new_crs_obj_id);
89 $new_crs_ref_id = end($new_crs_ref_ids);
90
91 $skl_local_prof_map = $a_mapping->getMappingsOfEntity('components/ILIAS/Skill', 'skl_local_prof');
92 foreach ($skl_local_prof_map as $old_prof_id => $new_prof_id) {
93 $this->skill_profile_service->updateProfileRefIdAfterImport((int) $new_prof_id, (int) $new_crs_ref_id);
94 $this->skill_profile_service->addRoleToProfile(
95 (int) $new_prof_id,
96 ilParticipants::getDefaultMemberRole((int) $new_crs_ref_id)
97 );
98 }
99 }
100
101 protected function handleOfflineStatus(string $xml, ilImportMapping $mapping): void
102 {
103 $use_internal_errors = libxml_use_internal_errors(true);
104 $root = simplexml_load_string($xml);
105 libxml_use_internal_errors($use_internal_errors);
106 if ($root === false) {
107 $errors = '';
108 foreach (libxml_get_errors() as $err) {
109 $errors .= $err->code . '<br/>';
110 }
111 $this->cont_log->error($xml);
112 $this->cont_log->error('Cannot parse xml: ' . $errors);
113 }
114 foreach ($root->xpath('//Item') as $item) {
115 $ref_id = 0;
116 $offline = null;
117 foreach ($item->attributes() as $name => $value) {
118 if ((string) $name === 'Offline') {
119 $offline = $value;
120 }
121 if ((string) $name === 'RefId') {
122 $ref_id = (string) $value;
123 }
124 }
125 if (is_null($offline)) {
126 $this->cont_log->debug('No offline handling for ref_id: ' . $ref_id);
127 continue;
128 }
129 $new_ref_id = $mapping->getMapping('components/ILIAS/Container', 'refs', $ref_id);
130 $obj = ilObjectFactory::getInstanceByRefId((int) $new_ref_id, false);
131 if (!$obj instanceof ilObject) {
132 $this->cont_log->warning('Cannot create instance for ref_id: ' . $new_ref_id);
133 continue;
134 }
135 if ($obj->supportsOfflineHandling()) {
136 if ($this->isRootNode($obj->getRefId(), $mapping)) {
137 $obj->setOfflineStatus(true);
138 } else {
139 // use the offline status of the imported XML file and set the offline status for the new container objects accordingly
140 $obj->setOfflineStatus(!((string) $offline === "0"));
141 }
142 $obj->update();
143 }
144 }
145 }
146
147 protected function isRootNode(int $ref_id, ilImportMapping $mapping): bool
148 {
149 global $DIC;
150
151 $tree = $DIC->repositoryTree();
152 $parent_id = $tree->getParentId($ref_id);
153 if ($parent_id) {
154 return $parent_id === $mapping->getTargetId();
155 }
156 return false;
157 }
158}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
finalProcessing(ilImportMapping $a_mapping)
ILIAS Skill Service SkillProfileService $skill_profile_service
isRootNode(int $ref_id, ilImportMapping $mapping)
handleOfflineStatus(string $xml, ilImportMapping $mapping)
importXmlRepresentation(string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
Import XML.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getMapping(string $a_comp, string $a_entity, string $a_old_id)
getMappingsOfEntity(string $a_comp, string $a_entity)
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
static writeStyleUsage(int $a_obj_id, int $a_style_id)
Write style usage.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
Class ilObject Basic functions for all objects.
static _getAllReferences(int $id)
get all reference ids for object ID
static _writeParentId(string $a_parent_type, int $a_pg_id, int $a_par_id)
static getDefaultMemberRole(int $a_ref_id)
Xml importer class.
$ref_id
Definition: ltiauth.php:66
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
global $DIC
Definition: shib_login.php:26