ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilImport Class Reference

Import class. More...

+ Inheritance diagram for ilImport:
+ Collaboration diagram for ilImport:

Public Member Functions

 __construct ($a_target_id=0)
 Constructor. More...
 
 getConfig ($a_comp)
 Get configuration (note that configurations are optional, null may be returned!) More...
 
 getMapping ()
 Get mapping object. More...
 
 setEntityTypes ($a_val)
 Set entity types. More...
 
 getEntityTypes ()
 Get entity types. More...
 
 addSkipEntity ($a_component, $a_entity, $skip=true)
 Add skip entity. More...
 
 setCurrentDataset ($a_val)
 Set currrent dataset. More...
 
 getCurrentDataset ()
 Get currrent dataset. More...
 
 afterEntityTypes ()
 After entity types are parsed. More...
 
 importRecord ($a_entity, $a_types, $a_record)
 After entity types are parsed. More...
 
 importEntity ( $a_tmp_file, $a_filename, $a_entity, $a_component, $a_copy_file=false)
 Import entity. More...
 
 importObject ( $a_new_obj, $a_tmp_file, $a_filename, $a_type, $a_comp="", $a_copy_file=false)
 Import repository object export file. More...
 
 importFromDirectory ($dir, $a_type, $a_comp)
 Import from directory. More...
 
 getTemporaryImportDir ()
 Get temporary import directory. More...
 
 processItemXml ($a_entity, $a_schema_version, $a_id, $a_xml, $a_install_id, $a_install_url)
 Process item xml. More...
 

Protected Member Functions

 setTemporaryImportDir ($a_val)
 Set temporary import directory. More...
 
 doImportObject ($dir, $a_type, $a_component="", $a_tmpdir="")
 Import repository object export file. More...
 

Protected Attributes

 $log
 
 $install_id = ""
 
 $install_url = ""
 
 $entities = ""
 
 $tmp_import_dir = ""
 
 $mapping = null
 
 $skip_entity = array()
 
 $configs = array()
 

Detailed Description

Import class.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 11 of file class.ilImport.php.

Constructor & Destructor Documentation

◆ __construct()

ilImport::__construct (   $a_target_id = 0)

Constructor.

Parameters
intid of parent container
Returns

Reimplemented in ilImportContainer.

Definition at line 33 of file class.ilImport.php.

34 {
35 include_once("./Services/Export/classes/class.ilImportMapping.php");
36 $this->mapping = new ilImportMapping();
37 $this->mapping->setTargetId($a_target_id);
38 $this->log = ilLoggerFactory::getLogger('exp');
39 }
static getLogger($a_component_id)
Get component logger.

References ilLoggerFactory\getLogger().

+ Here is the call graph for this function:

Member Function Documentation

◆ addSkipEntity()

ilImport::addSkipEntity (   $a_component,
  $a_entity,
  $skip = true 
)

Add skip entity.

Parameters
string$a_valcomponent
string$a_valentity

Definition at line 105 of file class.ilImport.php.

106 {
107 $this->skip_entity[$a_component][$a_entity] = $skip;
108 }

◆ afterEntityTypes()

ilImport::afterEntityTypes ( )

After entity types are parsed.

Definition at line 134 of file class.ilImport.php.

135 {
136 $this->getCurrentDataset()->setImport($this);
137 }
getCurrentDataset()
Get currrent dataset.

References getCurrentDataset().

+ Here is the call graph for this function:

◆ doImportObject()

ilImport::doImportObject (   $dir,
  $a_type,
  $a_component = "",
  $a_tmpdir = "" 
)
protected

Import repository object export file.

Parameters
stringabsolute filename of temporary upload file

Reimplemented in ilImportContainer.

Definition at line 249 of file class.ilImport.php.

