ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 include_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 
143  $ref_mapping = $a_mapping->getMappingsOfEntity('Services/Container', 'refs');
144 
145  //if (count($media_objects) > 0 || count($file_objects) > 0)
146  //{
147  foreach ($pages as $p)
148  {
149  $id = explode(":", $p);
150  if (count($id) == 3)
151  {
152  include_once("./Services/COPage/classes/class.ilPageObject.php");
153  if (ilPageObject::_exists($id[0], $id[1], $id[2], true))
154  {
155  include_once("./Services/COPage/classes/class.ilPageObjectFactory.php");
156 
158  $new_page = ilPageObjectFactory::getInstance($id[0], $id[1], 0, $id[2]);
159  $new_page->buildDom();
160  $med = $new_page->resolveMediaAliases($media_objects, $this->config->getReuseOriginallyExportedMedia());
161  $fil = $new_page->resolveFileItems($file_objects);
162  $res = $new_page->resolveResources($ref_mapping);
163  $il = false;
164  if (!$this->config->getSkipInternalLinkResolve())
165  {
166  $il = $new_page->resolveIntLinks();
167  $this->log->debug("resolve internal link for page ".$id[0]."-".$id[1]."-".$id[2]);
168  }
169  if ($med || $fil || $il || $res)
170  {
171  $new_page->update(false, true);
172  }
173  }
174  }
175  }
176  //}
177  $this->log->debug("end");
178  }
179 }
180 
181 ?>
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
getSchemaVersion()
Get schema version.
COPage Data set class.
Manifest parser for ILIAS standard export files.
init()
Initialisation.
Importer class for pages.
getImport()
Get import.
finalProcessing($a_mapping)
Final processing.
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
Import XML.
static getInstance($a_parent_type, $a_id=0, $a_old_nr=0, $a_lang="-")
Get page object instance.
$parser
Definition: BPMN2Parser.php:24
static getLogger($a_component_id)
Get component logger.
Xml importer class.