19 declare(strict_types=1);
56 $this->log = $DIC->logger()->exp();
68 if (isset($this->configs[$a_comp])) {
69 return $this->configs[$a_comp];
73 $comp_arr = explode(
"/", $a_comp);
74 $a_class =
"il" . $comp_arr[1] .
"ExportConfig";
75 $exp_config =
new $a_class();
76 $this->configs[$a_comp] = $exp_config;
89 $tree = $DIC->repositoryTree();
91 $valid_items = array();
92 $sub_items = $tree->getSubTree($tree->getNodeData($a_ref_id));
93 foreach ($sub_items as $sub_item) {
94 if (in_array($sub_item[
"type"], self::$export_implementer)) {
96 "type" => (string) $sub_item[
"type"],
97 "title" => (
string) $sub_item[
"title"],
98 "ref_id" => (
int) $sub_item[
"child"],
99 "obj_id" => (
int) $sub_item[
"obj_id"],
116 if (is_array($files)) {
118 return (
int) $files[0][
"timestamp"];
133 string $a_obj_type =
"" 136 if (is_array($files)) {
153 string $a_type =
"xml",
154 string $a_obj_type =
"",
155 string $a_entity =
"" 159 $logger = $DIC->logger()->exp();
160 $objDefinition = $DIC[
'objDefinition'];
162 $ent = ($a_entity ==
"")
166 if ($a_obj_type ==
"") {
170 if (in_array($a_obj_type, self::$new_file_structure)) {
172 $dir .=
'il' . $objDefinition->getClassName($a_obj_type) . $ent . DIRECTORY_SEPARATOR;
173 $dir .= self::createPathFromId($a_obj_id, $a_obj_type) . DIRECTORY_SEPARATOR;
174 $dir .= ($a_type ==
'xml' ?
'export' :
'export_' . $a_type);
178 $exporter_class = ilImportExportFactory::getExporterClass($a_obj_type);
179 $export_dir = call_user_func(
180 array($exporter_class,
'lookupExportDirectory'),
187 $logger->debug(
'Export dir is ' . $export_dir);
197 public static function _getExportFiles(
int $a_obj_id, $a_export_types =
"",
string $a_obj_type =
""): array
199 if ($a_obj_type ==
"") {
203 if ($a_export_types ==
"") {
204 $a_export_types = array(
"xml");
206 if (!is_array($a_export_types)) {
207 $a_export_types = array($a_export_types);
213 $types = $a_export_types;
215 foreach ($types as $type) {
219 if (!is_dir($dir) || !is_writable($dir)) {
227 while ($entry = $h_dir->read()) {
228 if ($entry !==
"." &&
230 substr($entry, -4) ===
".zip" &&
231 preg_match(
"/^[0-9]{10}_{2}[0-9]+_{2}(" . $a_obj_type .
"_)*[0-9]+\.zip\$/", $entry)) {
232 $ts = substr($entry, 0, strpos($entry,
"__"));
233 $file[$entry . $type] = [
234 "type" => (string) $type,
235 "file" => (
string) $entry,
236 "size" => (
int) filesize($dir .
"/" . $entry),
237 "timestamp" => (
int) $ts
254 string $a_export_type =
"xml",
255 string $a_obj_type =
"" 261 if ($a_obj_type ==
"") {
282 $lng = $DIC->language();
283 $lng->loadLanguageModule(
"export");
290 $a_tpl->setVariable(
"LOCATION_STYLESHEET", $location_stylesheet);
291 $a_tpl->loadStandardTemplate();
293 $a_tpl->setDescription(
$lng->txt(
"export_export_date") .
": " .
294 date(
'Y-m-d H:i:s', time()) .
" (" . date_default_timezone_get() .
")");
295 $f_tpl =
new ilTemplate(
"tpl.export_list.html",
true,
true,
"Services/Export");
296 foreach ($a_files as $file) {
297 $f_tpl->setCurrentBlock(
"file_row");
298 $f_tpl->setVariable(
"TITLE", $file[
"title"]);
299 $f_tpl->setVariable(
"TYPE",
$lng->txt(
"obj_" . $file[
"type"]));
300 $f_tpl->setVariable(
"FILE", $file[
"file"]);
301 $f_tpl->parseCurrentBlock();
303 $a_tpl->setContent($f_tpl->get());
304 $index_content = $a_tpl->getSpecial(
"DEFAULT",
false,
false,
false,
true,
false,
false);
306 $f = fopen($a_filename,
"w");
307 fwrite(
$f, $index_content);
332 string $a_target_release =
"" 334 $this->log->debug(
"export type: $a_type, id: $a_id, target_release: " . $a_target_release);
337 if ($a_target_release ==
"") {
339 $a_target_release = $v[0] .
"." . $v[1] .
".0";
340 $this->log->debug(
"target_release set to: " . $a_target_release);
345 $this->manifest_writer->xmlHeader();
346 $this->manifest_writer->xmlStartTag(
349 "MainEntity" => $a_type,
353 "InstallationUrl" => ILIAS_HTTP_PATH
363 $sub_dir = $ts .
'__' .
IL_INST_ID .
'__' . $a_type .
'_' . $a_id;
364 $new_file = $sub_dir .
'.zip';
366 $this->export_run_dir = $export_dir .
"/" . $sub_dir;
368 $this->log->debug(
"export dir: " . $this->export_run_dir);
370 $this->cnt = array();
372 $class = ilImportExportFactory::getExporterClass($a_type);
373 $comp = ilImportExportFactory::getComponentForExport($a_type);
375 $success = $this->
processExporter($comp, $class, $a_type, $a_target_release, [$a_id]);
377 $this->manifest_writer->xmlEndTag(
'Manifest');
378 $this->manifest_writer->xmlDumpFile($this->export_run_dir .
"/manifest.xml",
false);
381 $this->log->debug(
"zip: " . $export_dir .
"/" . $new_file);
382 $this->log->debug(
"run dir: " . $this->export_run_dir);
389 $exp->setVersion($a_target_release);
391 $exp->setExportType(
'xml');
392 $exp->setFilename($new_file);
397 "success" => $success,
399 "directory" => $export_dir
414 string $a_target_release,
417 string $a_export_dir,
418 string $a_type_for_file =
"" 422 $objDefinition = $DIC[
'objDefinition'];
426 if ($a_target_release ==
"") {
428 $a_target_release = $v[0] .
"." . $v[1] .
".0";
431 if ($a_type_for_file ==
"") {
432 $a_type_for_file = $a_entity;
435 $comp = $a_component;
436 $c = explode(
"/", $comp);
437 $class =
"il" .
$c[1] .
"Exporter";
441 $this->manifest_writer->xmlHeader();
442 $this->manifest_writer->xmlStartTag(
445 "MainEntity" => $a_entity,
449 "InstallationUrl" => ILIAS_HTTP_PATH
453 $export_dir = $a_export_dir;
457 $sub_dir = $ts .
'__' .
IL_INST_ID .
'__' . $a_type_for_file .
'_' . $a_id;
458 $new_file = $sub_dir .
'.zip';
460 $this->export_run_dir = $export_dir .
"/" . $sub_dir;
463 $this->cnt = array();
464 $success = $this->
processExporter($comp, $class, $a_entity, $a_target_release, [$a_id]);
465 $this->manifest_writer->xmlEndTag(
'Manifest');
466 $this->manifest_writer->xmlDumpFile($this->export_run_dir .
"/manifest.xml",
false);
473 "success" => $success,
475 "directory" => $export_dir
493 string $a_target_release,
497 $this->log->debug(
"process exporter, comp: " . $a_comp .
", class: " . $a_class .
", entity: " . $a_entity .
498 ", target release " . $a_target_release .
", id: " . print_r($a_id,
true));
500 if (!is_array($a_id)) {
504 $a_id = array($a_id);
508 if (!class_exists($a_class)) {
509 $export_class_file =
"./" . $a_comp .
"/classes/class." . $a_class .
".php";
510 if (!is_file($export_class_file)) {
511 throw new ilExportException(
'Export class file "' . $export_class_file .
'" not found.');
515 $exp =
new $a_class();
516 $exp->setExport($this);
517 if (!isset($this->cnt[$a_comp])) {
518 $this->cnt[$a_comp] = 1;
520 $this->cnt[$a_comp]++;
522 $set_dir_relative = $a_comp .
"/set_" . $this->cnt[$a_comp];
523 $set_dir_absolute = $this->export_run_dir .
"/" . $set_dir_relative;
525 $this->log->debug(
"dir: " . $set_dir_absolute);
527 $this->log->debug(
"init exporter");
531 $this->log->debug(
"process head dependencies for " . $a_entity);
532 $sequence = $exp->getXmlExportHeadDependencies($a_entity, $a_target_release, $a_id);
533 foreach ($sequence as $s) {
534 $comp = explode(
"/", $s[
"component"]);
535 $exp_class =
"il" . $comp[1] .
"Exporter";
550 $export_writer->xmlHeader();
552 $sv = $exp->determineSchemaVersion($a_entity, $a_target_release);
553 $sv[
"uses_dataset"] ??=
false;
554 $sv[
'xsd_file'] ??=
'';
555 $this->log->debug(
"schema version for entity: $a_entity, target release: $a_target_release");
556 $this->log->debug(
"...is: " . $sv[
"schema_version"] .
", namespace: " . $sv[
"namespace"] .
557 ", xsd file: " . $sv[
"xsd_file"] .
", uses_dataset: " . ((
int) $sv[
"uses_dataset"]));
559 $attribs = array(
"InstallationId" =>
IL_INST_ID,
560 "InstallationUrl" => ILIAS_HTTP_PATH,
561 "Entity" => $a_entity,
562 "SchemaVersion" => $sv[
"schema_version"],
564 "xmlns:xsi" =>
"http://www.w3.org/2001/XMLSchema-instance",
565 "xmlns:exp" =>
"http://www.ilias.de/Services/Export/exp/4_1",
566 "xsi:schemaLocation" =>
"http://www.ilias.de/Services/Export/exp/4_1 " . ILIAS_HTTP_PATH .
"/xml/ilias_export_4_1.xsd" 568 if ($sv[
"namespace"] !=
"" && $sv[
"xsd_file"] !=
"") {
569 $attribs[
"xsi:schemaLocation"] .=
" " . $sv[
"namespace"] .
" " .
570 ILIAS_HTTP_PATH .
"/xml/" . $sv[
"xsd_file"];
571 $attribs[
"xmlns"] = $sv[
"namespace"];
573 if ($sv[
"uses_dataset"]) {
574 $attribs[
"xsi:schemaLocation"] .=
" " .
575 "http://www.ilias.de/Services/DataSet/ds/4_3 " . ILIAS_HTTP_PATH .
"/xml/ilias_ds_4_3.xsd";
576 $attribs[
"xmlns:ds"] =
"http://www.ilias.de/Services/DataSet/ds/4_3";
578 $export_writer->xmlStartTag(
'exp:Export', $attribs);
581 foreach ($a_id as
$id) {
582 $exp->setExportDirectories(
583 $set_dir_relative .
"/expDir_" . $dir_cnt,
584 $set_dir_absolute .
"/expDir_" . $dir_cnt
586 $export_writer->xmlStartTag(
'exp:ExportItem', array(
"Id" => $id));
588 $xml = $exp->getXmlRepresentation($a_entity, $sv[
"schema_version"], (
string) $id);
589 $export_writer->appendXML($xml);
590 $export_writer->xmlEndTag(
'exp:ExportItem');
594 $export_writer->xmlEndTag(
'exp:Export');
595 $export_writer->xmlDumpFile($set_dir_absolute .
"/export.xml",
false);
597 $this->manifest_writer->xmlElement(
599 array(
"Component" => $a_comp,
"Path" => $set_dir_relative .
"/export.xml")
603 $this->log->debug(
"process tail dependencies of " . $a_entity);
604 $sequence = $exp->getXmlExportTailDependencies($a_entity, $a_target_release, $a_id);
605 foreach ($sequence as $s) {
606 if (empty((array) ($s[
"ids"] ?? []))) {
610 $comp = explode(
"/", $s[
"component"]);
611 $exp_class =
"il" . $comp[1] .
"Exporter";
624 $this->log->debug(
"returning " . ((
int) $success) .
" for " . $a_entity);
635 $num = $a_container_id;
637 for ($i = $max_exponent; $i > 0; $i--) {
638 $factor = pow($factor, $i);
639 if (($tmp = (
int) ($num / $factor)) or $found) {
641 $num = $num % $factor;
646 $path_string = (implode(
'/',
$path) .
'/');
648 return $path_string . $a_name .
'_' . $a_container_id;
static _getLastExportFileDate(int $a_obj_id, string $a_type="", string $a_obj_type="")
Get date of last export file.
const ILIAS_VERSION_NUMERIC
special template class to simplify handling of ITX/PEAR
getConfig(string $a_comp)
Get configuration (note that configurations are optional, null may be returned!)
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getStyleSheetLocation(string $mode="output", string $a_css_name="", string $a_css_location="")
get full style sheet file name (path inclusive) of current user
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.
static _getValidExportSubItems(int $a_ref_id)
Get a list of subitems of a repository resource, that implement the export.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
processExporter(string $a_comp, string $a_class, string $a_entity, string $a_target_release, array $a_id=null)
Process exporter.
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
static _getExportFiles(int $a_obj_id, $a_export_types="", string $a_obj_type="")
ilXmlWriter $manifest_writer
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
static _getLastExportFileInformation(int $a_obj_id, string $a_type="", string $a_obj_type="")
Get last export file information.
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)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static _lookupType(int $id, bool $reference=false)
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)