ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
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 $is_container_export = $element->getIRSS()->isContainerExport();
197 $writer->writeDirectoryRecursive(
198 $export_info->getLegacyExportRunDir(),
199 ($is_container_export) ? '' : $export_info->getExportFolderName()
200 );
201
202 # delete legacy export run dir
203 # tmp solution, remove if no longer needed
204 ilFileUtils::delDir($export_info->getLegacyExportRunDir());
205 return $element;
206 }
207
208 public function createExportOfObject(
209 ilObject $export_object,
210 int $user_id,
211 ExportConfigCollectionInterface $export_configs
212 ): void {
213 $export_info = $this->getExportInfoWithObject(
214 $export_object,
215 time(),
216 $export_configs
217 );
218 $element = $this->createExport(
219 $user_id,
220 $export_info,
221 ""
222 );
223 }
224
225 public function getExportInfo(
226 ObjectId $object_id,
227 int $time_stamp,
228 ExportConfigCollectionInterface $export_configs
229 ): ilExportHandlerExportInfoInterface {
230 return $this->export_handler->info()->export()->handler()
231 ->withTarget($this->getExportTarget($object_id), $time_stamp)
232 ->withExportConfigs($export_configs);
233 }
234
235 public function getExportInfoWithObject(
236 ilObject $export_object,
237 int $time_stamp,
238 ExportConfigCollectionInterface $export_configs
239 ): ilExportHandlerExportInfoInterface {
240 return $this->export_handler->info()->export()->handler()
241 ->withTarget($this->getExportTargetWithObject($export_object), $time_stamp)
242 ->withExportConfigs($export_configs);
243 }
244
245 public function getContainerExportInfo(
246 ObjectId $main_entity_object_id,
247 ilExportHandlerContainerExportInfoObjectIdCollectionInterface $object_ids,
248 ExportConfigCollectionInterface $export_configs
249 ): ilExportHandlerContainerExportInfoInterface {
250 return $this->export_handler->info()->export()->container()->handler()
251 ->withMainExportEntity($main_entity_object_id)
252 ->withObjectIds($object_ids)
253 ->withTimestamp(time())
254 ->withExportConfigs($export_configs);
255 }
256
257 public function getObjectIdCollectioBuilder(): ilExportHandlerContainerExportInfoObjectIdCollectionBuilderInterface
258 {
259 return $this->export_handler->info()->export()->container()->objectId()->collectionBuilder();
260 }
261
263 ReferenceId $container_reference_id,
264 bool $public_access = false
265 ): ilExportHandlerContainerExportInfoObjectIdCollectionBuilderInterface {
266 $id_collection_builder = $this->export_handler->info()->export()->container()->objectId()->collectionBuilder();
267 $tree_nodes = $this->tree->getSubTree($this->tree->getNodeData($container_reference_id->toInt()));
268 foreach ($tree_nodes as $node) {
269 if (
270 $node['type'] == 'rolf' or
271 !$this->obj_definition->allowExport($node['type']) or
272 ($node['type'] == "file" && ilObjFileAccess::_isFileHidden($node['title'])) or
273 !$this->access->checkAccess('write', '', (int) $node['ref_id'])
274 ) {
275 continue;
276 }
277 $reference_id = new ReferenceId((int) $node['ref_id']);
278 $object_id = $reference_id->toObjectId();
279 $keys = $this->export_handler->repository()->key()->collection()->withElement(
280 $this->export_handler->repository()->key()->handler()->withObjectId($object_id)
281 );
282 $elements = $this->export_handler->repository()->handler()->getElements($keys);
283 $create_new_export = (
284 ($public_access and !$this->export_handler->publicAccess()->handler()->hasPublicAccessFile($object_id)) or
285 !$public_access and $elements->count() == 0
286 );
287 $id_collection_builder = $id_collection_builder->addObjectId($object_id, $create_new_export);
288 }
289 return $id_collection_builder;
290 }
291}
ilExportHandlerDataFactoryWrapperInterface $data_factory_wrapper
Definition: Handler.php:52
getExportInfo(ObjectId $object_id, int $time_stamp, ExportConfigCollectionInterface $export_configs)
Definition: Handler.php:225
getContainerExportInfo(ObjectId $main_entity_object_id, ilExportHandlerContainerExportInfoObjectIdCollectionInterface $object_ids, ExportConfigCollectionInterface $export_configs)
Definition: Handler.php:245
getObjectIdCollectionBuilderFrom(ReferenceId $container_reference_id, bool $public_access=false)
Definition: Handler.php:262
createExportOfObject(ilObject $export_object, int $user_id, ExportConfigCollectionInterface $export_configs)
Definition: Handler.php:208
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:235
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['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const ILIAS_VERSION_NUMERIC
Combines all available interfaces which can be called via global $ilAccess.
if(!file_exists('../ilias.ini.php'))
$container
@noRector
Definition: wac.php:39