ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExportContainer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
30{
31 private string $cont_export_dir = '';
35
41 {
42 $this->eo = $eo;
44 global $DIC;
45 $this->archives = $DIC->legacyArchives();
46 }
47
51 public function exportObject(string $a_type, int $a_id, string $a_target_release = ""): array
52 {
53 $log = $GLOBALS['DIC']->logger()->exp();
54
55 // if no target release specified, use latest major release number
56 if ($a_target_release == "") {
57 $v = explode(".", ILIAS_VERSION_NUMERIC);
58 $a_target_release = $v[0] . "." . $v[1] . ".0";
59 }
60
61 // Create base export directory
62 ilExport::_createExportDirectory($a_id, "xml", $a_type);
63 $export_dir = ilExport::_getExportDirectory($a_id, "xml", $a_type);
64 $ts = time();
65 $sub_dir = $ts . "__" . IL_INST_ID . "__" . $a_type . "_" . $a_id;
66
67 $this->cont_export_dir = $export_dir . DIRECTORY_SEPARATOR . $sub_dir;
68 ilFileUtils::makeDirParents($this->cont_export_dir);
69
70 $log->debug('Using base directory: ' . $this->export_run_dir);
71
72 $this->manifestWriterBegin($a_type, $a_id, $a_target_release);
73 $this->addContainer();
74 $this->addSubitems($a_id, $a_type, $a_target_release);
75 $this->manifestWriterEnd($a_type, $a_id, $a_target_release);
76
77 ilFileUtils::zip($this->cont_export_dir, $this->cont_export_dir . '.zip');
78 ilFileUtils::delDir($this->cont_export_dir);
79 return [];
80 }
81
82 protected function manifestWriterBegin(string $a_type, int $a_id, string $a_target_release): void
83 {
84 $this->cont_manifest_writer = new ilXmlWriter();
85 $this->cont_manifest_writer->xmlHeader();
86 $this->cont_manifest_writer->xmlStartTag(
87 'Manifest',
88 array(
89 "MainEntity" => $a_type,
90 "Title" => ilObject::_lookupTitle($a_id),
91 /* "TargetRelease" => $a_target_release, */
92 "InstallationId" => IL_INST_ID,
93 "InstallationUrl" => ILIAS_HTTP_PATH
94 )
95 );
96 }
97
98 protected function addContainer(): void
99 {
100 }
101
102 protected function addSubitems(int $a_id, string $a_type, string $a_target_release): void
103 {
104 $set_number = 1;
105 foreach ($this->eo->getSubitemsForExport() as $ref_id) {
106 // get last export file
108
109 $expi = ilExportFileInfo::lookupLastExport($obj_id, 'xml', $a_target_release);
110
111 if (!$expi instanceof ilExportFileInfo) {
112 $this->log->warning('Cannot find export file for refId ' . $ref_id . ', type ' . ilObject::_lookupType($a_id));
113 continue;
114 }
115
116 $exp_dir = ilExport::_getExportDirectory($obj_id, 'xml', ilObject::_lookupType($obj_id));
117 $exp_full = $exp_dir . DIRECTORY_SEPARATOR . $expi->getFilename();
118
119 $this->log->debug('Zip path ' . $exp_full);
120
121 // Unzip
122 $this->archives->unzip(
123 $exp_full
124 );
125
126 // create set directory
127 ilFileUtils::makeDirParents($this->cont_export_dir . DIRECTORY_SEPARATOR . 'set_' . $set_number);
128
129 // cut .zip
130 $new_path_rel = 'set_' . $set_number . DIRECTORY_SEPARATOR . $expi->getBasename();
131 $new_path_abs = $this->cont_export_dir . DIRECTORY_SEPARATOR . $new_path_rel;
132
133 $this->log->debug($new_path_rel . ' ' . $new_path_abs);
134
135 // Move export
136 rename(
137 $exp_dir . DIRECTORY_SEPARATOR . $expi->getBasename(),
138 $new_path_abs
139 );
140
141 $this->log->debug($exp_dir . DIRECTORY_SEPARATOR . $expi->getBasename() . ' -> ' . $new_path_abs);
142
143 // Delete latest container xml of source
144 if ($a_id == $obj_id) {
145 $expi->delete();
146 if (file_exists($exp_full)) {
147 $this->log->info('Deleting' . $exp_full);
148 unlink($exp_full);
149 }
150 }
151
152 $this->cont_manifest_writer->xmlElement(
153 'ExportSet',
154 array(
155 'Path' => $new_path_rel,
156 'Type' => ilObject::_lookupType($obj_id)
157 )
158 );
159 ++$set_number;
160 }
161 }
162
163 protected function manifestWriterEnd(string $a_type, int $a_id, string $a_target_release): void
164 {
165 $this->cont_manifest_writer->xmlEndTag('Manifest');
166 $this->log->debug($this->cont_export_dir . DIRECTORY_SEPARATOR . 'manifest.xml');
167 $this->cont_manifest_writer->xmlDumpFile($this->cont_export_dir . DIRECTORY_SEPARATOR . 'manifest.xml', true);
168 }
169}
addSubitems(int $a_id, string $a_type, string $a_target_release)
manifestWriterEnd(string $a_type, int $a_id, string $a_target_release)
manifestWriterBegin(string $a_type, int $a_id, string $a_target_release)
exportObject(string $a_type, int $a_id, string $a_target_release="")
@inheritDoc
__construct(ilExportOptions $eo)
Constructor.
@classDescription Stores information of creation date and versions of export files
static lookupLastExport(int $a_obj_id, string $a_type, string $a_version='')
Lookup last export.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _createExportDirectory(int $a_obj_id, string $a_export_type="xml", string $a_obj_type="")
ilLogger $log
static _getExportDirectory(int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
@depricated Get export directory for an repository object
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static zip(string $a_dir, string $a_file, bool $compress_content=false)
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
debug(string $message, array $context=[])
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_INST_ID
Definition: constants.php:40
const ILIAS_VERSION_NUMERIC
$ref_id
Definition: ltiauth.php:66
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54