250 {
251 if ($a_component == "") {
252 include_once("./Services/Export/classes/class.ilImportExportFactory.php");
253 $a_component = ilImportExportFactory::getComponentForExport($a_type);
254 }
255 $this->comp = $a_component;
256
257 // get import class
258 $success = true;
259
260 // process manifest file
261 include_once("./Services/Export/classes/class.ilManifestParser.php");
262 if (!is_file($dir . "/manifest.xml")) {
263 include_once("./Services/Export/exceptions/class.ilManifestFileNotFoundImportException.php");
264 $mess = (DEVMODE)
265 ? 'Manifest file not found: "' . $dir . "/manifest.xml" . '".'
266 : 'Manifest file not found: "manifest.xml."';
268 $e->setManifestDir($dir);
269 $e->setTmpDir($a_tmpdir);
270 throw $e;
271 }
272 $parser = new ilManifestParser($dir . "/manifest.xml");
273 $this->mapping->setInstallUrl($parser->getInstallUrl());
274 $this->mapping->setInstallId($parser->getInstallId());
275
276 // check for correct type
277 if ($parser->getMainEntity() != $a_type) {
278 include_once("./Services/Export/exceptions/class.ilImportObjectTypeMismatchException.php");
279 $e = new ilImportObjectTypeMismatchException("Object type does not match. Import file has type '" . $parser->getMainEntity() . "' but import being processed for '" . $a_type . "'.");
280 throw $e;
281 }
282
283 // process export files
284 $expfiles = $parser->getExportFiles();
285
286 include_once("./Services/Export/classes/class.ilExportFileParser.php");
287 include_once("./Services/Export/classes/class.ilImportExportFactory.php");
288 $all_importers = array();
289 foreach ($expfiles as $expfile) {
290 $comp = $expfile["component"];
291 $class = ilImportExportFactory::getImporterClass($comp);
292
293 // log a warning for inactive page component plugins, but continue import
294 // page content will be imported, but not its additional data
295 // (other plugins throw an exception in ilImportExportFactory)
296 if ($class == '') {
297 $this->log->warning("no class found for component: $comp");
298 continue;
299 }
300
301 $this->log->debug("create new class = $class");
302
303 $this->importer = new $class();
304 $this->importer->setImport($this);
305 $all_importers[] = $this->importer;
306 $this->importer->setImportDirectory($dir);
307 $this->importer->init();
308 $this->current_comp = $comp;
309 try {
310 $this->log->debug("Process file: " . $dir . "/" . $expfile["path"]);
311 $parser = new ilExportFileParser($dir . "/" . $expfile["path"], $this, "processItemXml");
312 } catch (Exception $e) {
313 $this->log->error("Import failed: " . $e->getMessage());
314 throw $e;
315 }
316 }
317
318 // write import ids before(!) final processing
319 $obj_map = $this->getMapping()->getMappingsOfEntity('Services/Container', 'objs');
320 if (is_array($obj_map)) {
321 foreach ($obj_map as $obj_id_old => $obj_id_new) {
322 ilObject::_writeImportId($obj_id_new, "il_" . $this->mapping->getInstallId() . "_" . ilObject::_lookupType($obj_id_new) . "_" . $obj_id_old);
323 }
324 }
325
326 // final processing
327 foreach ($all_importers as $imp) {
328 $this->log->debug("Call finalProcessing for: " . get_class($imp));
329 $imp->finalProcessing($this->mapping);
330 }
331
332 // we should only get on mapping here
333 $top_mapping = $this->mapping->getMappingsOfEntity($this->comp, $a_type);
334 $new_id = (int) current($top_mapping);
335 return array(
336 'new_id' => $new_id,
337 'importers' => (array) $all_importers
338 );
339 }
$parser
Definition: BPMN2Parser.php:23
$success
Definition: Utf8Test.php:86
getMapping()
Get mapping object.
manifest.xml file not found-exception for import
Manifest parser for ILIAS standard export files.
static _writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
static _lookupType($a_id, $a_reference=false)
lookup object type
$a_type
Definition: workflow.php:92

References $a_type, $parser, $success, ilObject\_lookupType(), ilObject\_writeImportId(), and getMapping().

Referenced by importFromDirectory(), and importObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getConfig()

ilImport::getConfig (   $a_comp)

Get configuration (note that configurations are optional, null may be returned!)

Parameters
string$a_compcomponent (e.g. "Modules/Glossary")
Returns
ilImportConfig $a_comp configuration object or null
Exceptions
ilImportException

Definition at line 48 of file class.ilImport.php.

49 {
50 // if created, return existing config object
51 if (isset($this->configs[$a_comp])) {
52 return $this->configs[$a_comp];
53 }
54
55 // create instance of export config object
56 $comp_arr = explode("/", $a_comp);
57 $a_class = "il" . $comp_arr[1] . "ImportConfig";
58 $import_config_file = "./" . $a_comp . "/classes/class." . $a_class . ".php";
59 if (!is_file($import_config_file)) {
60 include_once("./Services/Export/exceptions/class.ilImportException.php");
61 throw new ilImportException('Component "' . $a_comp . '" does not provide ImportConfig class.');
62 }
63 include_once($import_config_file);
64 $imp_config = new $a_class();
65 $this->configs[$a_comp] = $imp_config;
66
67 return $imp_config;
68 }
General import exception.

◆ getCurrentDataset()

ilImport::getCurrentDataset ( )

Get currrent dataset.

Returns
object currrent dataset

Definition at line 126 of file class.ilImport.php.

127 {
128 return $this->current_dataset;
129 }

Referenced by afterEntityTypes(), and importRecord().

+ Here is the caller graph for this function:

◆ getEntityTypes()

ilImport::getEntityTypes ( )
final

Get entity types.

Returns
array entity types

Definition at line 94 of file class.ilImport.php.

95 {
96 return $this->entity_types;
97 }

◆ getMapping()

ilImport::getMapping ( )

Get mapping object.

Returns
ilImportMapping ilImportMapping

Definition at line 74 of file class.ilImport.php.

75 {
76 return $this->mapping;
77 }

References $mapping.

Referenced by ilImportContainer\createDummy(), doImportObject(), ilImportContainer\doImportObject(), and processItemXml().

+ Here is the caller graph for this function:

◆ getTemporaryImportDir()

ilImport::getTemporaryImportDir ( )

Get temporary import directory.

Returns
string temporary import directory (used to unzip and read import)

Definition at line 239 of file class.ilImport.php.

240 {
242 }

References $tmp_import_dir.

◆ importEntity()

ilImport::importEntity (   $a_tmp_file,
  $a_filename,
  $a_entity,
  $a_component,
  $a_copy_file = false 
)
final

Import entity.

Definition at line 153 of file class.ilImport.php.

159 {
160 $this->importObject(null, $a_tmp_file, $a_filename, $a_entity, $a_component, $a_copy_file);
161 }
importObject( $a_new_obj, $a_tmp_file, $a_filename, $a_type, $a_comp="", $a_copy_file=false)
Import repository object export file.

References importObject().

+ Here is the call graph for this function:

◆ importFromDirectory()

ilImport::importFromDirectory (   $dir,
  $a_type,
  $a_comp 
)

Import from directory.

Parameters

return

Definition at line 213 of file class.ilImport.php.

214 {
215 $ret = $this->doImportObject($dir, $a_type, $a_comp);
216
217 if (is_array($ret)) {
218 return $ret['new_id'];
219 }
220 return null;
221 }
doImportObject($dir, $a_type, $a_component="", $a_tmpdir="")
Import repository object export file.
$ret
Definition: parser.php:6

References $a_type, $ret, and doImportObject().

+ Here is the call graph for this function:

◆ importObject()

ilImport::importObject (   $a_new_obj,
  $a_tmp_file,
  $a_filename,
  $a_type,
  $a_comp = "",
  $a_copy_file = false 
)
final

Import repository object export file.

Parameters
stringabsolute filename of temporary upload file

Definition at line 169 of file class.ilImport.php.

176 {
177
178 // create temporary directory
179 $tmpdir = ilUtil::ilTempnam();
180 ilUtil::makeDir($tmpdir);
181 if ($a_copy_file) {
182 copy($a_tmp_file, $tmpdir . "/" . $a_filename);
183 } else {
184 ilUtil::moveUploadedFile($a_tmp_file, $a_filename, $tmpdir . "/" . $a_filename);
185 }
186
187 $this->log->debug("unzip: " . $tmpdir . "/" . $a_filename);
188
189 ilUtil::unzip($tmpdir . "/" . $a_filename);
190 $dir = $tmpdir . "/" . substr($a_filename, 0, strlen($a_filename) - 4);
191
192 $this->setTemporaryImportDir($dir);
193
194 $this->log->debug("dir: " . $dir);
195
196 $ret = $this->doImportObject($dir, $a_type, $a_comp, $tmpdir);
197 $new_id = null;
198 if (is_array($ret)) {
199 $new_id = $ret['new_id'];
200 }
201
202 // delete temporary directory
203 ilUtil::delDir($tmpdir);
204 return $new_id;
205 }
setTemporaryImportDir($a_val)
Set temporary import directory.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...

