ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMediaPoolExportOptionXMLMaster.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24use ILIAS\Export\ExportHandler\I\Consumer\Context\HandlerInterface as ilExportHandlerConsumerContextInterface;
25use ILIAS\Export\ExportHandler\I\Consumer\File\Identifier\CollectionInterface as ilExportHandlerConsumerFileIdentifierCollectionInterface;
26use ILIAS\Export\ExportHandler\I\Consumer\File\Identifier\HandlerInterface as ilExportHandlerConsumerFileIdentifierInterface;
27use ILIAS\Export\ExportHandler\I\Info\File\CollectionInterface as ilExportHandlerFileInfoCollectionInterface;
30
31class ilMediaPoolExportOptionXMLMaster extends ilBasicLegacyExportOption
32{
33 protected ilLanguage $lng;
34 protected ilDBInterface $db;
35
36 public function init(Container $DIC): void
37 {
38 $this->lng = $DIC->language();
39 $this->db = $DIC->database();
41 }
42
43 public function getExportType(): string
44 {
45 return 'xml_master';
46 }
47
48 public function getExportOptionId(): string
49 {
50 return 'mep_exp_option_xml_master';
51 }
52
53 public function getSupportedRepositoryObjectTypes(): array
54 {
55 return ['mep'];
56 }
57
58 public function getLabel(): string
59 {
60 $this->lng->loadLanguageModule('exp');
61 return $this->lng->txt("exp_format_dropdown-xml") . " (" . $this->lng->txt("mep_master_language_only") . ")";
62 }
63
64 public function onDownloadFiles(
65 ilExportHandlerConsumerContextInterface $context,
66 ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
67 ): void {
68 foreach ($file_identifiers as $file_identifier) {
69 $file = explode(":", trim($file_identifier->getIdentifier()));
71 $context->exportObject()->getId(),
72 "",
73 $context->exportObject()->getType()
74 );
75 $export_dir = substr($export_dir, 0, strlen($export_dir) - 1);
76 $file[1] = basename($file[1]);
78 $export_dir . "/" . $file[1],
79 $file[1]
80 );
81 }
82 }
83
84 public function onDownloadWithLink(
85 ReferenceId $reference_id,
86 ilExportHandlerConsumerFileIdentifierInterface $file_identifier
87 ): void {
88 $object_id = $reference_id->toObjectId()->toInt();
89 $type = ilObject::_lookupType($object_id);
90 $file = explode(":", trim($file_identifier->getIdentifier()));
92 $object_id,
93 "",
94 $type
95 );
96 $export_dir = substr($export_dir, 0, strlen($export_dir) - 1);
97 $file[1] = basename($file[1]);
99 $export_dir . "/" . $file[1],
100 $file[1]
101 );
102 }
103
104 public function onDeleteFiles(
105 ilExportHandlerConsumerContextInterface $context,
106 ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
107 ): void {
108 foreach ($file_identifiers as $file_identifier) {
109 $file = explode(":", $file_identifier->getIdentifier());
110 $file[1] = basename($file[1]);
111 $export_dir = ilExport::_getExportDirectory(
112 $context->exportObject()->getId(),
113 "",
114 $context->exportObject()->getType()
115 );
116 $export_dir = substr($export_dir, 0, strlen($export_dir) - 1);
117 $exp_file = $export_dir . "/" . str_replace("..", "", $file[1]);
118 $exp_dir = $export_dir . "/" . substr($file[1], 0, strlen($file[1]) - 4);
119 if (is_file($exp_file)) {
120 unlink($exp_file);
121 }
122 if (
123 is_dir($exp_dir) and
124 count(scandir($exp_dir)) === 2
125 ) {
126 ilFileUtils::delDir($exp_dir);
127 }
128 }
129 }
130
131 public function getFiles(
132 ilExportHandlerConsumerContextInterface $context
133 ): \ILIAS\Export\ExportHandler\I\Info\File\CollectionInterface {
134 $collection_builder = $context->fileCollectionBuilder();
136 $context->exportObject()->getId(),
137 "",
138 $context->exportObject()->getType()
139 );
140 $dir = substr($dir, 0, strlen($dir) - 1);
141 $file_infos = $this->getExportFiles($dir);
142 $object_id = new ObjectId($context->exportObject()->getId());
143 foreach ($file_infos as $file_name => $file_info) {
144 $collection_builder = $collection_builder->withSPLFileInfo(
145 new SplFileInfo($dir . DIRECTORY_SEPARATOR . $file_info["file"]),
146 $object_id,
147 $this
148 );
149 }
150 return $collection_builder->collection();
151 }
152
153 public function isObjectSupported(
154 ObjectId $object_id
155 ): bool {
156 $ot = (new TranslationsRepository($this->db))->getFor($object_id->toInt());
157 return $ot->getContentTranslationActivated();
158 }
159
160 public function onExportOptionSelected(
161 ilExportHandlerConsumerContextInterface $context
162 ): void {
163 if ($this->isObjectSupported(new ObjectId($context->exportObject()->getId()))) {
164 $opt = ilUtil::stripSlashes("master");
165 $context->exportObject()->exportXML($opt);
166 }
167 $this->ctrl->redirectByClass(ilExportGUI::class, ilExportGUI::CMD_LIST_EXPORT_FILES);
168 }
169
170 protected function getExportFiles(
171 string $directory
172 ): array {
173 $file = [];
174 try {
175 $h_dir = dir($directory);
176 while ($entry = $h_dir->read()) {
177 if (
178 $entry !== "." &&
179 $entry !== ".." &&
180 substr($entry, - 4) === ".zip"
181 ) {
182 $ts = substr($entry, 0, strpos($entry, "__"));
183 $file[$entry . $this->getExportType()] = [
184 "type" => $this->getExportType(),
185 "file" => $entry,
186 "size" => (int) filesize($directory . "/" . $entry),
187 "timestamp" => (int) $ts
188 ];
189 }
190 }
191 } catch (Exception $e) {
192
193 }
194 return $file;
195 }
196}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
language()
Get interface to the i18n service.
Definition: Container.php:95
const CMD_LIST_EXPORT_FILES
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 deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
language handling
onDownloadFiles(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
getFiles(ilExportHandlerConsumerContextInterface $context)
onDeleteFiles(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
onDownloadWithLink(ReferenceId $reference_id, ilExportHandlerConsumerFileIdentifierInterface $file_identifier)
onExportOptionSelected(ilExportHandlerConsumerContextInterface $context)
static _lookupType(int $id, bool $reference=false)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
Interface ilDBInterface.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$context
Definition: webdav.php:31