ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilCOPageImporter.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/Export/classes/class.ilXmlImporter.php");
5
14{
18 protected $log;
19
23 protected $ds;
24
29 protected $importer_plugins = array();
30
34 public function init()
35 {
36 global $DIC;
38 $ilPluginAdmin = $DIC['ilPluginAdmin'];
39
40 include_once("./Services/COPage/classes/class.ilCOPageDataSet.php");
41 $this->ds = new ilCOPageDataSet();
42 $this->ds->setDSPrefix("ds");
43 $this->config = $this->getImport()->getConfig("Services/COPage");
44
45 $this->log = ilLoggerFactory::getLogger('copg');
46
47 // collect all page component plugins that have their own exporter
48 require_once('Services/COPage/classes/class.ilPageComponentPluginImporter.php');
49 foreach (ilPluginAdmin::getActivePluginsForSlot(IL_COMP_SERVICE, "COPage", "pgcp") as $plugin_name) {
50 if ($ilPluginAdmin->supportsExport(IL_COMP_SERVICE, "COPage", "pgcp", $plugin_name)) {
51 require_once('Customizing/global/plugins/Services/COPage/PageComponent/'
52 . $plugin_name . '/classes/class.il' . $plugin_name . 'Importer.php');
53
54 $this->importer_plugins[] = $plugin_name;
55 }
56 }
57 }
58
59
66 public function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
67 {
68 $this->log->debug("entity: " . $a_entity . ", id: " . $a_id);
69
70 if ($a_entity == "pgtp") {
71 include_once("./Services/DataSet/classes/class.ilDataSetImportParser.php");
73 $a_entity,
74 $this->getSchemaVersion(),
75 $a_xml,
76 $this->ds,
77 $a_mapping
78 );
79 }
80
81 if ($a_entity == "pg") {
82 $pg_id = $a_mapping->getMapping("Services/COPage", "pg", $a_id);
83
84 $this->log->debug("mapping id: " . $pg_id);
85
86 if ($pg_id != "") {
87 $id = explode(":", $pg_id);
88 if (count($id) == 2) {
89 include_once("./Services/COPage/classes/class.ilPageObjectFactory.php");
90
91 while (substr($a_xml, 0, 11) == "<PageObject") {
92 $l1 = strpos($a_xml, ">");
93
94 $page_tag = "<?xml version='1.0'?> " . substr($a_xml, 0, $l1 + 1) . "</PageObject>";
95 $page_data = simplexml_load_string($page_tag);
96 $lstr = $page_data['Language'];
97 $p = strpos($a_xml, "</PageObject>") + 13;
98 $next_xml = "<PageObject>" . substr($a_xml, $l1 + 1, $p - $l1 - 1);
99
100 if ($this->config->getForceLanguage() != "") {
101 $lstr = $this->config->getForceLanguage();
102 }
103 if ($lstr == "") {
104 $lstr = "-";
105 }
106 // see bug #0019049
107 $next_xml = str_replace("&amp;", "&", $next_xml);
108 if ($this->config->getUpdateIfExists() && ilPageObject::_exists($id[0], $id[1], $lstr)) {
109 $page = ilPageObjectFactory::getInstance($id[0], $id[1], 0, $lstr);
110 $page->setImportMode(true);
111 $page->setXMLContent($next_xml);
112 $page->updateFromXML();
113 $this->extractPluginProperties($page);
114 } else {
115 $new_page = ilPageObjectFactory::getInstance($id[0]);
116 $new_page->setImportMode(true);
117 $new_page->setId($id[1]);
118 if ($lstr != "" && $lstr != "-") {
119 $new_page->setLanguage($lstr);
120 }
121 $new_page->setXMLContent($next_xml);
122 $new_page->setActive(true);
123 // array_key_exists does NOT work on simplexml!
124 if (isset($page_data["Active"])) {
125 $new_page->setActive($page_data["Active"]);
126 }
127 $new_page->setActivationStart($page_data["ActivationStart"]);
128 $new_page->setActivationEnd($page_data["ActivationEnd"]);
129 $new_page->setShowActivationInfo($page_data["ShowActivationInfo"]);
130 $new_page->createFromXML();
131 $this->extractPluginProperties($new_page);
132 }
133
134 $a_xml = substr($a_xml, $p);
135 if ($lstr == "") {
136 $lstr = "-";
137 }
138 $a_mapping->addMapping("Services/COPage", "pgl", $a_id . ":" . $lstr, $pg_id . ":" . $lstr);
139 }
140 }
141 }
142 }
143 $this->log->debug("done");
144 }
145
151 public function finalProcessing($a_mapping)
152 {
153 $this->log->debug("start");
154 $pages = $a_mapping->getMappingsOfEntity("Services/COPage", "pgl");
155 $media_objects = $a_mapping->getMappingsOfEntity("Services/MediaObjects", "mob");
156 $file_objects = $a_mapping->getMappingsOfEntity("Modules/File", "file");
157
158 $ref_mapping = $a_mapping->getMappingsOfEntity('Services/Container', 'refs');
159
160 //if (count($media_objects) > 0 || count($file_objects) > 0)
161 //{
162 foreach ($pages as $p) {
163 $id = explode(":", $p);
164 if (count($id) == 3) {
165 include_once("./Services/COPage/classes/class.ilPageObject.php");
166 if (ilPageObject::_exists($id[0], $id[1], $id[2], true)) {
167 include_once("./Services/COPage/classes/class.ilPageObjectFactory.php");
168
170 $new_page = ilPageObjectFactory::getInstance($id[0], $id[1], 0, $id[2]);
171 $new_page->buildDom();
172 $med = $new_page->resolveMediaAliases($media_objects, $this->config->getReuseOriginallyExportedMedia());
173 $fil = $new_page->resolveFileItems($file_objects);
174 $new_page->resolveResources($ref_mapping);
175 $il = false;
176 if (!$this->config->getSkipInternalLinkResolve()) {
177 $il = $new_page->resolveIntLinks();
178 $this->log->debug("resolve internal link for page " . $id[0] . "-" . $id[1] . "-" . $id[2]);
179 }
180 $plug = $this->replacePluginProperties($new_page);
181 if ($med || $fil || $il || $plug) {
182 $new_page->update(false, true);
183 }
184 }
185 }
186 }
187 //}
188 $this->log->debug("end");
189 }
190
200 protected function extractPluginProperties($a_page)
201 {
202 if (empty($this->importer_plugins)) {
203 return;
204 }
205
206 $a_page->buildDom();
207 $domdoc = $a_page->getDomDoc();
208 $xpath = new DOMXPath($domdoc);
209 $nodes = $xpath->query("//PageContent[child::Plugged]");
210
212 foreach ($nodes as $pcnode) {
213 // page content id (unique in the page)
214 $pc_id = $pcnode->getAttribute('PCID');
215 $plnode = $pcnode->childNodes->item(0);
216 $plugin_name = $plnode->getAttribute('PluginName');
217 $plugin_version = $plnode->getAttribute('PluginVersion');
218
219 // additional data will be imported
220 if (in_array($plugin_name, $this->importer_plugins)) {
221 // get the id of the mapped plugged page content
222 $id = $a_page->getParentType()
223 . ':' . $a_page->getId()
224 . ':' . $a_page->getLanguage()
225 . ':' . $pc_id;
226
227 $properties = array();
229 foreach ($plnode->childNodes as $child) {
230 $properties[$child->getAttribute('Name')] = $child->nodeValue;
231 }
232
233 // statical provision of content to the pluged importer classes
236 }
237 }
238 }
239
251 public function replacePluginProperties($a_page)
252 {
253 if (empty($this->importer_plugins)) {
254 return false;
255 }
256
257 $a_page->buildDom();
258 $domdoc = $a_page->getDomDoc();
259 $xpath = new DOMXPath($domdoc);
260 $nodes = $xpath->query("//PageContent[child::Plugged]");
261
262 $modified = false;
263
265 foreach ($nodes as $pcnode) {
266 // page content id (unique in the page)
267 $pc_id = $pcnode->getAttribute('PCID');
268 $plnode = $pcnode->childNodes->item(0);
269 $plugin_name = $plnode->getAttribute('PluginName');
270
271 // get the id of the mapped plugged page content
272 $id = $a_page->getParentType()
273 . ':' . $a_page->getId()
274 . ':' . $a_page->getLanguage()
275 . ':' . $pc_id;
276
277 $plugin_version = ilPageComponentPluginImporter::getPCVersion($id);
279
280 // update the version if modified by the plugin importer
281 if (isset($plugin_version)) {
282 $plnode->setAttribute('PluginVersion', $plugin_version);
283 $modified = true;
284 }
285
286 // update the properties if modified by the plugin importer
287 if (is_array($properties)) {
289 foreach ($plnode->childNodes as $child) {
290 $plnode->removeChild($child);
291 }
292 foreach ($properties as $name => $value) {
293 $child = new DOMElement('PluggedProperty', $value);
294 $plnode->appendChild($child);
295 $child->setAttribute('Name', $name);
296 }
297 $modified = true;
298 }
299 }
300
301 return $modified;
302 }
303}
$parser
Definition: BPMN2Parser.php:23
An exception for terminatinating execution or to throw for unit testing.
const IL_COMP_SERVICE
COPage Data set class.
Importer class for pages.
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
Import XML.
Manifest parser for ILIAS standard export files.
static getLogger($a_component_id)
Get component logger.
static getPCProperties($a_id)
Get the properties of a plugged page content.
static getPCVersion($a_id)
Get the version of a plugged page content.
static setPCProperties($a_id, $a_properties)
Set the properties of a plugged page content This method is used by ilCOPageExporter to provide the p...
static setPCVersion($a_id, $a_version)
Set the version of a plugged page content This method is used by ilCOPageExporter to provide the vers...
static getInstance($a_parent_type, $a_id=0, $a_old_nr=0, $a_lang="-")
Get page object instance.
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
static getActivePluginsForSlot($a_ctype, $a_cname, $a_slot_id)
Get all active plugins for a slot.
Xml importer class.
getSchemaVersion()
Get schema version.
getImport()
Get import.
finalProcessing($a_mapping)
Final processing.
if($format !==null) $name
Definition: metadata.php:230
$DIC
Definition: xapitoken.php:46