ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
28 function init()
29 {
30 include_once("./Services/COPage/classes/class.ilCOPageDataSet.php");
31 $this->ds = new ilCOPageDataSet();
32 $this->ds->setDSPrefix("ds");
33 $this->config = $this->getImport()->getConfig("Services/COPage");
34
35 $this->log = ilLoggerFactory::getLogger('copg');
36 }
37
38
45 function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
46 {
47 $this->log->debug("entity: ".$a_entity.", id: ".$a_id);
48
49 if ($a_entity == "pgtp")
50 {
51 include_once("./Services/DataSet/classes/class.ilDataSetImportParser.php");
52 $parser = new ilDataSetImportParser($a_entity, $this->getSchemaVersion(),
53 $a_xml, $this->ds, $a_mapping);
54 }
55
56 if ($a_entity == "pg")
57 {
58 $pg_id = $a_mapping->getMapping("Services/COPage", "pg", $a_id);
59
60 $this->log->debug("mapping id: ".$pg_id);
61
62 if ($pg_id != "")
63 {
64 $id = explode(":", $pg_id);
65 if (count($id) == 2)
66 {
67 include_once("./Services/COPage/classes/class.ilPageObjectFactory.php");
68
69 while (substr($a_xml, 0, 11) == "<PageObject")
70 {
71 $l1 = strpos($a_xml, ">");
72
73 $page_tag = "<?xml version='1.0'?> ".substr($a_xml, 0, $l1+1)."</PageObject>";
74 $page_data = simplexml_load_string($page_tag);
75 $lstr = $page_data['Language'];
76 $p = strpos($a_xml, "</PageObject>") + 13;
77 $next_xml = "<PageObject>".substr($a_xml, $l1+1, $p - $l1 -1);
78
79 if ($this->config->getForceLanguage() != "")
80 {
81 $lstr = $this->config->getForceLanguage();
82 }
83 if ($lstr == "")
84 {
85 $lstr = "-";
86 }
87 // see bug #0019049
88 $next_xml = str_replace("&amp;", "&", $next_xml);
89 if ($this->config->getUpdateIfExists() && ilPageObject::_exists($id[0], $id[1], $lstr))
90 {
91 $page = ilPageObjectFactory::getInstance($id[0], $id[1], 0, $lstr);
92 $page->setImportMode(true);
93 $page->setXMLContent($next_xml);
94 $page->updateFromXML();
95 }
96 else
97 {
98 $new_page = ilPageObjectFactory::getInstance($id[0]);
99 $new_page->setImportMode(true);
100 $new_page->setId($id[1]);
101 if ($lstr != "" && $lstr != "-")
102 {
103 $new_page->setLanguage($lstr);
104 }
105 $new_page->setXMLContent($next_xml);
106 $new_page->setActive(true);
107 // array_key_exists does NOT work on simplexml!
108 if (isset($page_data["Active"]))
109 {
110 $new_page->setActive($page_data["Active"]);
111 }
112 $new_page->setActivationStart($page_data["ActivationStart"]);
113 $new_page->setActivationEnd($page_data["ActivationEnd"]);
114 $new_page->setShowActivationInfo($page_data["ShowActivationInfo"]);
115 $new_page->createFromXML();
116 }
117
118 $a_xml = substr($a_xml, $p);
119 if ($lstr == "")
120 {
121 $lstr = "-";
122 }
123 $a_mapping->addMapping("Services/COPage", "pgl", $a_id.":".$lstr, $pg_id.":".$lstr);
124 }
125 }
126 }
127 }
128 $this->log->debug("done");
129 }
130
136 function finalProcessing($a_mapping)
137 {
138 $this->log->debug("start");
139 $pages = $a_mapping->getMappingsOfEntity("Services/COPage", "pgl");
140 $media_objects = $a_mapping->getMappingsOfEntity("Services/MediaObjects", "mob");
141 $file_objects = $a_mapping->getMappingsOfEntity("Modules/File", "file");
142 //if (count($media_objects) > 0 || count($file_objects) > 0)
143 //{
144 foreach ($pages as $p)
145 {
146 $id = explode(":", $p);
147 if (count($id) == 3)
148 {
149 include_once("./Services/COPage/classes/class.ilPageObject.php");
150 if (ilPageObject::_exists($id[0], $id[1], $id[2], true))
151 {
152 include_once("./Services/COPage/classes/class.ilPageObjectFactory.php");
153 $new_page = ilPageObjectFactory::getInstance($id[0], $id[1], 0, $id[2]);
154 $new_page->buildDom();
155 $med = $new_page->resolveMediaAliases($media_objects, $this->config->getReuseOriginallyExportedMedia());
156 $fil = $new_page->resolveFileItems($file_objects);
157 $il = false;
158 if (!$this->config->getSkipInternalLinkResolve())
159 {
160 $il = $new_page->resolveIntLinks();
161 $this->log->debug("resolve internal link for page ".$id[0]."-".$id[1]."-".$id[2]);
162 }
163 if ($med || $fil || $il)
164 {
165 $new_page->update(false, true);
166 }
167 }
168 }
169 }
170 //}
171 $this->log->debug("end");
172 }
173}
174
175?>
COPage Data set class.
Importer class for pages.
finalProcessing($a_mapping)
Final processing.
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 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.
Xml importer class.
getSchemaVersion()
Get schema version.
getImport()
Get import.