ILIAS  trunk Revision v12.0_alpha-1329-g1094ddb0c33
ilContainerImporter Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilContainerImporter:
+ Collaboration diagram for ilContainerImporter:

Public Member Functions

 init ()
 
 importXmlRepresentation (string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
 Import XML. More...
 
 finalProcessing (ilImportMapping $a_mapping)
 
- Public Member Functions inherited from ilXmlImporter
 __construct ()
 
 setImport (ilImport $a_val)
 
 getImport ()
 
 init ()
 
 setInstallId (string $a_val)
 
 getInstallId ()
 
 setInstallUrl (string $a_val)
 
 getInstallUrl ()
 
 setSchemaVersion (string $a_val)
 
 getSchemaVersion ()
 
 setImportDirectory (string $a_val)
 
 getImportDirectory ()
 
 setSkipEntities (array $a_val)
 
 getSkipEntities ()
 
 exportedFromSameInstallation ()
 
 importXmlRepresentation (string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
 
 finalProcessing (ilImportMapping $a_mapping)
 
 afterContainerImportProcessing (ilImportMapping $mapping)
 

Protected Member Functions

 handleOfflineStatus (string $xml, ilImportMapping $mapping)
 
 isRootNode (int $ref_id, ilImportMapping $mapping)
 

Protected Attributes

ilLogger $cont_log
 
ILIAS Skill Service SkillProfileService $skill_profile_service
 
string $import_id
 
TranslationsRepository $translations_repository
 
- Protected Attributes inherited from ilXmlImporter
array $skip_entities = array()
 
ilImport $imp
 
string $install_id
 
string $install_url
 
string $schema_version
 
string $import_directory
 

Private Attributes

string $structure_xml
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning container xml importer

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 27 of file class.ilContainerImporter.php.

Member Function Documentation

◆ finalProcessing()

ilContainerImporter::finalProcessing ( ilImportMapping  $a_mapping)

Reimplemented from ilXmlImporter.

Definition at line 69 of file class.ilContainerImporter.php.

69 : void
70 {
71 $this->handleOfflineStatus($this->structure_xml, $a_mapping);
72 // pages
73 $page_map = $a_mapping->getMappingsOfEntity('components/ILIAS/COPage', 'pg');
74 foreach ($page_map as $old_pg_id => $new_pg_id) {
75 $parts = explode(':', $old_pg_id);
76 $pg_type = $parts[0];
77 $old_obj_id = $parts[1];
78 $parts = explode(':', $new_pg_id);
79 $new_pg_id = array_pop($parts);
80 $new_obj_id = $a_mapping->getMapping('components/ILIAS/Container', 'objs', $old_obj_id);
81 // see bug #22718, this missed a check for the pg type
82 if ($new_obj_id > 0 && in_array($pg_type, ["crs", "grp", "fold", "cont"], true)) {
83 ilPageObject::_writeParentId($pg_type, (int) $new_pg_id, (int) $new_obj_id);
84 $this->cont_log->debug('write parent id, type: ' . $pg_type . ", page id: " . $new_pg_id . ", parent id: " . $new_obj_id);
85 }
86 }
87
88 // style
89 $sty_map = $a_mapping->getMappingsOfEntity('components/ILIAS/Style', 'sty');
90 foreach ($sty_map as $old_sty_id => $new_sty_id) {
91 if (isset(ilContainerXmlParser::$style_map[$old_sty_id])) {
92 foreach (ilContainerXmlParser::$style_map[$old_sty_id] as $obj_id) {
93 ilObjStyleSheet::writeStyleUsage((int) $obj_id, (int) $new_sty_id);
94 }
95 }
96 }
97
98 // skills
99 $crs_map = $a_mapping->getMappingsOfEntity('components/ILIAS/Course', 'crs');
100 $new_crs_obj_id = end($crs_map);
101 $new_crs_ref_ids = ilObject::_getAllReferences((int) $new_crs_obj_id);
102 $new_crs_ref_id = end($new_crs_ref_ids);
103
104 $skl_local_prof_map = $a_mapping->getMappingsOfEntity('components/ILIAS/Skill', 'skl_local_prof');
105 foreach ($skl_local_prof_map as $old_prof_id => $new_prof_id) {
106 $this->skill_profile_service->updateProfileRefIdAfterImport((int) $new_prof_id, (int) $new_crs_ref_id);
107 $this->skill_profile_service->addRoleToProfile(
108 (int) $new_prof_id,
109 ilParticipants::getDefaultMemberRole((int) $new_crs_ref_id)
110 );
111 }
112
113 # Patch Start: Fix multilingualism replaces course title
114 $obj_id = (int) $a_mapping->getMapping('components/ILIAS/ILIASObject', 'obj', $this->import_id);
115 $translations = $this->translations_repository->getFor($obj_id);
116 $translations_new = new Translations($translations->getObjId(), [], $translations->getDefaultLanguage(), $translations->getBaseLanguage());
117 $languages = $translations->getLanguages();
118 foreach ($languages as $language) {
119 $translations_new = $language->getTitle() === 'NO TITLE'
120 ? $translations_new
121 : $translations_new->withLanguage($language);
122 }
123 $this->translations_repository->store($translations_new);
124 # Patch End: Fix multilingualism replaces course title
125 }
handleOfflineStatus(string $xml, ilImportMapping $mapping)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
getMappingsOfEntity(string $a_comp, string $a_entity)
static writeStyleUsage(int $a_obj_id, int $a_style_id)
Write style usage.
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)
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61

References $parts, ilContainerXmlParser\$style_map, ilObject\_getAllReferences(), ilPageObject\_writeParentId(), ilParticipants\getDefaultMemberRole(), ilImportMapping\getMapping(), ilImportMapping\getMappingsOfEntity(), handleOfflineStatus(), ILIAS\Repository\int(), and ilObjStyleSheet\writeStyleUsage().

+ Here is the call graph for this function:

◆ handleOfflineStatus()

ilContainerImporter::handleOfflineStatus ( string  $xml,
ilImportMapping  $mapping 
)
protected

Definition at line 127 of file class.ilContainerImporter.php.

127 : void
128 {
129 $use_internal_errors = libxml_use_internal_errors(true);
130 $root = simplexml_load_string($xml);
131 libxml_use_internal_errors($use_internal_errors);
132 if ($root === false) {
133 $errors = '';
134 foreach (libxml_get_errors() as $err) {
135 $errors .= $err->code . '<br/>';
136 }
137 $this->cont_log->error($xml);
138 $this->cont_log->error('Cannot parse xml: ' . $errors);
139 }
140 foreach ($root->xpath('//Item') as $item) {
141 $ref_id = 0;
142 $offline = null;
143 foreach ($item->attributes() as $name => $value) {
144 if ((string) $name === 'Offline') {
145 $offline = $value;
146 }
147 if ((string) $name === 'RefId') {
148 $ref_id = (string) $value;
149 }
150 }
151 if (is_null($offline)) {
152 $this->cont_log->debug('No offline handling for ref_id: ' . $ref_id);
153 continue;
154 }
155 $new_ref_id = $mapping->getMapping('components/ILIAS/Container', 'refs', $ref_id);
156 $obj = ilObjectFactory::getInstanceByRefId((int) $new_ref_id, false);
157 if (!$obj instanceof ilObject) {
158 $this->cont_log->warning('Cannot create instance for ref_id: ' . $new_ref_id);
159 continue;
160 }
161 if ($obj->supportsOfflineHandling()) {
162 if ($this->isRootNode($obj->getRefId(), $mapping)) {
163 $obj->setOfflineStatus(true);
164 } else {
165 // use the offline status of the imported XML file and set the offline status for the new container objects accordingly
166 $obj->setOfflineStatus(!((string) $offline === "0"));
167 }
168 $obj->update();
169 }
170 }
171 }
isRootNode(int $ref_id, ilImportMapping $mapping)
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.
$ref_id
Definition: ltiauth.php:66

References $ref_id, ilObjectFactory\getInstanceByRefId(), ilImportMapping\getMapping(), and isRootNode().

Referenced by finalProcessing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importXmlRepresentation()

ilContainerImporter::importXmlRepresentation ( string  $a_entity,
string  $a_id,
string  $a_xml,
ilImportMapping  $a_mapping 
)

Import XML.

Reimplemented from ilXmlImporter.

Definition at line 52 of file class.ilContainerImporter.php.

52 : void
53 {
54 $this->structure_xml = $a_xml;
55 $this->cont_log->debug('Import xml: ' . $a_xml);
56 $this->cont_log->debug('Using id: ' . $a_id);
57
58 $parser = new ilContainerXmlParser($a_mapping, trim($a_xml));
59 $parser->parse($a_id);
60
61 # Patch Start: Fix multilingualism replaces course title
62 $this->import_id = $a_id;
63 # Patch End: Fix multilingualism replaces course title
64 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ init()

ilContainerImporter::init ( )

Reimplemented from ilXmlImporter.

Definition at line 38 of file class.ilContainerImporter.php.

38 : void
39 {
40 global $DIC;
41
42 $this->translations_repository = new TranslationsRepository($DIC->database());
43 $this->cont_log = ilLoggerFactory::getLogger('cont');
44 $this->skill_profile_service = $DIC->skills()->profile();
45 }
static getLogger(string $a_component_id)
Get component logger.
global $DIC
Definition: shib_login.php:26

References $DIC, and ilLoggerFactory\getLogger().

+ Here is the call graph for this function:

◆ isRootNode()

ilContainerImporter::isRootNode ( int  $ref_id,
ilImportMapping  $mapping 
)
protected

Definition at line 173 of file class.ilContainerImporter.php.

173 : bool
174 {
175 global $DIC;
176
177 $tree = $DIC->repositoryTree();
178 $parent_id = $tree->getParentId($ref_id);
179 if ($parent_id) {
180 return $parent_id === $mapping->getTargetId();
181 }
182 return false;
183 }

References $DIC, $ref_id, and ilImportMapping\getTargetId().

Referenced by handleOfflineStatus().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $cont_log

ilLogger ilContainerImporter::$cont_log
protected

Definition at line 30 of file class.ilContainerImporter.php.

◆ $import_id

string ilContainerImporter::$import_id
protected

Definition at line 34 of file class.ilContainerImporter.php.

◆ $skill_profile_service

ILIAS Skill Service SkillProfileService ilContainerImporter::$skill_profile_service
protected

Definition at line 31 of file class.ilContainerImporter.php.

◆ $structure_xml

string ilContainerImporter::$structure_xml
private

Definition at line 29 of file class.ilContainerImporter.php.

◆ $translations_repository

TranslationsRepository ilContainerImporter::$translations_repository
protected

Definition at line 35 of file class.ilContainerImporter.php.


The documentation for this class was generated from the following file: