ILIAS  release_7 Revision v7.30-3-g800a261c036
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...
 
 addSkipImporter ($a_component, $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()
 
 $skip_importer = []
 

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 35 of file class.ilImport.php.

36 {
37 include_once("./Services/Export/classes/class.ilImportMapping.php");
38 $this->mapping = new ilImportMapping();
39 $this->mapping->setTargetId($a_target_id);
40 $this->log = ilLoggerFactory::getLogger('exp');
41 }
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 101 of file class.ilImport.php.

102 {
103 $this->skip_entity[$a_component][$a_entity] = $skip;
104 }

◆ addSkipImporter()

ilImport::addSkipImporter (   $a_component,
  $skip = true 
)

Add skip entity.

Parameters
string$a_valcomponent
string$a_valentity

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

113 {
114 $this->skip_importer[$a_component] = $skip;
115 }

◆ afterEntityTypes()

ilImport::afterEntityTypes ( )

After entity types are parsed.

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

142 {
143 $this->getCurrentDataset()->setImport($this);
144 }
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 256 of file class.ilImport.php.

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

References Vendor\Package\$e, $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 50 of file class.ilImport.php.

51 {
52 // if created, return existing config object
53 if (isset($this->configs[$a_comp])) {
54 return $this->configs[$a_comp];
55 }
56
57 // create instance of export config object
58 $comp_arr = explode("/", $a_comp);
59 $a_class = "il" . $comp_arr[1] . "ImportConfig";
60 $imp_config = new $a_class();
61 $this->configs[$a_comp] = $imp_config;
62
63 return $imp_config;
64 }

◆ getCurrentDataset()

ilImport::getCurrentDataset ( )

Get currrent dataset.

Returns
object currrent dataset

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

134 {
135 return $this->current_dataset;
136 }

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 90 of file class.ilImport.php.

91 {
92 return $this->entity_types;
93 }

◆ getMapping()

ilImport::getMapping ( )

Get mapping object.

Returns
ilImportMapping ilImportMapping

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

71 {
72 return $this->mapping;
73 }

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 246 of file class.ilImport.php.

247 {
249 }

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 160 of file class.ilImport.php.

166 {
167 $this->importObject(null, $a_tmp_file, $a_filename, $a_entity, $a_component, $a_copy_file);
168 }
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 220 of file class.ilImport.php.

221 {
222 $ret = $this->doImportObject($dir, $a_type, $a_comp);
223
224 if (is_array($ret)) {
225 return $ret['new_id'];
226 }
227 return null;
228 }
doImportObject($dir, $a_type, $a_component="", $a_tmpdir="")
Import repository object export file.
$ret
Definition: parser.php:6

References $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 176 of file class.ilImport.php.

183 {
184
185 // create temporary directory
186 $tmpdir = ilUtil::ilTempnam();
187 ilUtil::makeDir($tmpdir);
188 if ($a_copy_file) {
189 copy($a_tmp_file, $tmpdir . "/" . $a_filename);
190 } else {
191 ilUtil::moveUploadedFile($a_tmp_file, $a_filename, $tmpdir . "/" . $a_filename);
192 }
193
194 $this->log->debug("unzip: " . $tmpdir . "/" . $a_filename);
195
196 ilUtil::unzip($tmpdir . "/" . $a_filename);
197 $dir = $tmpdir . "/" . substr($a_filename, 0, strlen($a_filename) - 4);
198
199 $this->setTemporaryImportDir($dir);
200
201 $this->log->debug("dir: " . $dir);
202
203 $ret = $this->doImportObject($dir, $a_type, $a_comp, $tmpdir);
204 $new_id = null;
205 if (is_array($ret)) {
206 $new_id = $ret['new_id'];
207 }
208
209 // delete temporary directory
210 ilUtil::delDir($tmpdir);
211 return $new_id;
212 }
setTemporaryImportDir($a_val)
Set temporary import directory.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static unzip(string $path_to_zip_file, bool $overwrite_existing=false, bool $unpack_flat=false)
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...

References $ret, ilUtil\delDir(), doImportObject(), ilUtil\ilTempnam(), ilUtil\makeDir(), ilUtil\moveUploadedFile(), 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 151 of file class.ilImport.php.

152 {
153 $this->getCurrentDataset()->importRecord($a_entity, $a_types, $a_record);
154 }

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 359 of file class.ilImport.php.

360 {
361 global $DIC;
362
363 $objDefinition = $DIC['objDefinition'];
364
365 // skip
366 if ($this->skip_entity[$this->current_comp][$a_entity]) {
367 return;
368 }
369
370 if ($objDefinition->isRBACObject($a_entity) &&
371 $this->getMapping()->getMapping('Services/Container', 'imported', $a_id)) {
372 $this->log->info('Ignoring referenced ' . $a_entity . ' with id ' . $a_id);
373 return;
374 }
375 $this->importer->setInstallId($a_install_id);
376 $this->importer->setInstallUrl($a_install_url);
377 $this->importer->setSchemaVersion($a_schema_version);
378 $this->importer->setSkipEntities($this->skip_entity);
379 $new_id = $this->importer->importXmlRepresentation($a_entity, $a_id, $a_xml, $this->mapping);
380
381 // Store information about imported obj_ids in mapping to avoid double imports of references
382 if ($objDefinition->isRBACObject($a_entity)) {
383 $this->getMapping()->addMapping('Services/Container', 'imported', $a_id, 1);
384 }
385
386 // @TODO new id is not always set
387 if ($new_id && $new_id !== true) {
388 $this->mapping->addMapping($this->comp, $a_entity, $a_id, $new_id);
389 }
390 }
global $DIC
Definition: goto.php:24

References $DIC, and getMapping().

+ Here is the call graph for this function:

◆ setCurrentDataset()

ilImport::setCurrentDataset (   $a_val)

Set currrent dataset.

Parameters
objectcurrrent dataset

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

123 {
124 $this->current_dataset = $a_val;
125 }

◆ setEntityTypes()

ilImport::setEntityTypes (   $a_val)
final

Set entity types.

Parameters
arrayentity types

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

81 {
82 $this->entity_types = $a_val;
83 }

◆ 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 236 of file class.ilImport.php.

237 {
238 $this->tmp_import_dir = $a_val;
239 }

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.

◆ $skip_importer

ilImport::$skip_importer = []
protected

Definition at line 27 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: