ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilImport Class Reference

Import class. 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

 validateXMLFiles (SplFileInfo $manifest_spl)
 
 checkStatuses (ilImportStatusHandlerCollectionInterface $import_status_collection)
 
 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
 
array $entity_types = []
 
ilXmlImporter $importer = null
 
string $comp = ''
 
string $current_comp = ''
 
string $entities = ""
 
string $tmp_import_dir = ""
 
ilImportMapping $mapping = null
 
array $skip_entity = array()
 
array $configs = array()
 
array $skip_importer = []
 
Archives $archives
 
Filesystems $filesystem
 
ilImportFactory $import
 
ilImportStatusFactory $import_status
 

Detailed Description

Import class.

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

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

Constructor & Destructor Documentation

◆ __construct()

ilImport::__construct ( int  $a_target_id = 0)

Reimplemented in ilImportContainer.

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

58 {
59 global $DIC;
60 $this->objDefinition = $DIC['objDefinition'];
61 $this->mapping = new ilImportMapping();
62 $this->mapping->setTargetId($a_target_id);
63 $this->log = $DIC->logger()->exp();
64 $this->archives = $DIC->archives();
65 $this->filesystem = $DIC->filesystem();
66 $this->import = new ilImportFactory();
67 $this->import_status = new ilImportStatusFactory();
68 }
global $DIC
Definition: shib_login.php:26

References $DIC, and ILIAS\Repository\filesystem().

+ Here is the call graph for this function:

Member Function Documentation

◆ addSkipEntity()

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

Add skip entity.

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

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

◆ addSkipImporter()

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

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

110 : void
111 {
112 $this->skip_importer[$a_component] = $skip;
113 }

◆ checkStatuses()

ilImport::checkStatuses ( ilImportStatusHandlerCollectionInterface  $import_status_collection)
protected

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

240 : void
241 {
242 if ($import_status_collection->hasStatusType(StatusType::FAILED)) {
243 throw new ilImportException($import_status_collection
244 ->withNumberingEnabled(true)
246 }
247 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References ILIAS\Export\ImportStatus\FAILED, and ILIAS\Export\ImportHandler\File\XML\Manifest\toString.

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

328 : array {
329 if ($a_component == "") {
330 $a_component = ilImportExportFactory::getComponentForExport($a_type);
331 }
332 $this->comp = $a_component;
333
334 // get import class
335 $success = true;
336
337 // process manifest file
338 if (!is_file($dir . "/manifest.xml")) {
339 $mess = (DEVMODE)
340 ? 'Manifest file not found: "' . $dir . "/manifest.xml" . '".'
341 : 'Manifest file not found: "manifest.xml."';
343 $e->setManifestDir($dir);
344 $e->setTmpDir($a_tmpdir);
345 throw $e;
346 }
347 $parser = new ilManifestParser($dir . "/manifest.xml");
348 $this->mapping->setInstallUrl($parser->getInstallUrl());
349 $this->mapping->setInstallId($parser->getInstallId());
350
351 // check for correct type
352 if ($parser->getMainEntity() != $a_type) {
354 "Object type does not match. Import file has type '" .
355 $parser->getMainEntity() . "' but import being processed for '" . $a_type . "'."
356 );
357 }
358
359 // process export files
360 $expfiles = $parser->getExportFiles();
361
362 $all_importers = array();
363 foreach ($expfiles as $expfile) {
364 $comp = $expfile["component"];
365
366 if (isset($this->skip_importer[$comp]) && $this->skip_importer[$comp] === true) {
367 continue;
368 }
369
370 $class = ilImportExportFactory::getImporterClass($comp);
371
372 // log a warning for inactive page component plugins, but continue import
373 // page content will be imported, but not its additional data
374 // (other plugins throw an exception in ilImportExportFactory)
375 if ($class == '') {
376 $this->log->warning("no class found for component: $comp");
377 continue;
378 }
379
380 $this->log->debug("create new class = $class");
381
382 $this->importer = new $class();
383 $this->importer->setImport($this);
384 $all_importers[] = $this->importer;
385 $this->importer->setImportDirectory($dir);
386 $this->importer->init();
387 $this->current_comp = $comp;
388 try {
389 $this->log->debug("Process file: " . $dir . "/" . $expfile["path"]);
390 $parser = new ilExportFileParser($dir . "/" . $expfile["path"], $this, "processItemXml");
391 } catch (Exception $e) {
392 $this->log->error("Import failed: " . $e->getMessage());
393 $this->log->error('XML failed: ' . file_get_contents($dir . '/' . $expfile['path']));
394 throw $e;
395 }
396 }
397
398 // write import ids before(!) final processing
399 $obj_map = $this->getMapping()->getMappingsOfEntity('components/ILIAS/Container', 'objs');
400 if (is_array($obj_map)) {
401 foreach ($obj_map as $obj_id_old => $obj_id_new) {
403 (int) $obj_id_new,
404 "il_" . $this->mapping->getInstallId() . "_" . ilObject::_lookupType((int) $obj_id_new) . "_" . $obj_id_old
405 );
406 }
407 }
408
409 // final processing
410 foreach ($all_importers as $imp) {
411 $this->log->debug("Call finalProcessing for: " . get_class($imp));
412 $imp->finalProcessing($this->mapping);
413 }
414
415 // we should only get on mapping here
416 $top_mapping = $this->mapping->getMappingsOfEntity($this->comp, $a_type);
417
418 $new_id = (int) current($top_mapping);
419 return array(
420 'new_id' => $new_id,
421 'importers' => $all_importers
422 );
423 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $comp
ilXmlImporter $importer
manifest.xml file not found-exception for import
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 73 of file class.ilImport.php.

74 {
75 // if created, return existing config object
76 if (isset($this->configs[$a_comp])) {
77 return $this->configs[$a_comp];
78 }
79 // create instance of export config object
80 $comp_arr = explode("/", $a_comp);
81 $a_class = "il" . ($comp_arr[2] ?? $comp_arr[1]) . "ImportConfig";
82 $imp_config = new $a_class();
83 $this->configs[$a_comp] = $imp_config;
84 return $imp_config;
85 }
Import configuration class parent class.

◆ getEntityTypes()

ilImport::getEntityTypes ( )
final

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

97 : array
98 {
100 }
array $entity_types

References $entity_types.

◆ getMapping()

ilImport::getMapping ( )

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

88 {
89 return $this->mapping;
90 }
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 315 of file class.ilImport.php.

315 : string
316 {
318 }
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 118 of file class.ilImport.php.

124 : int {
125 return $this->importObject(null, $a_tmp_file, $a_filename, $a_entity, $a_component, $a_copy_file);
126 }
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 293 of file class.ilImport.php.

293 : ?int
294 {
295 $ret = $this->doImportObject($dir, $a_type, $a_comp);
296 if (is_array($ret)) {
297 return $ret['new_id'];
298 }
299 return null;
300 }
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 249 of file class.ilImport.php.

256 : ?int {
257 // Unzip
258 $status_collection = $this->unzipFile(
259 $a_filename,
260 $a_tmp_file,
261 $a_copy_file
262 );
263 $this->checkStatuses($status_collection);
264 $success_status = $status_collection->getCollectionOfAllByType(StatusType::SUCCESS)->current();
265 $target_dir_info = new SplFileInfo($success_status->getContent()->toString());
266 $delete_dir_info = new SplFileInfo($target_dir_info->getPath());
267 $manifest_spl = new SplFileInfo($target_dir_info->getPathname() . DIRECTORY_SEPARATOR . 'manifest.xml');
268 // Validate manifest files
269 try {
270 $status_collection = $this->validateXMLFiles($manifest_spl);
271 $this->checkStatuses($status_collection);
272 } catch (Exception $e) {
273 $this->filesystem->temp()->deleteDir($delete_dir_info->getFilename());
274 throw $e;
275 }
276 // Import
277 try {
278 $this->setTemporaryImportDir($target_dir_info->getPathname());
279 $ret = $this->doImportObject($target_dir_info->getPathname(), $a_type, $a_comp, $target_dir_info->getPath());
280 $new_id = null;
281 if (is_array($ret) && array_key_exists('new_id', $ret)) {
282 $new_id = $ret['new_id'];
283 }
284 } catch (Exception $e) {
285 $this->filesystem->temp()->deleteDir($delete_dir_info->getFilename());
286 throw $e;
287 }
288 // Delete tmp files
289 $this->filesystem->temp()->deleteDir($delete_dir_info->getFilename());
290 return $new_id;
291 }
validateXMLFiles(SplFileInfo $manifest_spl)
setTemporaryImportDir(string $a_val)
Set temporary import directory.
checkStatuses(ilImportStatusHandlerCollectionInterface $import_status_collection)

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

435 : void {
436 // skip
437 if (isset($this->skip_entity[$this->current_comp][$a_entity]) &&
438 $this->skip_entity[$this->current_comp][$a_entity]) {
439 return;
440 }
441
442 if ($this->objDefinition->isRBACObject($a_entity) &&
443 $this->getMapping()->getMapping('components/ILIAS/Container', 'imported', $a_id)) {
444 $this->log->info('Ignoring referenced ' . $a_entity . ' with id ' . $a_id);
445 return;
446 }
447 $this->importer->setInstallId($a_install_id);
448 $this->importer->setInstallUrl($a_install_url);
449 $this->importer->setSchemaVersion($a_schema_version);
450 $this->importer->setSkipEntities($this->skip_entity);
451 $this->importer->importXmlRepresentation($a_entity, $a_id, $a_xml, $this->mapping);
452
453 // Store information about imported obj_ids in mapping to avoid double imports of references
454 if ($this->objDefinition->isRBACObject($a_entity)) {
455 $this->getMapping()->addMapping('components/ILIAS/Container', 'imported', $a_id, '1');
456 }
457 }

◆ setEntityTypes()

ilImport::setEntityTypes ( array  $a_val)
final

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

92 : void
93 {
94 $this->entity_types = $a_val;
95 }

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

307 {
308 $this->tmp_import_dir = $a_val;
309 }

◆ validateXMLFiles()

ilImport::validateXMLFiles ( SplFileInfo  $manifest_spl)
protected

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

175 : ilImportStatusHandlerCollectionInterface
176 {
177 $export_files = $this->import->file()->xml()->export()->collection();
178 $manifest_handlers = $this->import->file()->xml()->manifest()->collection();
179 $statuses = $this->import_status->collection();
180 // Find export xmls
181 try {
182 $manifest_handlers = $manifest_handlers->withElement(
183 $this->import->file()->xml()->manifest()->handler()->withFileInfo($manifest_spl)
184 );
185 // VALIDATE 1st manifest file, can be either export-set or export-file
186 $statuses = $manifest_handlers->validateElements();
187 if ($statuses->hasStatusType(StatusType::FAILED)) {
188 return $statuses;
189 }
190 // If export set look for the export file manifests + VALIDATE
191 if ($manifest_handlers->containsExportObjectType(ExportObjectType::EXPORT_SET)) {
192 $manifest_handlers = $manifest_handlers->findNextFiles();
193 $statuses = $manifest_handlers->validateElements();
194 }
195 if ($statuses->hasStatusType(StatusType::FAILED)) {
196 return $statuses;
197 }
198 // If export file look for the export xmls
199 if ($manifest_handlers->containsExportObjectType(ExportObjectType::EXPORT_FILE)) {
200 foreach ($manifest_handlers as $manfiest_file_handler) {
201 $export_files = $export_files->withMerged($manfiest_file_handler->findXMLFileHandlers());
202 }
203 }
204 } catch (ilImportStatusException $e) {
205 $this->checkStatuses($e->getStatuses());
206 }
207 // VALIDATE export xmls
208 $path_to_export_item_child = $this->import->path()->handler()
209 ->withStartAtRoot(true)
210 ->withNode($this->import->path()->node()->simple()->withName('exp:Export'))
211 ->withNode($this->import->path()->node()->simple()->withName('exp:ExportItem'))
212 ->withNode($this->import->path()->node()->anyNode());
213 $component_tree = $this->import->parser()->nodeInfo()->tree()->handler();
214 foreach ($export_files as $export_file) {
215 if ($export_file->isContainerExportXML()) {
216 $component_tree = $component_tree->withRootInFile($export_file, $path_to_export_item_child);
217 break;
218 }
219 }
220 foreach ($export_files as $export_file) {
221 $found_statuses = $export_file->buildValidationSets();
222 if (!$found_statuses->hasStatusType(StatusType::FAILED)) {
223 $found_statuses = $this->import->validation()->handler()->validateSets(
224 $export_file->getValidationSets()
225 );
226 }
227 if (!$found_statuses->hasStatusType(StatusType::FAILED)) {
228 $statuses = $statuses->getMergedCollectionWith($found_statuses);
229 continue;
230 }
231 $info_str = "<br> Location: " . $export_file->getILIASPath($component_tree) . "<br>";
232 $found_statuses = $found_statuses->mergeContentToElements(
233 $this->import_status->content()->builder()->string()->withString($info_str)
234 );
235 $statuses = $statuses->getMergedCollectionWith($found_statuses);
236 }
237 return $statuses;
238 }

References Vendor\Package\$e, and ILIAS\Export\ImportStatus\FAILED.

Field Documentation

◆ $archives

Archives ilImport::$archives
protected

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

◆ $comp

string ilImport::$comp = ''
protected

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

◆ $configs

array ilImport::$configs = array()
protected

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

◆ $current_comp

string ilImport::$current_comp = ''
protected

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

◆ $entities

string ilImport::$entities = ""
protected

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

◆ $entity_types

array ilImport::$entity_types = []
protected

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

Referenced by getEntityTypes().

◆ $filesystem

Filesystems ilImport::$filesystem
protected

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

◆ $import

ilImportFactory ilImport::$import
protected

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

◆ $import_status

ilImportStatusFactory ilImport::$import_status
protected

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

◆ $importer

ilXmlImporter ilImport::$importer = null
protected

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

◆ $log

ilLogger ilImport::$log
protected

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

◆ $mapping

ilImportMapping ilImport::$mapping = null
protected

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

Referenced by getMapping().

◆ $objDefinition

ilObjectDefinition ilImport::$objDefinition
protected

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

◆ $skip_entity

array ilImport::$skip_entity = array()
protected

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

◆ $skip_importer

array ilImport::$skip_importer = []
protected

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

◆ $tmp_import_dir

string ilImport::$tmp_import_dir = ""
protected

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


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