19 declare(strict_types=1);
60 $this->objDefinition = $DIC[
'objDefinition'];
62 $this->mapping->setTargetId($a_target_id);
63 $this->log = $DIC->logger()->exp();
64 $this->archives = $DIC->archives();
66 $this->
import =
new ilImportFactory();
67 $this->import_status =
new ilImportStatusFactory();
76 if (isset($this->configs[$a_comp])) {
77 return $this->configs[$a_comp];
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;
94 $this->entity_types = $a_val;
105 public function addSkipEntity(
string $a_component,
string $a_entity,
bool $skip =
true): void
107 $this->skip_entity[$a_component][$a_entity] = $skip;
112 $this->skip_importer[$a_component] = $skip;
123 bool $a_copy_file =
false 125 return $this->
importObject(
null, $a_tmp_file, $a_filename, $a_entity, $a_component, $a_copy_file);
128 protected function unzipFile(
129 string $zip_file_name,
130 string $path_to_tmp_upload,
131 bool $file_is_on_server
133 $import_status_collection = $this->import_status->collection()->withNumberingEnabled(
true);
135 $this->
filesystem->temp()->createDir($tmp_dir_info->getFilename());
136 $target_file_path_str = $tmp_dir_info->getRealPath() . DIRECTORY_SEPARATOR . $zip_file_name;
137 $target_dir_path_str = substr($target_file_path_str, 0, -4);
142 $file_is_on_server &&
143 !copy($path_to_tmp_upload, $target_file_path_str)
145 !$file_is_on_server &&
149 return $import_status_collection->withAddedStatus(
150 $this->import_status->handler()
152 ->withContent($this->import_status->content()->builder()->string()->withString(
153 'Could not move file.' 158 $unzip = $this->archives->unzip(
159 Streams::ofResource(fopen($target_file_path_str,
'rb')),
160 $this->archives->unzipOptions()
161 ->withZipOutputPath($tmp_dir_info->getRealPath())
162 ->withDirectoryHandling(ZipDirectoryHandling::ENSURE_SINGLE_TOP_DIR)
164 return $unzip->extract()
165 ? $import_status_collection->withAddedStatus(
166 $this->import_status->handler()->withType(StatusType::SUCCESS)
167 ->withContent($this->import_status->content()->builder()->string()->withString($target_dir_path_str))
169 : $import_status_collection->withAddedStatus(
171 ->withContent($this->import_status->content()->builder()->string()->withString(
'Unzip failed.'))
177 $export_files = $this->
import->file()->xml()->export()->collection();
178 $manifest_handlers = $this->
import->file()->xml()->manifest()->collection();
179 $statuses = $this->import_status->collection();
182 $manifest_handlers = $manifest_handlers->withElement(
183 $this->import->file()->xml()->manifest()->handler()->withFileInfo($manifest_spl)
186 $statuses = $manifest_handlers->validateElements();
191 if ($manifest_handlers->containsExportObjectType(ExportObjectType::EXPORT_SET)) {
192 $manifest_handlers = $manifest_handlers->findNextFiles();
193 $statuses = $manifest_handlers->validateElements();
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());
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);
220 foreach ($export_files as $export_file) {
221 $found_statuses = $export_file->buildValidationSets();
223 $found_statuses = $this->
import->validation()->handler()->validateSets(
224 $export_file->getValidationSets()
228 $statuses = $statuses->getMergedCollectionWith($found_statuses);
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)
235 $statuses = $statuses->getMergedCollectionWith($found_statuses);
244 ->withNumberingEnabled(
true)
255 bool $a_copy_file =
false 258 $status_collection = $this->unzipFile(
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->getRealPath() . DIRECTORY_SEPARATOR .
'manifest.xml');
273 $this->
filesystem->temp()->deleteDir($delete_dir_info->getFilename());
279 $ret = $this->
doImportObject($target_dir_info->getRealPath(), $a_type, $a_comp, $target_dir_info->getPath());
281 if (is_array($ret) && array_key_exists(
'new_id', $ret)) {
282 $new_id = $ret[
'new_id'];
285 $this->
filesystem->temp()->deleteDir($delete_dir_info->getFilename());
289 $this->
filesystem->temp()->deleteDir($delete_dir_info->getFilename());
296 if (is_array($ret)) {
297 return $ret[
'new_id'];
308 $this->tmp_import_dir = $a_val;
326 string $a_component =
"",
327 string $a_tmpdir =
"" 329 if ($a_component ==
"") {
330 $a_component = ilImportExportFactory::getComponentForExport($a_type);
332 $this->comp = $a_component;
338 if (!is_file($dir .
"/manifest.xml")) {
340 ?
'Manifest file not found: "' . $dir .
"/manifest.xml" .
'".' 341 :
'Manifest file not found: "manifest.xml."';
343 $e->setManifestDir($dir);
344 $e->setTmpDir($a_tmpdir);
348 $this->mapping->setInstallUrl($parser->getInstallUrl());
349 $this->mapping->setInstallId($parser->getInstallId());
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 .
"'." 360 $expfiles = $parser->getExportFiles();
362 $all_importers = array();
363 foreach ($expfiles as $expfile) {
364 $comp = $expfile[
"component"];
366 if (isset($this->skip_importer[$comp]) && $this->skip_importer[$comp] ===
true) {
370 $class = ilImportExportFactory::getImporterClass($comp);
376 $this->log->warning(
"no class found for component: $comp");
380 $this->log->debug(
"create new class = $class");
382 $this->importer =
new $class();
383 $this->importer->setImport($this);
386 $this->importer->init();
387 $this->current_comp =
$comp;
389 $this->log->debug(
"Process file: " . $dir .
"/" . $expfile[
"path"]);
390 $parser =
new ilExportFileParser($dir .
"/" . $expfile[
"path"], $this,
"processItemXml");
392 $this->log->error(
"Import failed: " . $e->getMessage());
393 $this->log->error(
'XML failed: ' . file_get_contents($dir .
'/' . $expfile[
'path']));
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) {
404 "il_" . $this->mapping->getInstallId() .
"_" .
ilObject::_lookupType((
int) $obj_id_new) .
"_" . $obj_id_old
410 foreach ($all_importers as $imp) {
411 $this->log->debug(
"Call finalProcessing for: " . get_class($imp));
412 $imp->finalProcessing($this->mapping);
416 $top_mapping = $this->mapping->getMappingsOfEntity($this->comp, $a_type);
418 $new_id = (
int) current($top_mapping);
421 'importers' => $all_importers
430 string $a_schema_version,
433 string $a_install_id,
434 string $a_install_url
437 if (isset($this->skip_entity[$this->current_comp][$a_entity]) &&
438 $this->skip_entity[$this->current_comp][$a_entity]) {
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);
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);
454 if ($this->objDefinition->isRBACObject($a_entity)) {
455 $this->
getMapping()->addMapping(
'components/ILIAS/Container',
'imported', $a_id,
'1');
doImportObject(string $dir, string $a_type, string $a_component="", string $a_tmpdir="")
Import repository object export file.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkStatuses(ilImportStatusHandlerCollectionInterface $import_status_collection)
static _writeImportId(int $obj_id, string $import_id)
write import id to db (static)
setEntityTypes(array $a_val)
ilImportStatusFactory $import_status
validateXMLFiles(SplFileInfo $manifest_spl)
importEntity(string $a_tmp_file, string $a_filename, string $a_entity, string $a_component, bool $a_copy_file=false)
Import entity.
__construct(int $a_target_id=0)
addSkipEntity(string $a_component, string $a_entity, bool $skip=true)
Add skip entity.
importObject(?object $a_new_obj, string $a_tmp_file, string $a_filename, string $a_type, string $a_comp="", bool $a_copy_file=false)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getTemporaryImportDir()
Get temporary import directory.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getConfig(string $a_comp)
Get configuration (note that configurations are optional, null may be returned!)
addSkipImporter(string $a_component, bool $skip=true)
Import configuration class parent class.
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
manifest.xml file not found-exception for import
Manifest parser for ILIAS standard export files.
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
setImportDirectory(string $a_val)
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.
importFromDirectory(string $dir, string $a_type, string $a_comp)
setTemporaryImportDir(string $a_val)
Set temporary import directory.
static _lookupType(int $id, bool $reference=false)
ilObjectDefinition $objDefinition
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
The Filesystems interface defines the access methods which can be used to fetch the different filesys...