ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilObjFileAbstractZipProcessor Class Reference

Class ilObjFileAbstractZipProcessor. More...

+ Inheritance diagram for ilObjFileAbstractZipProcessor:
+ Collaboration diagram for ilObjFileAbstractZipProcessor:

Public Member Functions

 __construct (ResourceStakeholder $stakeholder, ilObjFileGUI $gui_object, Services $storage, ilFileServicesSettings $settings, private $tree)
 
- Public Member Functions inherited from ilObjFileAbstractProcessor
 __construct (protected ResourceStakeholder $stakeholder, protected ilObjFileGUI $gui_object, protected Services $storage, protected ilFileServicesSettings $settings)
 
 getInvalidFileNames ()
 
- Public Member Functions inherited from ilObjFileProcessorInterface
 process (ResourceIdentification $rid, ?string $title=null, ?string $description=null, ?string $copyright_id=null)
 Processes a given resource for the given arguments. More...
 

Protected Member Functions

 createSurroundingContainer (ResourceIdentification $rid)
 
 createContainerObj (string $dir_name, int $parent_id)
 Creates a container object depending on the parent's node type and returns it. More...
 
 openZip (ResourceIdentification $rid)
 Opens the zip archive of the given resource. More...
 
 getZipFiles ()
 Yields the file-paths of the currently open zip-archive. More...
 
 hasMultipleRootEntriesInZip ()
 
 getZipDirectories ()
 Yields the directory-paths of the currently open zip-archive. More...
 
 storeZippedFile (string $file_path)
 Creates an IRSS resource from the given filepath. More...
 
 closeZip ()
 Closes the currently open zip-archive. More...
 
 isWorkspace ()
 Returns whether the current context is workspace. More...
 
- Protected Member Functions inherited from ilObjFileAbstractProcessor
 createFileObj (ResourceIdentification $rid, int $parent_id, ?string $title=null, ?string $description=null, ?string $copyright_id=null, bool $create_reference=false)
 Creates an ilObjFile instance for the provided information. More...
 

Protected Attributes

bool $create_base_container_for_multiple_root_entries = false
 @description Unzip on operating systems may behave differently when unzipping if there are only one or more root nodes in the zip. More...
 
- Protected Attributes inherited from ilObjFileAbstractProcessor
ilFileServicesPolicy $policy
 
ilCountPDFPages $page_counter
 
array $invalid_file_names = []
 

Private Member Functions

 getZipPaths ()
 Yields all paths of the currently open zip-archive (without some macos stuff). More...
 
 getPossibleContainerObj (int $parent_id)
 Returns a container object that is possible for the given parent. More...
 

Private Attributes

const IRSS_FILEPATH_KEY = 'uri'
 
ZipArchive $archive = null
 
int $id_type
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilObjFileAbstractZipProcessor::__construct ( ResourceStakeholder  $stakeholder,
ilObjFileGUI  $gui_object,
Services  $storage,
ilFileServicesSettings  $settings,
private  $tree 
)
Parameters
ilTree | ilWorkspaceTree$tree

Definition at line 51 of file class.ilObjFileAbstractZipProcessor.php.

