ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilGlossaryImporter.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
12{
16 public function init()
17 {
18 $this->ds = new ilGlossaryDataSet();
19 $this->ds->setDSPrefix("ds");
20 $this->config = $this->getImport()->getConfig("Modules/Glossary");
21 }
22
29 public function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
30 {
31 if ($a_entity == "glo") {
32 // case i container
33 if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
34 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
35 }
36
37 // in the new version (5.1) we are also here, but the following file should not exist
38 // if being exported with 5.1 or higher
39 $xml_file = $this->getImportDirectory() . '/' . basename($this->getImportDirectory()) . '.xml';
40 $GLOBALS['ilLog']->write(__METHOD__ . ': Using XML file ' . $xml_file);
41
42 // old school import
43 if (file_exists($xml_file)) {
44 if (!is_object($newObj)) {
45 // create and insert object in objecttree
46 $newObj = new ilObjGlossary();
47 $newObj->setType("glo");
48 $newObj->setTitle(basename($this->getImportDirectory()));
49 $newObj->create(true);
50 }
51
52 $contParser = new ilContObjParser(
53 $newObj,
54 $xml_file,
55 basename($this->getImportDirectory())
56 );
57
58 $contParser->startParsing();
59
60 ilObject::_writeImportId($newObj->getId(), $newObj->getImportId());
61
62 // write term map for taxonomies to mapping object
63 $term_map = $contParser->getGlossaryTermMap();
64 foreach ($term_map as $k => $v) {
65 $a_mapping->addMapping(
66 "Services/Taxonomy",
67 "tax_item",
68 "glo:term:" . $k,
69 $v
70 );
71
72 // this is since 4.3 does not export these ids but 4.4 tax node assignment needs it
73 $a_mapping->addMapping(
74 "Services/Taxonomy",
75 "tax_item_obj_id",
76 "glo:term:" . $k,
77 $newObj->getId()
78 );
79
80 $a_mapping->addMapping(
81 "Services/AdvancedMetaData",
82 "advmd_sub_item",
83 "advmd:term:" . $k,
84 $v
85 );
86 }
87
88 $a_mapping->addMapping("Modules/Glossary", "glo", $a_id, $newObj->getId());
89 $a_mapping->addMapping("Services/AdvancedMetaData", "parent", $a_id, $newObj->getId());
90
91 $this->current_glo = $newObj;
92 } else {
93 // necessary?
94 // ilObject::_writeImportId($newObj->getId(), $newObj->getImportId());
95 $parser = new ilDataSetImportParser(
96 $a_entity,
97 $this->getSchemaVersion(),
98 $a_xml,
99 $this->ds,
100 $a_mapping
101 );
102
103 // in the new version the mapping above is done in the dataset
104 }
105 }
106 }
107
114 public function finalProcessing($a_mapping)
115 {
116
117 // get all glossaries of the import
118 $maps = $a_mapping->getMappingsOfEntity("Modules/Glossary", "glo");
119 foreach ($maps as $old => $new) {
120 if ($old != "new_id" && (int) $old > 0) {
121 // get all new taxonomys of this object
122 $new_tax_ids = $a_mapping->getMapping("Services/Taxonomy", "tax_usage_of_obj", $old);
123 if ($new_tax_ids !== false) {
124 $tax_ids = explode(":", $new_tax_ids);
125 foreach ($tax_ids as $tid) {
126 ilObjTaxonomy::saveUsage($tid, $new);
127 }
128 }
129
130 // advmd column order
131 if ($this->exportedFromSameInstallation()) {
132 $advmdco = $a_mapping->getMappingsOfEntity("Modules/Glossary", "advmd_col_order");
133 foreach ($advmdco as $id => $order) {
134 $id = explode(":", $id);
135 $field_glo_id = $id[0];
136 $field_id = $id[1];
137 if ($field_glo_id == $old) {
138 // #17454
139 $new_local_id = $a_mapping->getMapping("Services/AdvancedMetaData", "lfld", $field_id);
140 if ($new_local_id) {
141 $field_id = $new_local_id;
142 }
143 ilGlossaryAdvMetaDataAdapter::writeColumnOrder($new, $field_id, $order);
144 }
145 }
146 }
147 }
148 }
149 }
150}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
Content Object Parser.
Manifest parser for ILIAS standard export files.
static writeColumnOrder($a_glo_id, $a_field_id, $a_order_nr)
Write single column order.
Glossary Data set class.
Importer class for files.
finalProcessing($a_mapping)
Final processing.
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
Import XML.
Class ilObjGlossary.
static saveUsage($a_tax_id, $a_obj_id)
Save Usage.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
Xml importer class.
getSchemaVersion()
Get schema version.
getImport()
Get import.
getImportDirectory()
Get import directory.
exportedFromSameInstallation()
Is exporting and importing installation identical?