ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Handler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ilFileUtils;
29use ILIAS\Export\ExportHandler\I\FactoryInterface as ilExportHandlerFactoryInterface;
30use ILIAS\Export\ExportHandler\I\Info\Export\Container\HandlerInterface as ilExportHandlerContainerExportInfoInterface;
31use ILIAS\Export\ExportHandler\I\Info\Export\Container\ObjectId\CollectionBuilderInterface as ilExportHandlerContainerExportInfoObjectIdCollectionBuilderInterface;
32use ILIAS\Export\ExportHandler\I\Info\Export\Container\ObjectId\CollectionInterface as ilExportHandlerContainerExportInfoObjectIdCollectionInterface;
33use ILIAS\Export\ExportHandler\I\Info\Export\HandlerInterface as ilExportHandlerExportInfoInterface;
34use ILIAS\Export\ExportHandler\I\Manager\HandlerInterface as ilExportHandlerManagerInterface;
35use ILIAS\Export\ExportHandler\I\Repository\Element\HandlerInterface as ilExportHandlerRepositoryElementInterface;
36use ILIAS\Export\ExportHandler\I\Target\HandlerInterface as ilExportHandlerTargetInterface;
37use ILIAS\Export\ExportHandler\I\Wrapper\DataFactory\HandlerInterface as ilExportHandlerDataFactoryWrapperInterface;
38use ILIAS\Export\ExportHandler\Info\Export\Handler as ilExportHandlerExportInfo;
41use ilObject;
44use ilTree;
45
46class Handler implements ilExportHandlerManagerInterface
47{
48 protected ilExportHandlerFactoryInterface $export_handler;
49 protected ilTree $tree;
52 protected ilExportHandlerDataFactoryWrapperInterface $data_factory_wrapper;
53
54 public function __construct(
55 ilExportHandlerFactoryInterface $export_handler,
59 ilExportHandlerDataFactoryWrapperInterface $data_factory_wrapper
60 ) {
61 $this->export_handler = $export_handler;
62 $this->obj_definition = $obj_definition;
63 $this->tree = $tree;
64 $this->access = $access;
65 $this->data_factory_wrapper = $data_factory_wrapper;
66 }
67
68 protected function getExportTargetWithObject(
69 ilObject $export_object
70 ) {
71 $obj_id = $export_object->getId();
72 $type = $export_object->getType();
73 $class = ilImportExportFactory::getExporterClass($type);
74 $comp = ilImportExportFactory::getComponentForExport($type);
75 $v = explode(".", ILIAS_VERSION_NUMERIC);
76 $target_release = $v[0] . "." . $v[1] . ".0";
77 return $this->export_handler->target()->handler()
78 ->withTargetRelease($target_release)
79 ->withType($type)
80 ->withObjectIds([$obj_id])
81 ->withClassname($class)
82 ->withComponent($comp);
83 }
84
85 protected function getExportTarget(
86 ObjectId $object_id
87 ): ilExportHandlerTargetInterface {
88 $obj_id = $object_id->toInt();
89 $type = ilObject::_lookupType($obj_id);
90 $class = ilImportExportFactory::getExporterClass($type);
91 $comp = ilImportExportFactory::getComponentForExport($type);
92 $v = explode(".", ILIAS_VERSION_NUMERIC);
93 $target_release = $v[0] . "." . $v[1] . ".0";
94 return $this->export_handler->target()->handler()
95 ->withTargetRelease($target_release)
96 ->withType($type)
97 ->withObjectIds([$obj_id])
98 ->withClassname($class)
99 ->withComponent($comp);
100 }
101
102 protected function writeToElement(
103 string $path_in_container,
104 ilExportHandlerExportInfo $export_info,
105 ilExportHandlerRepositoryElementInterface $element
106 ): void {
107 $export_info = $export_info->withCurrentElement($element);
108 $manifest = $this->export_handler->part()->manifest()->handler()
109 ->withInfo($export_info);
110 $element->getIRSS()->write(
111 Streams::ofString($manifest->getXML(false)),
112 $path_in_container . DIRECTORY_SEPARATOR . $export_info->getExportFolderName() . DIRECTORY_SEPARATOR . "manifest.xml"
113 );
114 foreach ($export_info->getComponentInfos() as $component_info) {
115 $component = $this->export_handler->part()->component()->handler()
116 ->withExportInfo($export_info)
117 ->withComponentInfo($component_info);
118 $element->getIRSS()->write(
119 Streams::ofString($component->getXML(false)),
120 $path_in_container . DIRECTORY_SEPARATOR . $component_info->getExportFilePathInContainer()
121 );
122 }
123 }
124
125 public function createContainerExport(
126 int $user_id,
127 ilExportHandlerContainerExportInfoInterface $container_export_info,
128 ): ilExportHandlerRepositoryElementInterface {
129 $main_export_info = $container_export_info->getMainEntityExportInfo();
130 $main_element = $this->createExport(
131 $user_id,
132 $main_export_info,
133 "set_" . $main_export_info->getSetNumber()
134 );
135 $repository = $this->export_handler->repository();
136 foreach ($container_export_info->getExportInfos() as $export_info) {
137 $stream = null;
138 $keys = $repository->key()->collection()
139 ->withElement($repository->key()->handler()->withObjectId($export_info->getTargetObjectId()));
140 $element = $export_info->getReuseExport()
141 ? $this->export_handler->repository()->handler()->getElements($keys)->newest()
142 : $this->createExport($user_id, $export_info, "");
143 $element = $element->getIRSS()->isContainerExport()
144 ? $this->createExport($user_id, $export_info, "")
145 : $element;
146 $stream = $element->getIRSSInfo()->getStream();
147 $zip_reader = new ZipReader($stream);
148 $zip_structure = $zip_reader->getStructure();
149 foreach ($zip_structure as $path_inside_zip => $item) {
150 if ($item['is_dir']) {
151 continue;
152 }
156 $stream = $zip_reader->getItem($path_inside_zip, $zip_structure)[0];
157 # Contents of the stream $stream are lost later (possible incompatible stream object), therefore a new
158 # stream with the content of $stream is created and passed on.
159 $main_element->getIRSS()->write(
160 Streams::ofString($stream->getContents()),
161 "set_" . $export_info->getSetNumber() . DIRECTORY_SEPARATOR . $path_inside_zip
162 );
163 }
164 }
165 $container = $this->export_handler->part()->container()->handler()
166 ->withExportInfos($container_export_info->getExportInfos()->withElementAtHead($main_export_info))
167 ->withMainEntityExportInfo($main_export_info);
168 $main_element->getIRSS()->write(
169 Streams::ofString($container->getXML(false)),
170 "manifest.xml"
171 );
172 return $main_element;
173 }
174
175 public function createExport(
176 int $user_id,
177 ilExportHandlerExportInfoInterface $export_info,
178 string $path_in_container
179 ): ilExportHandlerRepositoryElementInterface {
180 # make legacy export run dir
181 # tmp solution, remove later if no longer needed
182 ilFileUtils::makeDirParents($export_info->getLegacyExportRunDir());
183
184 $stakeholder = $this->export_handler->repository()->stakeholder()->handler()->withOwnerId($user_id);
185 $object_id = $this->data_factory_wrapper->objId($export_info->getTarget()->getObjectIds()[0]);
186 $element = $this->export_handler->repository()->handler()->createElement(
187 $object_id,
188 $export_info,
189 $stakeholder
190 );
191 $this->writeToElement($path_in_container, $export_info, $element);
192
193 # write files from legacy export run dir to irss
194 # tmp solution, remove later if no longer needed
195 $writer = $this->export_handler->consumer()->handler()->exportWriter($element);
196 $writer->writeDirectoryRecursive(
197 $export_info->getLegacyExportRunDir(),
198 $export_info->getExportFolderName()
199 );
200
201 # delete legacy export run dir
202 # tmp solution, remove if no longer needed
203 ilFileUtils::delDir($export_info->getLegacyExportRunDir());
204 return $element;
205 }
206
207 public function createExportOfObject(
208 ilObject $export_object,
209 int $user_id,
210 ExportConfigCollectionInterface $export_configs
211 ): void {
212 $export_info = $this->getExportInfoWithObject(
213 $export_object,
214 time(),
215 $export_configs
216 );
217 $element = $this->createExport(
218 $user_id,
219 $export_info,
220 ""
221 );
222 }
223
224 public function getExportInfo(
225 ObjectId $object_id,
226 int $time_stamp,
227 ExportConfigCollectionInterface $export_configs
228 ): ilExportHandlerExportInfoInterface {
229 return $this->export_handler->info()->export()->handler()
230 ->withTarget($this->getExportTarget($object_id), $time_stamp)
231 ->withExportConfigs($export_configs);
232 }
233
234 public function getExportInfoWithObject(
235 ilObject $export_object,
236 int $time_stamp,
237 ExportConfigCollectionInterface $export_configs
238 ): ilExportHandlerExportInfoInterface {
239 return $this->export_handler->info()->export()->handler()
240 ->withTarget($this->getExportTargetWithObject($export_object), $time_stamp)
241 ->withExportConfigs($export_configs);
242 }
243
244 public function getContainerExportInfo(
245 ObjectId $main_entity_object_id,
246 ilExportHandlerContainerExportInfoObjectIdCollectionInterface $object_ids,
247 ExportConfigCollectionInterface $export_configs
248 ): ilExportHandlerContainerExportInfoInterface {
249 return $this->export_handler->info()->export()->container()->handler()
250 ->withMainExportEntity($main_entity_object_id)
251 ->withObjectIds($object_ids)
252 ->withTimestamp(time())
253 ->withExportConfigs($export_configs);
254 }
255
256 public function getObjectIdCollectioBuilder(): ilExportHandlerContainerExportInfoObjectIdCollectionBuilderInterface
257 {
258 return $this->export_handler->info()->export()->container()->objectId()->collectionBuilder();
259 }
260
262 ReferenceId $container_reference_id,
263 bool $public_access = false
264 ): ilExportHandlerContainerExportInfoObjectIdCollectionBuilderInterface {
265 $id_collection_builder = $this->export_handler->info()->export()->container()->objectId()->collectionBuilder();
266 $tree_nodes = $this->tree->getSubTree($this->tree->getNodeData($container_reference_id->toInt()));
267 foreach ($tree_nodes as $node) {
268 if (
269 $node['type'] == 'rolf' or
270 !$this->obj_definition->allowExport($node['type']) or
271 ($node['type'] == "file" && ilObjFileAccess::_isFileHidden($node['title'])) or
272 !$this->access->checkAccess('write', '', (int) $node['ref_id'])
273 ) {
274 continue;
275 }
276 $reference_id = new ReferenceId((int) $node['ref_id']);
277 $object_id = $reference_id->toObjectId();
278 $keys = $this->export_handler->repository()->key()->collection()->withElement(
279 $this->export_handler->repository()->key()->handler()->withObjectId($object_id)
280 );
281 $elements = $this->export_handler->repository()->handler()->getElements($keys);
282 $create_new_export = (
283 ($public_access and !$this->export_handler->publicAccess()->handler()->hasPublicAccessFile($object_id)) or
284 !$public_access and $elements->count() == 0
285 );
286 $id_collection_builder = $id_collection_builder->addObjectId($object_id, $create_new_export);
287 }
288 return $id_collection_builder;
289 }
290}
ilExportHandlerDataFactoryWrapperInterface $data_factory_wrapper
Definition: Handler.php:52
getExportInfo(ObjectId $object_id, int $time_stamp, ExportConfigCollectionInterface $export_configs)
Definition: Handler.php:224
getContainerExportInfo(ObjectId $main_entity_object_id, ilExportHandlerContainerExportInfoObjectIdCollectionInterface $object_ids, ExportConfigCollectionInterface $export_configs)
Definition: Handler.php:244
getObjectIdCollectionBuilderFrom(ReferenceId $container_reference_id, bool $public_access=false)
Definition: Handler.php:261
createExportOfObject(ilObject $export_object, int $user_id, ExportConfigCollectionInterface $export_configs)
Definition: Handler.php:207
writeToElement(string $path_in_container, ilExportHandlerExportInfo $export_info, ilExportHandlerRepositoryElementInterface $element)
Definition: Handler.php:102
ilExportHandlerFactoryInterface $export_handler
Definition: Handler.php:48
createExport(int $user_id, ilExportHandlerExportInfoInterface $export_info, string $path_in_container)
Definition: Handler.php:175
getExportInfoWithObject(ilObject $export_object, int $time_stamp, ExportConfigCollectionInterface $export_configs)
Definition: Handler.php:234
getExportTarget(ObjectId $object_id)
Definition: Handler.php:85
__construct(ilExportHandlerFactoryInterface $export_handler, ilObjectDefinition $obj_definition, ilTree $tree, ilAccessHandler $access, ilExportHandlerDataFactoryWrapperInterface $data_factory_wrapper)
Definition: Handler.php:54
getExportTargetWithObject(ilObject $export_object)
Definition: Handler.php:68
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41
Class ilFileUtils.
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
Factory for importer/exporter implementers.
Access class for file objects.
static _isFileHidden(string $a_file_name)
Returns true, if a file with the specified name, is usually hidden from the user.
parses the objects.xml it handles the xml-description of all ilias objects
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const ILIAS_VERSION_NUMERIC
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
if(!file_exists('../ilias.ini.php'))
$container
@noRector
Definition: wac.php:37