57 {
58 parent::__construct($stakeholder, $gui_object, $storage, $settings);
59
60 $this->id_type = $gui_object->getIdType();
61 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\GlobalScreen\Provider\__construct(), and ilObject2GUI\getIdType().

+ Here is the call graph for this function:

Member Function Documentation

◆ closeZip()

ilObjFileAbstractZipProcessor::closeZip ( )
protected

Closes the currently open zip-archive.

Definition at line 223 of file class.ilObjFileAbstractZipProcessor.php.

223 : void
224 {
225 if ($this->archive instanceof \ZipArchive) {
226 $this->archive->close();
227 }
228 }

◆ createContainerObj()

ilObjFileAbstractZipProcessor::createContainerObj ( string  $dir_name,
int  $parent_id 
)
protected

Creates a container object depending on the parent's node type and returns it.

Definition at line 77 of file class.ilObjFileAbstractZipProcessor.php.

77 : ilObject
78 {
79 $container_obj = $this->getPossibleContainerObj($parent_id);
80 $container_obj->setTitle($dir_name);
81
82 $container_obj->create();
83 $container_obj->createReference();
84
85 $this->gui_object->putObjectInTree($container_obj, $parent_id);
86
87 return $container_obj;
88 }
getPossibleContainerObj(int $parent_id)
Returns a container object that is possible for the given parent.
Class ilObject Basic functions for all objects.

References getPossibleContainerObj().

Referenced by createSurroundingContainer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createSurroundingContainer()

ilObjFileAbstractZipProcessor::createSurroundingContainer ( ResourceIdentification  $rid)
protected

Definition at line 63 of file class.ilObjFileAbstractZipProcessor.php.

63 : int
64 {
65 // create one base container with the name of the zip itself, all other containers will be created inside this one
66 $zip_name = $this->storage->manage()->getCurrentRevision($rid)->getInformation()->getTitle();
67 $info = new SplFileInfo($zip_name);
68 $base_path = $info->getBasename("." . $info->getExtension());
69 $base_container = $this->createContainerObj($base_path, $this->gui_object->getParentId());
70
71 return (int) $base_container->getRefId();
72 }
createContainerObj(string $dir_name, int $parent_id)
Creates a container object depending on the parent's node type and returns it.
$info
Definition: entry_point.php:21

References $info, and createContainerObj().

Referenced by ilObjFileUnzipRecursiveProcessor\process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPossibleContainerObj()

ilObjFileAbstractZipProcessor::getPossibleContainerObj ( int  $parent_id)
private

Returns a container object that is possible for the given parent.

Definition at line 241 of file class.ilObjFileAbstractZipProcessor.php.

241 : ilObject
242 {
243 $type = ($this->isWorkspace()) ?
244 ilObject::_lookupType($this->tree->lookupObjectId($parent_id)) :
245 ilObject::_lookupType($parent_id, true);
246
247 return match ($type) {
248 'wfld', 'wsrt' => new ilObjWorkspaceFolder(),
249 'cat', 'root' => new ilObjCategory(),
250 default => new ilObjFolder(),
251 };
252 }
Class ilObjCategory.
isWorkspace()
Returns whether the current context is workspace.
Class ilObjFolder.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupType(int $id, bool $reference=false)

References ilObject\_lookupType(), and isWorkspace().

Referenced by createContainerObj().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getZipDirectories()

ilObjFileAbstractZipProcessor::getZipDirectories ( )
protected

Yields the directory-paths of the currently open zip-archive.

This fixes the issue that win and mac zip archives have different directory structures.

Returns
Generator|string[]

Definition at line 173 of file class.ilObjFileAbstractZipProcessor.php.

173 : Generator
174 {
175 $directories = [];
176 foreach ($this->getZipPaths() as $path) {
177 if (str_ends_with($path, "/") || str_ends_with($path, "\\")) {
178 $directories[] = $path;
179 continue;
180 }
181 // add all parent directories of files, too. depending on the OS used to create the zip,
182 // these directories may not be present as explicit directory entries in the zip
183 $dir_name = dirname($path) . '/';
184 if ($dir_name !== './' && $dir_name !== '/' && !in_array($dir_name, $directories, true)) {
185 $directories[] = $dir_name;
186 }
187 }
188
189 $directories_with_parents = [];
190
191 foreach ($directories as $directory) {
192 $parent = dirname($directory) . '/';
193 if ($parent !== './' && !in_array($parent, $directories)) {
194 $directories_with_parents[] = $parent;
195 }
196 $directories_with_parents[] = $directory;
197 }
198
199 $directories_with_parents = array_unique($directories_with_parents);
200 sort($directories_with_parents);
201 yield from $directories_with_parents;
202 }
getZipPaths()
Yields all paths of the currently open zip-archive (without some macos stuff).
$path
Definition: ltiservices.php:30

References $path, ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\from(), getZipPaths(), and ILIAS\UI\examples\Symbol\Glyph\Sort\sort().

Referenced by hasMultipleRootEntriesInZip().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getZipFiles()

ilObjFileAbstractZipProcessor::getZipFiles ( )
protected

Yields the file-paths of the currently open zip-archive.

Returns
Generator|string[]

Definition at line 131 of file class.ilObjFileAbstractZipProcessor.php.

131 : Generator
132 {
133 foreach ($this->getZipPaths() as $path) {
134 if (str_ends_with($path, "/")) {
135 continue;
136 }
137 if (str_ends_with($path, "\\")) {
138 continue;
139 }
140 yield $path;
141 }
142 }

References $path, and getZipPaths().

Referenced by hasMultipleRootEntriesInZip().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getZipPaths()

ilObjFileAbstractZipProcessor::getZipPaths ( )
private

Yields all paths of the currently open zip-archive (without some macos stuff).

Returns
Generator|string[]

Definition at line 108 of file class.ilObjFileAbstractZipProcessor.php.

108 : Generator
109 {
110 if (!$this->archive instanceof \ZipArchive) {
111 throw new LogicException("cannot read content of unopened zip archive");
112 }
113
114 for ($i = 0, $i_max = $this->archive->count(); $i < $i_max; $i++) {
115 $path = $this->archive->getNameIndex($i, ZipArchive::FL_UNCHANGED);
116 if (str_contains($path, '__MACOSX')) {
117 continue;
118 }
119 if (str_contains($path, '.DS_')) {
120 continue;
121 }
122
123 yield $path;
124 }
125 }

References $path.

Referenced by getZipDirectories(), and getZipFiles().

+ Here is the caller graph for this function:

◆ hasMultipleRootEntriesInZip()

ilObjFileAbstractZipProcessor::hasMultipleRootEntriesInZip ( )
protected

Definition at line 144 of file class.ilObjFileAbstractZipProcessor.php.

144 : bool
145 {
146 $amount = 0;
147 foreach ($this->getZipDirectories() as $zip_directory) {
148 $dirname = dirname($zip_directory);
149 if ($dirname === '.') {
150 $amount++;
151 }
152 if ($amount > 1) {
153 return true;
154 }
155 }
156 foreach ($this->getZipFiles() as $zip_file) {
157 $dirname = dirname($zip_file);
158 if ($dirname === '.') {
159 $amount++;
160 }
161 if ($amount > 1) {
162 return true;
163 }
164 }
165 return false;
166 }
getZipDirectories()
Yields the directory-paths of the currently open zip-archive.
getZipFiles()
Yields the file-paths of the currently open zip-archive.

References getZipDirectories(), and getZipFiles().

+ Here is the call graph for this function:

◆ isWorkspace()

ilObjFileAbstractZipProcessor::isWorkspace ( )
protected

Returns whether the current context is workspace.

Definition at line 233 of file class.ilObjFileAbstractZipProcessor.php.

233 : bool
234 {
235 return (ilObject2GUI::WORKSPACE_NODE_ID === $this->id_type);
236 }

References ilObject2GUI\WORKSPACE_NODE_ID.

Referenced by getPossibleContainerObj().

+ Here is the caller graph for this function:

◆ openZip()

ilObjFileAbstractZipProcessor::openZip ( ResourceIdentification  $rid)
protected

Opens the zip archive of the given resource.

Definition at line 93 of file class.ilObjFileAbstractZipProcessor.php.

93 : void
94 {
95 if ($this->archive instanceof \ZipArchive) {
96 throw new LogicException("openZip() can only be called once, yet it was called again.");
97 }
98
99 $file_uri = $this->storage->consume()->stream($rid)->getStream()->getMetadata(self::IRSS_FILEPATH_KEY);
100 $this->archive = new ZipArchive();
101 $this->archive->open($file_uri);
102 }

◆ storeZippedFile()

ilObjFileAbstractZipProcessor::storeZippedFile ( string  $file_path)
protected

Creates an IRSS resource from the given filepath.

Definition at line 207 of file class.ilObjFileAbstractZipProcessor.php.

208 {
209 if (!$this->archive instanceof \ZipArchive) {
210 throw new LogicException("No archive has been opened yet, call openZip() first in order to read files.");
211 }
212
213 return $this->storage->manage()->stream(
214 Streams::ofString($this->archive->getFromName($file_path)),
215 $this->stakeholder,
216 basename($file_path)
217 );
218 }

Field Documentation

◆ $archive

ZipArchive ilObjFileAbstractZipProcessor::$archive = null
private

Definition at line 36 of file class.ilObjFileAbstractZipProcessor.php.

◆ $create_base_container_for_multiple_root_entries

bool ilObjFileAbstractZipProcessor::$create_base_container_for_multiple_root_entries = false
protected

@description Unzip on operating systems may behave differently when unzipping if there are only one or more root nodes in the zip.

Currently, the behavior is the same as in ILIAS 7 and earlier, that in any case the zip structure is checked out directly at the current location in the magazine. If this value is set to true here, another category/folder will be placed around the files and folders of the zip when unpacking if more than one root-node is present. For example, macOS behaves in exactly this way.

Definition at line 46 of file class.ilObjFileAbstractZipProcessor.php.

◆ $id_type

int ilObjFileAbstractZipProcessor::$id_type
private

Definition at line 37 of file class.ilObjFileAbstractZipProcessor.php.

◆ IRSS_FILEPATH_KEY

const ilObjFileAbstractZipProcessor::IRSS_FILEPATH_KEY = 'uri'
private

Definition at line 34 of file class.ilObjFileAbstractZipProcessor.php.


The documentation for this class was generated from the following file: