ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCOPageImporter.php
Go to the documentation of this file.
1<?php
2
24{
26 protected ilLogger $log;
28 // Names of active plugins with own importers for additional data
29 protected array $importer_plugins = array();
30
31 public function init(): void
32 {
33 global $DIC;
35 $component_repository = $DIC["component.repository"];
36
37 $this->ds = new ilCOPageDataSet();
38 $this->ds->setDSPrefix("ds");
39 $this->config = $this->getImport()->getConfig("components/ILIAS/COPage");
40
41 $this->log = ilLoggerFactory::getLogger('copg');
42
43 // collect all page component plugins that have their own exporter
44 foreach ($component_repository->getPluginSlotById("pgcp")->getActivePlugins() as $plugin) {
45 $plugin_name = $plugin->getName();
46 if ($plugin->supportsExport()) {
47 $this->importer_plugins[] = $plugin_name;
48 }
49 }
50 }
51
52 public function importXmlRepresentation(
53 string $a_entity,
54 string $a_id,
55 string $a_xml,
56 ilImportMapping $a_mapping
57 ): void {
58 $this->log->debug("entity: " . $a_entity . ", id: " . $a_id);
59
60 if ($a_entity == "pgtp") {
61 $parser = new ilDataSetImportParser(
62 $a_entity,
63 $this->getSchemaVersion(),
64 $a_xml,
65 $this->ds,
66 $a_mapping
67 );
68 }
69
70 if ($a_entity == "pg") {
71 $pg_id = $a_mapping->getMapping("components/ILIAS/COPage", "pg", $a_id);
72
73 $this->log->debug("mapping id: " . $pg_id);
74 if ($pg_id != "") {
75 $id = explode(":", $pg_id);
76 if (count($id) == 2) {
77 while (substr($a_xml, 0, 11) == "<PageObject") {
78 $l1 = strpos($a_xml, ">");
79
80 $page_tag = "<?xml version='1.0'?> " . substr($a_xml, 0, $l1 + 1) . "</PageObject>";
81 $page_data = simplexml_load_string($page_tag);
82 $lstr = $page_data['Language'];
83 $p = strpos($a_xml, "</PageObject>") + 13;
84 $next_xml = "<PageObject>" . substr($a_xml, $l1 + 1, $p - $l1 - 1);
85
86 if ($this->config->getForceLanguage() != "") {
87 $lstr = $this->config->getForceLanguage();
88 }
89 if ($lstr == "") {
90 $lstr = "-";
91 }
92 // see bug #0019049
93 $next_xml = str_replace("&amp;", "&", $next_xml);
94 if ($this->config->getUpdateIfExists() && ilPageObject::_exists($id[0], $id[1], $lstr)) {
95 $page = ilPageObjectFactory::getInstance($id[0], $id[1], 0, $lstr);
96 $page->setImportMode(true);
97 $page->setXMLContent($next_xml);
98 $page->updateFromXML();
99 $this->extractPluginProperties($page);
100 } else {
101 // #31937, #39229 (added lang === "-")
102 if ($lstr === "-" && ilPageObject::_exists($id[0], (int) $id[1], "-", true)) {
103 return;
104 }
106 $new_page->setImportMode(true);
107 $new_page->setId($id[1]);
108 if ($lstr != "" && $lstr != "-") {
109 $new_page->setLanguage($lstr);
110 }
111 $this->log->debug(">>> CREATE PAGE " . $id[0] . ":" . $id[1]);
112 $new_page->setXMLContent($next_xml);
113 $new_page->setActive(true);
114 // array_key_exists does NOT work on simplexml!
115 if (isset($page_data["Active"])) {
116 $new_page->setActive((string) $page_data["Active"]);
117 }
118 $new_page->setActivationStart($page_data["ActivationStart"]);
119 $new_page->setActivationEnd($page_data["ActivationEnd"]);
120 $new_page->setShowActivationInfo((string) $page_data["ShowActivationInfo"]);
121 $new_page->createFromXML();
122 $this->extractPluginProperties($new_page);
123 }
124
125 $a_xml = substr($a_xml, $p);
126 if ($lstr == "") {
127 $lstr = "-";
128 }
129 $a_mapping->addMapping("components/ILIAS/COPage", "pgl", $a_id . ":" . $lstr, $pg_id . ":" . $lstr);
130 }
131 }
132 }
133 }
134 $this->log->debug("done");
135 }
136
137 public function finalProcessing(
138 ilImportMapping $a_mapping
139 ): void {
140 $this->log->debug("start");
141 $pages = $a_mapping->getMappingsOfEntity("components/ILIAS/COPage", "pgl");
142 $media_objects = $a_mapping->getMappingsOfEntity("components/ILIAS/MediaObjects", "mob");
143 $file_objects = $a_mapping->getMappingsOfEntity("components/ILIAS/File", "file");
144
145 $ref_mapping = $a_mapping->getMappingsOfEntity('components/ILIAS/Container', 'refs');
146
147 foreach ($pages as $p) {
148 $id = explode(":", $p);
149 if (count($id) == 3) {
150 if (ilPageObject::_exists($id[0], $id[1], $id[2], true)) {
152 $new_page = ilPageObjectFactory::getInstance($id[0], $id[1], 0, $id[2]);
153 $new_page->buildDom();
154 $med = $new_page->resolveMediaAliases($media_objects, $this->config->getReuseOriginallyExportedMedia());
155 $fil = $new_page->resolveFileItems($file_objects);
156 $res = $new_page->resolveResources($ref_mapping);
157 $il = false;
158 if (!$this->config->getSkipInternalLinkResolve()) {
159 $il = $new_page->resolveIntLinks();
160 $this->log->debug("resolve internal link for page " . $id[0] . "-" . $id[1] . "-" . $id[2]);
161 }
162 $plug = $this->replacePluginProperties($new_page);
163 if ($med || $fil || $il || $plug || $res) {
164 $new_page->update(false, true);
165 }
166 }
167 }
168 }
169 $this->log->debug("end");
170 }
171
173 ilImportMapping $a_mapping
174 ): void {
175 }
176
184 protected function extractPluginProperties(
185 ilPageObject $a_page
186 ): void {
187 if (empty($this->importer_plugins)) {
188 return;
189 }
190
191 $a_page->buildDom();
192 $domdoc = $a_page->getDomDoc();
193 $xpath = new DOMXPath($domdoc);
194 $nodes = $xpath->query("//PageContent[child::Plugged]");
195
197 foreach ($nodes as $pcnode) {
198 // page content id (unique in the page)
199 $pc_id = $pcnode->getAttribute('PCID');
200 $plnode = $pcnode->childNodes->item(0);
201 $plugin_name = $plnode->getAttribute('PluginName');
202 $plugin_version = $plnode->getAttribute('PluginVersion');
203
204 // additional data will be imported
205 if (in_array($plugin_name, $this->importer_plugins)) {
206 // get the id of the mapped plugged page content
207 $id = $a_page->getParentType()
208 . ':' . $a_page->getId()
209 . ':' . $a_page->getLanguage()
210 . ':' . $pc_id;
211
212 $properties = array();
214 foreach ($plnode->childNodes as $child) {
215 $properties[$child->getAttribute('Name')] = $child->nodeValue;
216 }
217
218 // statical provision of content to the pluged importer classes
221 }
222 }
223 }
224
233 public function replacePluginProperties(
234 ilPageObject $a_page
235 ): bool {
236 if (empty($this->importer_plugins)) {
237 return false;
238 }
239
240 $a_page->buildDom();
241 $domdoc = $a_page->getDomDoc();
242 $xpath = new DOMXPath($domdoc);
243 $nodes = $xpath->query("//PageContent[child::Plugged]");
244
245 $modified = false;
246
248 foreach ($nodes as $pcnode) {
249 // page content id (unique in the page)
250 $pc_id = $pcnode->getAttribute('PCID');
251 $plnode = $pcnode->childNodes->item(0);
252 $plugin_name = $plnode->getAttribute('PluginName');
253
254 // get the id of the mapped plugged page content
255 $id = $a_page->getParentType()
256 . ':' . $a_page->getId()
257 . ':' . $a_page->getLanguage()
258 . ':' . $pc_id;
259
262
263 // update the version if modified by the plugin importer
264 if (isset($plugin_version)) {
265 $plnode->setAttribute('PluginVersion', $plugin_version);
266 $modified = true;
267 }
268
269 // update the properties if modified by the plugin importer
270 if (is_array($properties)) {
272 foreach ($plnode->childNodes as $child) {
273 $plnode->removeChild($child);
274 }
275 foreach ($properties as $name => $value) {
276 $child = new DOMElement('PluggedProperty', $value);
277 $plnode->appendChild($child);
278 $child->setAttribute('Name', $name);
279 }
280 $modified = true;
281 }
282 }
283
284 return $modified;
285 }
286}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
importXmlRepresentation(string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
afterContainerImportProcessing(ilImportMapping $a_mapping)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Import configuration class parent class.
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
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 getPCProperties(string $a_id)
Get the properties of a plugged page content.
static getPCVersion(string $a_id)
Get the version of a plugged page content.
static setPCVersion(string $a_id, string $a_version)
Set the version of a plugged page content This method is used by ilCOPageExporter to provide the vers...
static setPCProperties(string $a_id, array $a_properties)
Set the properties of a plugged page content This method is used by ilCOPageExporter to provide the p...
static getInstance(string $a_parent_type, int $a_id=0, int $a_old_nr=0, string $a_lang="-")
Get page object instance.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
Xml importer class.
$res
Definition: ltiservices.php:69
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26