ILIAS  release_8 Revision v8.24
ilImport Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

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

Public Member Functions

 __construct (int $a_target_id=0)
 
 getConfig (string $a_comp)
 Get configuration (note that configurations are optional, null may be returned!) More...
 
 getMapping ()
 
 setEntityTypes (array $a_val)
 
 getEntityTypes ()
 
 addSkipEntity (string $a_component, string $a_entity, bool $skip=true)
 Add skip entity. More...
 
 addSkipImporter (string $a_component, bool $skip=true)
 
 importEntity (string $a_tmp_file, string $a_filename, string $a_entity, string $a_component, bool $a_copy_file=false)
 Import entity. More...
 
 importObject (?object $a_new_obj, string $a_tmp_file, string $a_filename, string $a_type, string $a_comp="", bool $a_copy_file=false)
 
 importFromDirectory (string $dir, string $a_type, string $a_comp)
 
 getTemporaryImportDir ()
 Get temporary import directory. More...
 
 processItemXml (string $a_entity, string $a_schema_version, string $a_id, string $a_xml, string $a_install_id, string $a_install_url)
 Process item xml. More...
 

Protected Member Functions

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

Protected Attributes

ilLogger $log
 
ilObjectDefinition $objDefinition
 
string $install_id = ""
 
string $install_url = ""
 
string $entities = ""
 
string $tmp_import_dir = ""
 
ilImportMapping $mapping = null
 
array $skip_entity = array()
 
array $configs = array()
 
array $skip_importer = []
 

Private Attributes

array $entity_types = []
 
ilXmlImporter $importer = null
 
string $comp = ''
 
string $current_comp = ''
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Import class

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

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

Constructor & Destructor Documentation

◆ __construct()

ilImport::__construct ( int  $a_target_id = 0)

Reimplemented in ilImportContainer.

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

