/** * Import a container * @param object $dir * @param object $type * @return */ protected function doImportObject($dir, $type) { $manifest_file = $dir . "/manifest.xml"; if (!file_exists($manifest_file)) { return false; } include_once "./Services/Export/classes/class.ilManifestParser.php"; $parser = new ilManifestParser($manifest_file); // Handling single containers without subitems if (!$parser->getExportSets()) { $this->createDummy($type); $new_id = parent::doImportObject($dir, $type); return $new_id; } // Handling containers with subitems $first = true; foreach ($parser->getExportSets() as $set) { $GLOBALS['ilLog']->write(__METHOD__ . ': do import with dir ' . $dir . DIRECTORY_SEPARATOR . $set['path'] . ' and type ' . $set['type']); $new_id = parent::doImportObject($dir . DIRECTORY_SEPARATOR . $set['path'], $set['type']); if ($first) { $ret = $new_id; $first = false; } } return $ret; }
/** * Import repository object export file * * @param string absolute filename of temporary upload file */ protected function doImportObject($dir, $a_type, $a_component = "", $a_tmpdir = "") { global $objDefinition, $tpl; if ($a_component == "") { $comp = $objDefinition->getComponentForType($a_type); $class = $objDefinition->getClassName($a_type); } else { $comp = $a_component; $c = explode("/", $comp); $class = $c[count($c) - 1]; } $this->comp = $comp; // get import class $success = true; // process manifest file include_once "./Services/Export/classes/class.ilManifestParser.php"; if (!is_file($dir . "/manifest.xml")) { include_once "./Services/Export/exceptions/class.ilManifestFileNotFoundImportException.php"; $e = new ilManifestFileNotFoundImportException('Manifest file not found: "' . $dir . "/manifest.xml" . '".'); $e->setManifestDir($dir); $e->setTmpDir($a_tmpdir); throw $e; } $parser = new ilManifestParser($dir . "/manifest.xml"); $this->mapping->setInstallUrl($parser->getInstallUrl()); $this->mapping->setInstallId($parser->getInstallId()); // process export files $expfiles = $parser->getExportFiles(); include_once "./Services/Export/classes/class.ilExportFileParser.php"; $all_importers = array(); foreach ($expfiles as $expfile) { $comp = $expfile["component"]; $comp_arr = explode("/", $comp); $import_class_file = "./" . $comp . "/classes/class.il" . $comp_arr[1] . "Importer.php"; $class = "il" . $comp_arr[1] . "Importer"; include_once $import_class_file; $this->importer = new $class(); $all_importers[] = $this->importer; $this->importer->setImportDirectory($dir); $this->importer->init(); $this->current_comp = $comp; try { $parser = new ilExportFileParser($dir . "/" . $expfile["path"], $this, "processItemXml"); } catch (Exception $e) { $GLOBALS['ilLog']->write(__METHOD__ . ': Import failed with message: ' . $e->getMessage()); #$GLOBALS['ilLog']->write(__METHOD__.': '.file_get_contents($dir.'/'.$expfile['path'])); throw $e; } } // final processing foreach ($all_importers as $imp) { $imp->finalProcessing($this->mapping); } // we should only get on mapping here $top_mapping = $this->mapping->getMappingsOfEntity($this->comp, $a_type); $new_id = (int) current($top_mapping); return $new_id; }