19 declare(strict_types=1);
59 $this->log = $DIC->logger()->exp();
63 ExportPathInfoInterface $export_path_info
74 return $this->export_path_info->getPathToComponentDirInContainer();
84 return $this->export_path_info->getPathToComponentExpDirInContainer();
89 return "set_" . $this->export_path_info->getSetNumber() . DIRECTORY_SEPARATOR . $this->export_path_info->getPathToComponentExpDirInContainer();
94 return $this->export_path_info->getSetNumber();
99 return $this->export_path_info->isContainerExport();
103 string $a_dir_relative,
104 string $a_dir_absolute
106 $this->dir_relative = $a_dir_relative;
107 $this->dir_absolute = $a_dir_absolute;
121 ilExportHandlerConsumerExportWriterInterface $export_writer,
132 ExportConfigCollectionInterface $export_configs
151 $tree = $DIC->repositoryTree();
153 $valid_items = array();
154 $sub_items = $tree->getSubTree($tree->getNodeData($a_ref_id));
155 foreach ($sub_items as $sub_item) {
156 if (in_array($sub_item[
"type"], self::$export_implementer)) {
158 "type" => (string) $sub_item[
"type"],
159 "title" => (
string) $sub_item[
"title"],
160 "ref_id" => (
int) $sub_item[
"child"],
161 "obj_id" => (
int) $sub_item[
"obj_id"],
179 if (is_array($files)) {
181 return (
int) $files[0][
"timestamp"];
197 string $a_obj_type =
"" 200 if (is_array($files)) {
218 string $a_type =
"xml",
219 string $a_obj_type =
"",
220 string $a_entity =
"" 224 $logger = $DIC->logger()->exp();
225 $objDefinition = $DIC[
'objDefinition'];
227 $ent = ($a_entity ==
"")
231 if ($a_obj_type ==
"") {
235 if (in_array($a_obj_type, self::$new_file_structure)) {
237 $dir .=
'il' . $objDefinition->getClassName($a_obj_type) . $ent . DIRECTORY_SEPARATOR;
238 $dir .= self::createPathFromId($a_obj_id, $a_obj_type) . DIRECTORY_SEPARATOR;
239 $dir .= ($a_type ==
'xml' ?
'export' :
'export_' . $a_type);
243 $exporter_class = ilImportExportFactory::getExporterClass($a_obj_type);
244 $export_dir = call_user_func(
245 array($exporter_class,
'lookupExportDirectory'),
252 $logger->debug(
'Export dir is ' . $export_dir);
263 public static function _getExportFiles(
int $a_obj_id, $a_export_types =
"",
string $a_obj_type =
""): array
265 if ($a_obj_type ==
"") {
269 if ($a_export_types ==
"") {
270 $a_export_types = array(
"xml");
272 if (!is_array($a_export_types)) {
273 $a_export_types = array($a_export_types);
279 $types = $a_export_types;
281 foreach ($types as $type) {
285 if (!is_dir($dir) || !is_writable($dir)) {
293 while ($entry = $h_dir->read()) {
294 if ($entry !==
"." &&
296 substr($entry, -4) ===
".zip" &&
297 preg_match(
"/^[0-9]{10}_{2}[0-9]+_{2}(" . $a_obj_type .
"_)*[0-9]+\.zip\$/", $entry)) {
298 $ts = substr($entry, 0, strpos($entry,
"__"));
299 $file[$entry . $type] = [
300 "type" => (string) $type,
301 "file" => (
string) $entry,
302 "size" => (
int) filesize($dir .
"/" . $entry),
303 "timestamp" => (
int) $ts
320 string $a_export_type =
"xml",
321 string $a_obj_type =
"" 327 if ($a_obj_type ==
"") {
349 $lng = $DIC->language();
350 $lng->loadLanguageModule(
"export");
357 $a_tpl->setVariable(
"LOCATION_STYLESHEET", $location_stylesheet);
358 $a_tpl->loadStandardTemplate();
360 $a_tpl->setDescription(
$lng->txt(
"export_export_date") .
": " .
361 date(
'Y-m-d H:i:s', time()) .
" (" . date_default_timezone_get() .
")");
362 $f_tpl =
new ilTemplate(
"tpl.export_list.html",
true,
true,
"components/ILIAS/Export");
363 foreach ($a_files as $file) {
364 $f_tpl->setCurrentBlock(
"file_row");
365 $f_tpl->setVariable(
"TITLE", $file[
"title"]);
366 $f_tpl->setVariable(
"TYPE",
$lng->txt(
"obj_" . $file[
"type"]));
367 $f_tpl->setVariable(
"FILE", $file[
"file"]);
368 $f_tpl->parseCurrentBlock();
370 $a_tpl->setContent($f_tpl->get());
371 $index_content = $a_tpl->getSpecial(
"DEFAULT",
false,
false,
false,
true,
false,
false);
373 $f = fopen($a_filename,
"w");
374 fwrite(
$f, $index_content);
400 string $a_target_release =
"" 402 $this->log->debug(
"export type: $a_type, id: $a_id, target_release: " . $a_target_release);
405 if ($a_target_release ==
"") {
407 $a_target_release = $v[0] .
"." . $v[1] .
".0";
408 $this->log->debug(
"target_release set to: " . $a_target_release);
413 $this->manifest_writer->xmlHeader();
414 $this->manifest_writer->xmlStartTag(
417 "MainEntity" => $a_type,
421 "InstallationUrl" => ILIAS_HTTP_PATH
431 $sub_dir = $ts .
'__' .
IL_INST_ID .
'__' . $a_type .
'_' . $a_id;
432 $new_file = $sub_dir .
'.zip';
434 $this->export_run_dir = $export_dir .
"/" . $sub_dir;
436 $this->log->debug(
"export dir: " . $this->export_run_dir);
438 $this->cnt = array();
440 $class = ilImportExportFactory::getExporterClass($a_type);
441 $comp = ilImportExportFactory::getComponentForExport($a_type);
443 $success = $this->
processExporter($comp, $class, $a_type, $a_target_release, [$a_id]);
445 $this->manifest_writer->xmlEndTag(
'Manifest');
446 $this->manifest_writer->xmlDumpFile($this->export_run_dir .
"/manifest.xml",
false);
449 $this->log->debug(
"zip: " . $export_dir .
"/" . $new_file);
450 $this->log->debug(
"run dir: " . $this->export_run_dir);
457 $exp->setVersion($a_target_release);
459 $exp->setExportType(
'xml');
460 $exp->setFilename($new_file);
465 "success" => $success,
467 "directory" => $export_dir
483 string $a_target_release,
486 string $a_export_dir,
487 string $a_type_for_file =
"" 491 $objDefinition = $DIC[
'objDefinition'];
495 if ($a_target_release ==
"") {
497 $a_target_release = $v[0] .
"." . $v[1] .
".0";
500 if ($a_type_for_file ==
"") {
501 $a_type_for_file = $a_entity;
504 $comp = $a_component;
505 $c = explode(
"/", $comp);
506 $component = str_replace(
"_",
"",
$c[2]);
507 $class =
"il" . $component .
"Exporter";
511 $this->manifest_writer->xmlHeader();
512 $this->manifest_writer->xmlStartTag(
515 "MainEntity" => $a_entity,
519 "InstallationUrl" => ILIAS_HTTP_PATH
523 $export_dir = $a_export_dir;
527 $sub_dir = $ts .
'__' .
IL_INST_ID .
'__' . $a_type_for_file .
'_' . $a_id;
528 $new_file = $sub_dir .
'.zip';
530 $this->export_run_dir = $export_dir .
"/" . $sub_dir;
533 $this->cnt = array();
534 $success = $this->
processExporter($comp, $class, $a_entity, $a_target_release, [$a_id]);
535 $this->manifest_writer->xmlEndTag(
'Manifest');
536 $this->manifest_writer->xmlDumpFile($this->export_run_dir .
"/manifest.xml",
false);
543 "success" => $success,
545 "directory" => $export_dir
564 string $a_target_release,
568 $this->log->debug(
"process exporter, comp: " . $a_comp .
", class: " . $a_class .
", entity: " . $a_entity .
569 ", target release " . $a_target_release .
", id: " . print_r($a_id,
true));
571 if (!is_array($a_id)) {
575 $a_id = array($a_id);
579 if (!class_exists($a_class)) {
580 $a_class = substr($a_class, 0, 2) .
"ILIAS" . substr($a_class, 2);
581 if (!class_exists($a_class)) {
582 $export_class_file =
"./" . $a_comp .
"/classes/class." . $a_class .
".php";
583 if (!is_file($export_class_file)) {
584 throw new ilExportException(
'Export class file "' . $export_class_file .
'" not found.');
589 $exp =
new $a_class();
590 $exp->setExport($this);
591 if (!isset($this->cnt[$a_comp])) {
592 $this->cnt[$a_comp] = 1;
594 $this->cnt[$a_comp]++;
596 $set_dir_relative = $a_comp .
"/set_" . $this->cnt[$a_comp];
597 $set_dir_absolute = $this->export_run_dir .
"/" . $set_dir_relative;
599 $this->log->debug(
"dir: " . $set_dir_absolute);
601 $this->log->debug(
"init exporter");
605 $this->log->debug(
"process head dependencies for " . $a_entity);
606 $sequence = $exp->getXmlExportHeadDependencies($a_entity, $a_target_release, $a_id);
607 foreach ($sequence as $s) {
608 $comp = explode(
"/", $s[
"component"]);
609 $component = str_replace(
"_",
"", $comp[2]);
610 $exp_class =
"il" . $component .
"Exporter";
625 $export_writer->xmlHeader();
627 $sv = $exp->determineSchemaVersion($a_entity, $a_target_release);
628 $sv[
"uses_dataset"] ??=
false;
629 $sv[
'xsd_file'] ??=
'';
630 $this->log->debug(
"schema version for entity: $a_entity, target release: $a_target_release");
631 $this->log->debug(
"...is: " . $sv[
"schema_version"] .
", namespace: " . $sv[
"namespace"] .
632 ", xsd file: " . $sv[
"xsd_file"] .
", uses_dataset: " . ((
int) $sv[
"uses_dataset"]));
634 $attribs = array(
"InstallationId" =>
IL_INST_ID,
635 "InstallationUrl" => ILIAS_HTTP_PATH,
636 "Entity" => $a_entity,
637 "SchemaVersion" => $sv[
"schema_version"],
639 "xmlns:xsi" =>
"http://www.w3.org/2001/XMLSchema-instance",
640 "xmlns:exp" =>
"http://www.ilias.de/Services/Export/exp/4_1",
641 "xsi:schemaLocation" =>
"http://www.ilias.de/Services/Export/exp/4_1 " . ILIAS_HTTP_PATH .
"/components/ILIAS/Export/xml/ilias_export_4_1.xsd" 643 if ($sv[
"namespace"] !=
"" && $sv[
"xsd_file"] !=
"") {
644 $attribs[
"xsi:schemaLocation"] .=
" " . $sv[
"namespace"] .
" " .
645 ILIAS_HTTP_PATH .
"/components/ILIAS/Export/xml/" . $sv[
"xsd_file"];
646 $attribs[
"xmlns"] = $sv[
"namespace"];
648 if ($sv[
"uses_dataset"]) {
649 $attribs[
"xsi:schemaLocation"] .=
" " .
650 "http://www.ilias.de/Services/DataSet/ds/4_3 " . ILIAS_HTTP_PATH .
"/components/ILIAS/Export/xml/ilias_ds_4_3.xsd";
651 $attribs[
"xmlns:ds"] =
"http://www.ilias.de/Services/DataSet/ds/4_3";
653 $export_writer->xmlStartTag(
'exp:Export', $attribs);
656 foreach ($a_id as
$id) {
657 $exp->setExportDirectories(
658 $set_dir_relative .
"/expDir_" . $dir_cnt,
659 $set_dir_absolute .
"/expDir_" . $dir_cnt
661 $export_writer->xmlStartTag(
'exp:ExportItem', array(
"Id" => $id));
662 $xml = $exp->getXmlRepresentation($a_entity, $sv[
"schema_version"], (
string) $id);
663 $export_writer->appendXML($xml);
664 $export_writer->xmlEndTag(
'exp:ExportItem');
668 $export_writer->xmlEndTag(
'exp:Export');
669 $export_writer->xmlDumpFile($set_dir_absolute .
"/export.xml",
false);
671 $this->manifest_writer->xmlElement(
673 array(
"Component" => $a_comp,
"Path" => $set_dir_relative .
"/export.xml")
677 $this->log->debug(
"process tail dependencies of " . $a_entity);
678 $sequence = $exp->getXmlExportTailDependencies($a_entity, $a_target_release, $a_id);
679 foreach ($sequence as $s) {
680 if (empty((array) ($s[
"ids"] ?? []))) {
684 $comp = explode(
"/", $s[
"component"]);
685 $component = str_replace(
"_",
"", $comp[2]);
686 $exp_class =
"il" . $component .
"Exporter";
699 $this->log->debug(
"returning " . ((
int) $success) .
" for " . $a_entity);
710 $num = $a_container_id;
712 for ($i = $max_exponent; $i > 0; $i--) {
713 $factor = pow($factor, $i);
714 if (($tmp = (
int) ($num / $factor)) or $found) {
716 $num = $num % $factor;
721 $path_string = (implode(
'/',
$path) .
'/');
723 return $path_string . $a_name .
'_' . $a_container_id;
ilExportHandlerConsumerExportWriterInterface $export_writer
static getStyleSheetLocation(string $mode="output", string $a_css_name="")
get full style sheet file name (path inclusive) of current user
static _getLastExportFileDate(int $a_obj_id, string $a_type="", string $a_obj_type="")
Get date of last export file
getPathToComponentExpDirInContainer()
special template class to simplify handling of ITX/PEAR
ExportConfigCollectionInterface $export_configs
static array $new_file_structure
exportEntity(string $a_entity, string $a_id, string $a_target_release, string $a_component, string $a_title, string $a_export_dir, string $a_type_for_file="")
Export an ILIAS entity
processExporter(string $a_comp, string $a_class, string $a_entity, string $a_target_release, ?array $a_id=null)
Process exporter
setPathInfo(ExportPathInfoInterface $export_path_info)
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static _getExportDirectory(int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
Get export directory for an repository object
getExportDirInContainer()
getPathToComponentExpDirInContainerWithLeadingSetNumber()
static _getValidExportSubItems(int $a_ref_id)
Get a list of subitems of a repository resource, that implement the export.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
const ILIAS_VERSION_NUMERIC
static _lookupTitle(int $obj_id)
static _generateIndexFile(string $a_filename, int $a_obj_id, array $a_files, string $a_type="")
Generates an index.html file including links to all xml files included (for container exports) ...
static _createExportDirectory(int $a_obj_id, string $a_export_type="xml", string $a_obj_type="")
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
ExportPathInfoInterface $export_path_info
static _getExportFiles(int $a_obj_id, $a_export_types="", string $a_obj_type="")
ilXmlWriter $manifest_writer
Stores information of creation date and versions of export files
getAbsoluteExportDirectory()
getRelativeExportDirectory()
setExportConfigs(ExportConfigCollectionInterface $export_configs)
exportObject(string $a_type, int $a_id, string $a_target_release="")
Export an ILIAS object (the object type must be known by objDefinition)
static getDataDir()
get data directory (outside webspace)
setExportWriter(ilExportHandlerConsumerExportWriterInterface $export_writer,)
static _getLastExportFileInformation(int $a_obj_id, string $a_type="", string $a_obj_type="")
Get last export file information
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static array $export_implementer
static createPathFromId(int $a_container_id, string $a_name)
static zip(string $a_dir, string $a_file, bool $compress_content=false)
static _lookupType(int $id, bool $reference=false)
setExportDirectories(string $a_dir_relative, string $a_dir_absolute)
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)