45 {
46 global $DIC;
47
48 $this->objDefinition = $DIC['objDefinition'];
49 $this->mapping = new ilImportMapping();
50 $this->mapping->setTargetId($a_target_id);
51 $this->log = $DIC->logger()->exp();
52 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28

References $DIC.

Member Function Documentation

◆ addSkipEntity()

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

Add skip entity.

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

91 : void
92 {
93 $this->skip_entity[$a_component][$a_entity] = $skip;
94 }

◆ addSkipImporter()

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

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

96 : void
97 {
98 $this->skip_importer[$a_component] = $skip;
99 }

◆ doImportObject()

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

Import repository object export file.

Reimplemented in ilImportContainer.

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

182 : array {
183 if ($a_component == "") {
184 $a_component = ilImportExportFactory::getComponentForExport($a_type);
185 }
186 $this->comp = $a_component;
187
188 // get import class
189 $success = true;
190
191 // process manifest file
192 if (!is_file($dir . "/manifest.xml")) {
193 $mess = (DEVMODE)
194 ? 'Manifest file not found: "' . $dir . "/manifest.xml" . '".'
195 : 'Manifest file not found: "manifest.xml."';
197 $e->setManifestDir($dir);
198 $e->setTmpDir($a_tmpdir);
199 throw $e;
200 }
201 $parser = new ilManifestParser($dir . "/manifest.xml");
202 $this->mapping->setInstallUrl($parser->getInstallUrl());
203 $this->mapping->setInstallId($parser->getInstallId());
204
205 // check for correct type
206 if ($parser->getMainEntity() != $a_type) {
208 "Object type does not match. Import file has type '" .
209 $parser->getMainEntity() . "' but import being processed for '" . $a_type . "'."
210 );
211 }
212
213 // process export files
214 $expfiles = $parser->getExportFiles();
215
216 $all_importers = array();
217 foreach ($expfiles as $expfile) {
218 $comp = $expfile["component"];
219
220 if (isset($this->skip_importer[$comp]) && $this->skip_importer[$comp] === true) {
221 continue;
222 }
223
224 $class = ilImportExportFactory::getImporterClass($comp);
225
226 // log a warning for inactive page component plugins, but continue import
227 // page content will be imported, but not its additional data
228 // (other plugins throw an exception in ilImportExportFactory)
229 if ($class == '') {
230 $this->log->warning("no class found for component: $comp");
231 continue;
232 }
233
234 $this->log->debug("create new class = $class");
235
236 $this->importer = new $class();
237 $this->importer->setImport($this);
238 $all_importers[] = $this->importer;
239 $this->importer->setImportDirectory($dir);
240 $this->importer->init();
241 $this->current_comp = $comp;
242 try {
243 $this->log->debug("Process file: " . $dir . "/" . $expfile["path"]);
244 $parser = new ilExportFileParser($dir . "/" . $expfile["path"], $this, "processItemXml");
245 } catch (Exception $e) {
246 $this->log->error("Import failed: " . $e->getMessage());
247 $this->log->error('XML failed: ' . file_get_contents($dir . '/' . $expfile['path']));
248 throw $e;
249 }
250 }
251
252 // write import ids before(!) final processing
253 $obj_map = $this->getMapping()->getMappingsOfEntity('Services/Container', 'objs');
254 if (is_array($obj_map)) {
255 foreach ($obj_map as $obj_id_old => $obj_id_new) {
257 (int) $obj_id_new,
258 "il_" . $this->mapping->getInstallId() . "_" . ilObject::_lookupType((int) $obj_id_new) . "_" . $obj_id_old
259 );
260 }
261 }
262
263 // final processing
264 foreach ($all_importers as $imp) {
265 $this->log->debug("Call finalProcessing for: " . get_class($imp));
266 $imp->finalProcessing($this->mapping);
267 }
268
269 // we should only get on mapping here
270 $top_mapping = $this->mapping->getMappingsOfEntity($this->comp, $a_type);
271
272 $new_id = (int) current($top_mapping);
273 return array(
274 'new_id' => $new_id,
275 'importers' => $all_importers
276 );
277 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $comp
ilXmlImporter $importer
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Manifest parser for ILIAS standard export files.
static _lookupType(int $id, bool $reference=false)
static _writeImportId(int $obj_id, string $import_id)
write import id to db (static)
setImportDirectory(string $a_val)

◆ getConfig()

ilImport::getConfig ( string  $a_comp)

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

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