References $a_type, $ret, ilUtil\delDir(), doImportObject(), ilUtil\ilTempnam(), ilUtil\makeDir(), setTemporaryImportDir(), and ilUtil\unzip().

Referenced by importEntity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importRecord()

ilImport::importRecord (   $a_entity,
  $a_types,
  $a_record 
)

After entity types are parsed.

Parameters

Definition at line 144 of file class.ilImport.php.

145 {
146 $this->getCurrentDataset()->importRecord($a_entity, $a_types, $a_record);
147 }

References getCurrentDataset().

+ Here is the call graph for this function:

◆ processItemXml()

ilImport::processItemXml (   $a_entity,
  $a_schema_version,
  $a_id,
  $a_xml,
  $a_install_id,
  $a_install_url 
)

Process item xml.

@global ilObjectDefinition $objDefinition

Definition at line 346 of file class.ilImport.php.

347 {
348 global $objDefinition;
349
350 // skip
351 if ($this->skip_entity[$this->current_comp][$a_entity]) {
352 return;
353 }
354
355 if ($objDefinition->isRBACObject($a_entity) &&
356 $this->getMapping()->getMapping('Services/Container', 'imported', $a_id)) {
357 $this->log->info('Ignoring referenced ' . $a_entity . ' with id ' . $a_id);
358 return;
359 }
360 $this->importer->setInstallId($a_install_id);
361 $this->importer->setInstallUrl($a_install_url);
362 $this->importer->setSchemaVersion($a_schema_version);
363 $this->importer->setSkipEntities($this->skip_entity);
364 $new_id = $this->importer->importXmlRepresentation($a_entity, $a_id, $a_xml, $this->mapping);
365
366 // Store information about imported obj_ids in mapping to avoid double imports of references
367 if ($objDefinition->isRBACObject($a_entity)) {
368 $this->getMapping()->addMapping('Services/Container', 'imported', $a_id, 1);
369 }
370
371 // @TODO new id is not always set
372 if ($new_id) {
373 $this->mapping->addMapping($this->comp, $a_entity, $a_id, $new_id);
374 }
375 }

References getMapping().

+ Here is the call graph for this function:

◆ setCurrentDataset()

ilImport::setCurrentDataset (   $a_val)

Set currrent dataset.

Parameters
objectcurrrent dataset

Definition at line 115 of file class.ilImport.php.

116 {
117 $this->current_dataset = $a_val;
118 }

◆ setEntityTypes()

ilImport::setEntityTypes (   $a_val)
final

Set entity types.

Parameters
arrayentity types

Definition at line 84 of file class.ilImport.php.

85 {
86 $this->entity_types = $a_val;
87 }

◆ setTemporaryImportDir()

ilImport::setTemporaryImportDir (   $a_val)
protected

Set temporary import directory.

Parameters
string$a_valtemporary import directory (used to unzip and read import)

Definition at line 229 of file class.ilImport.php.

230 {
231 $this->tmp_import_dir = $a_val;
232 }

Referenced by importObject().

+ Here is the caller graph for this function:

Field Documentation

◆ $configs

ilImport::$configs = array()
protected

Definition at line 25 of file class.ilImport.php.

◆ $entities

ilImport::$entities = ""
protected

Definition at line 20 of file class.ilImport.php.

◆ $install_id

ilImport::$install_id = ""
protected

Definition at line 18 of file class.ilImport.php.

◆ $install_url

ilImport::$install_url = ""
protected

Definition at line 19 of file class.ilImport.php.

◆ $log

ilImport::$log
protected

Definition at line 16 of file class.ilImport.php.

◆ $mapping

ilImport::$mapping = null
protected

Definition at line 23 of file class.ilImport.php.

Referenced by getMapping().

◆ $skip_entity

ilImport::$skip_entity = array()
protected

Definition at line 24 of file class.ilImport.php.

◆ $tmp_import_dir

ilImport::$tmp_import_dir = ""
protected

Definition at line 21 of file class.ilImport.php.

Referenced by getTemporaryImportDir().


The documentation for this class was generated from the following file: