35 include_once(
"./Services/Export/classes/class.ilImportMapping.php");
37 $this->mapping->setTargetId($a_target_id);
51 if (isset($this->configs[$a_comp])) {
52 return $this->configs[$a_comp];
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.');
63 include_once($import_config_file);
64 $imp_config =
new $a_class();
65 $this->configs[$a_comp] = $imp_config;
86 $this->entity_types = $a_val;
96 return $this->entity_types;
107 $this->skip_entity[$a_component][$a_entity] = $skip;
117 $this->current_dataset = $a_val;
128 return $this->current_dataset;
160 $this->
importObject(null, $a_tmp_file, $a_filename, $a_entity, $a_component, $a_copy_file);
182 copy($a_tmp_file, $tmpdir .
"/" . $a_filename);
184 ilUtil::moveUploadedFile($a_tmp_file, $a_filename, $tmpdir .
"/" . $a_filename);
187 $this->log->debug(
"unzip: " . $tmpdir .
"/" . $a_filename);
190 $dir = $tmpdir .
"/" . substr($a_filename, 0, strlen($a_filename) - 4);
194 $this->log->debug(
"dir: " . $dir);
198 if (is_array(
$ret)) {
199 $new_id =
$ret[
'new_id'];
217 if (is_array(
$ret)) {
218 return $ret[
'new_id'];
231 $this->tmp_import_dir = $a_val;
251 if ($a_component ==
"") {
252 include_once(
"./Services/Export/classes/class.ilImportExportFactory.php");
253 $a_component = ilImportExportFactory::getComponentForExport(
$a_type);
255 $this->comp = $a_component;
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");
265 ?
'Manifest file not found: "' . $dir .
"/manifest.xml" .
'".' 266 :
'Manifest file not found: "manifest.xml."';
268 $e->setManifestDir($dir);
269 $e->setTmpDir($a_tmpdir);
273 $this->mapping->setInstallUrl(
$parser->getInstallUrl());
274 $this->mapping->setInstallId(
$parser->getInstallId());
278 include_once(
"./Services/Export/exceptions/class.ilImportObjectTypeMismatchException.php");
284 $expfiles =
$parser->getExportFiles();
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);
297 $this->log->warning(
"no class found for component: $comp");
301 $this->log->debug(
"create new class = $class");
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;
310 $this->log->debug(
"Process file: " . $dir .
"/" . $expfile[
"path"]);
313 $this->log->error(
"Import failed: " . $e->getMessage());
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) {
327 foreach ($all_importers as $imp) {
328 $this->log->debug(
"Call finalProcessing for: " . get_class($imp));
329 $imp->finalProcessing($this->mapping);
333 $top_mapping = $this->mapping->getMappingsOfEntity($this->comp,
$a_type);
334 $new_id = (int) current($top_mapping);
337 'importers' => (array) $all_importers
346 public function processItemXml($a_entity, $a_schema_version, $a_id, $a_xml, $a_install_id, $a_install_url)
350 $objDefinition = $DIC[
'objDefinition'];
353 if ($this->skip_entity[$this->current_comp][$a_entity]) {
357 if ($objDefinition->isRBACObject($a_entity) &&
358 $this->
getMapping()->getMapping(
'Services/Container',
'imported', $a_id)) {
359 $this->log->info(
'Ignoring referenced ' . $a_entity .
' with id ' . $a_id);
362 $this->importer->setInstallId($a_install_id);
363 $this->importer->setInstallUrl($a_install_url);
364 $this->importer->setSchemaVersion($a_schema_version);
365 $this->importer->setSkipEntities($this->skip_entity);
366 $new_id = $this->importer->importXmlRepresentation($a_entity, $a_id, $a_xml, $this->mapping);
369 if ($objDefinition->isRBACObject($a_entity)) {
370 $this->
getMapping()->addMapping(
'Services/Container',
'imported', $a_id, 1);
374 if ($new_id && $new_id !==
true) {
375 $this->mapping->addMapping($this->comp, $a_entity, $a_id, $new_id);
importEntity( $a_tmp_file, $a_filename, $a_entity, $a_component, $a_copy_file=false)
Import entity.
setEntityTypes($a_val)
Set entity types.
doImportObject($dir, $a_type, $a_component="", $a_tmpdir="")
Import repository object export file.
afterEntityTypes()
After entity types are parsed.
getMapping()
Get mapping object.
processItemXml($a_entity, $a_schema_version, $a_id, $a_xml, $a_install_id, $a_install_url)
Process item xml.
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
importFromDirectory($dir, $a_type, $a_comp)
Import from directory.
addSkipEntity($a_component, $a_entity, $skip=true)
Add skip entity.
getTemporaryImportDir()
Get temporary import directory.
General import exception.
manifest.xml file not found-exception for import
setCurrentDataset($a_val)
Set currrent dataset.
importObject( $a_new_obj, $a_tmp_file, $a_filename, $a_type, $a_comp="", $a_copy_file=false)
Import repository object export file.
static _lookupType($a_id, $a_reference=false)
lookup object type
getConfig($a_comp)
Get configuration (note that configurations are optional, null may be returned!)
Manifest parser for ILIAS standard export files.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
getEntityTypes()
Get entity types.
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static _writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
static getLogger($a_component_id)
Get component logger.
importRecord($a_entity, $a_types, $a_record)
After entity types are parsed.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
Import object type does not match.
setTemporaryImportDir($a_val)
Set temporary import directory.
getCurrentDataset()
Get currrent dataset.
__construct($a_target_id=0)
Constructor.