58 {
59 // if created, return existing config object
60 if (isset($this->configs[$a_comp])) {
61 return $this->configs[$a_comp];
62 }
63
64 // create instance of export config object
65 $comp_arr = explode("/", $a_comp);
66 $a_class = "il" . $comp_arr[1] . "ImportConfig";
67 $imp_config = new $a_class();
68 $this->configs[$a_comp] = $imp_config;
69
70 return $imp_config;
71 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ getEntityTypes()

ilImport::getEntityTypes ( )
final

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

83 : array
84 {
86 }
array $entity_types

References $entity_types.

◆ getMapping()

ilImport::getMapping ( )

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

74 {
75 return $this->mapping;
76 }
ilImportMapping $mapping

References $mapping.

◆ getTemporaryImportDir()

ilImport::getTemporaryImportDir ( )

Get temporary import directory.

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

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

169 : string
170 {
172 }
string $tmp_import_dir

◆ importEntity()

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

Import entity.

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

110 : int {
111 return $this->importObject(null, $a_tmp_file, $a_filename, $a_entity, $a_component, $a_copy_file);
112 }
importObject(?object $a_new_obj, string $a_tmp_file, string $a_filename, string $a_type, string $a_comp="", bool $a_copy_file=false)

◆ importFromDirectory()

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

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

147 : ?int
148 {
149 $ret = $this->doImportObject($dir, $a_type, $a_comp);
150 if (is_array($ret)) {
151 return $ret['new_id'];
152 }
153 return null;
154 }
doImportObject(string $dir, string $a_type, string $a_component="", string $a_tmpdir="")
Import repository object export file.

◆ importObject()

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

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

121 : ?int {
122
123 // create temporary directory
124 $tmpdir = ilFileUtils::ilTempnam();
125 ilFileUtils::makeDir($tmpdir);
126 if ($a_copy_file) {
127 copy($a_tmp_file, $tmpdir . "/" . $a_filename);
128 } else {
129 ilFileUtils::moveUploadedFile($a_tmp_file, $a_filename, $tmpdir . "/" . $a_filename);
130 }
131
132 $this->log->debug("unzip: " . $tmpdir . "/" . $a_filename);
133 ilFileUtils::unzip($tmpdir . "/" . $a_filename);
134 $dir = $tmpdir . "/" . substr($a_filename, 0, strlen($a_filename) - 4);
135 $this->setTemporaryImportDir($dir);
136 $this->log->debug("dir: " . $dir);
137 $ret = $this->doImportObject($dir, $a_type, $a_comp, $tmpdir);
138 $new_id = null;
139 if (is_array($ret) && array_key_exists('new_id', $ret)) {
140 $new_id = $ret['new_id'];
141 }
142 // delete temporary directory
143 ilFileUtils::delDir($tmpdir);
144 return $new_id;
145 }
static unzip(string $path_to_zip_file, bool $overwrite_existing=false, bool $unpack_flat=false)
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
setTemporaryImportDir(string $a_val)
Set temporary import directory.

◆ processItemXml()

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

Process item xml.

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

289 : void {
290 // skip
291 if (isset($this->skip_entity[$this->current_comp][$a_entity]) &&
292 $this->skip_entity[$this->current_comp][$a_entity]) {
293 return;
294 }
295
296 if ($this->objDefinition->isRBACObject($a_entity) &&
297 $this->getMapping()->getMapping('Services/Container', 'imported', $a_id)) {
298 $this->log->info('Ignoring referenced ' . $a_entity . ' with id ' . $a_id);
299 return;
300 }
301 $this->importer->setInstallId($a_install_id);
302 $this->importer->setInstallUrl($a_install_url);
303 $this->importer->setSchemaVersion($a_schema_version);
304 $this->importer->setSkipEntities($this->skip_entity);
305 $this->importer->importXmlRepresentation($a_entity, $a_id, $a_xml, $this->mapping);
306
307 // Store information about imported obj_ids in mapping to avoid double imports of references
308 if ($this->objDefinition->isRBACObject($a_entity)) {
309 $this->getMapping()->addMapping('Services/Container', 'imported', $a_id, '1');
310 }
311 }

◆ setEntityTypes()

ilImport::setEntityTypes ( array  $a_val)
final

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

78 : void
79 {
80 $this->entity_types = $a_val;
81 }

◆ setTemporaryImportDir()

ilImport::setTemporaryImportDir ( string  $a_val)
protected

Set temporary import directory.

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

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

161 {
162 $this->tmp_import_dir = $a_val;
163 }

Field Documentation

◆ $comp

string ilImport::$comp = ''
private

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

◆ $configs

array ilImport::$configs = array()
protected

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

◆ $current_comp

string ilImport::$current_comp = ''
private

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

◆ $entities

string ilImport::$entities = ""
protected

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

◆ $entity_types

array ilImport::$entity_types = []
private

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

Referenced by getEntityTypes().

◆ $importer

ilXmlImporter ilImport::$importer = null
private

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

◆ $install_id

string ilImport::$install_id = ""
protected

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

◆ $install_url

string ilImport::$install_url = ""
protected

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

◆ $log

ilLogger ilImport::$log
protected

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

◆ $mapping

ilImportMapping ilImport::$mapping = null
protected

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

Referenced by getMapping().

◆ $objDefinition

ilObjectDefinition ilImport::$objDefinition
protected

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

◆ $skip_entity

array ilImport::$skip_entity = array()
protected

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

◆ $skip_importer

array ilImport::$skip_importer = []
protected

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

◆ $tmp_import_dir

string ilImport::$tmp_import_dir = ""
protected

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


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