ILIAS  release_8 Revision v8.24
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, $tree)
 
- Public Member Functions inherited from ilObjFileAbstractProcessor
 __construct (ResourceStakeholder $stakeholder, ilObjFileGUI $gui_object, Services $storage, ilFileServicesSettings $settings)
 
 getInvalidFileNames ()
 
- Public Member Functions inherited from ilObjFileProcessorInterface
 process (ResourceIdentification $rid, array $options=[])
 Processes a given resource for the given arguments. More...
 

Protected Member Functions

 createSurroundingContainer (ResourceIdentification $rid)
 
 createContainerObj (string $dir_name, int $parent_id, array $options=[])
 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, array $options=[], bool $create_reference=false)
 Creates an ilObjFile instance for the provided information. More...
 
 applyOptions (ilObject $obj, array $options)
 Apply provided options to the given object. 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
 
ilFileServicesSettings $settings
 
ilCountPDFPages $page_counter
 
Services $storage
 
ResourceStakeholder $stakeholder
 
ilObjFileGUI $gui_object
 
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'
 
 $tree
 
ZipArchive $archive = null
 
int $id_type
 

Additional Inherited Members

- Data Fields inherited from ilObjFileProcessorInterface
const OPTION_FILENAME = 'title'
 
const OPTION_DESCRIPTION = 'description'
 
const OPTIONS
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilObjFileAbstractZipProcessor::__construct ( ResourceStakeholder  $stakeholder,
ilObjFileGUI  $gui_object,
Services  $storage,
ilFileServicesSettings  $settings,
  $tree 
)

Member Function Documentation

◆ closeZip()

ilObjFileAbstractZipProcessor::closeZip ( )
protected

Closes the currently open zip-archive.

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

220 : void
221 {
222 if ($this->archive !== null) {
223 $this->archive->close();
224 }
225 }

Referenced by ilObjFileUnzipFlatProcessor\process(), and ilObjFileUnzipRecursiveProcessor\process().

+ Here is the caller graph for this function:

◆ createContainerObj()

ilObjFileAbstractZipProcessor::createContainerObj ( string  $dir_name,
int  $parent_id,
array  $options = [] 
)
protected

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

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

83 : ilObject
84 {
85 $container_obj = $this->getPossibleContainerObj($parent_id);
86 $container_obj->setTitle($dir_name);
87
88 if (!empty($options)) {
89 $this->applyOptions($container_obj, $options);
90 }
91
92 $container_obj->create();
93 $container_obj->createReference();
94
95 $this->gui_object->putObjectInTree($container_obj, $parent_id);
96
97 return $container_obj;
98 }
applyOptions(ilObject $obj, array $options)
Apply provided options to the given object.
getPossibleContainerObj(int $parent_id)
Returns a container object that is possible for the given parent.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References ilObjFileAbstractProcessor\applyOptions(), and getPossibleContainerObj().

Referenced by createSurroundingContainer(), and ilObjFileUnzipRecursiveProcessor\process().

+ 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 69 of file class.ilObjFileAbstractZipProcessor.php.

69 : int
70 {
71 // create one base container with the name of the zip itself, all other containers will be created inside this one
72 $zip_name = $this->storage->manage()->getCurrentRevision($rid)->getInformation()->getTitle();
73 $info = new SplFileInfo($zip_name);
74 $base_path = $info->getBasename("." . $info->getExtension());
75 $base_container = $this->createContainerObj($base_path, $this->gui_object->getParentId());
76
77 return (int) $base_container->getRefId();
78 }
createContainerObj(string $dir_name, int $parent_id, array $options=[])
Creates a container object depending on the parent's node type and returns it.

References createContainerObj().

Referenced by ilObjFileUnzipFlatProcessor\process(), and 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.

Parameters
int$parent_id
Returns
ilObject

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
248 switch ($type) {
249 case 'wfld':
250 case 'wsrt':
251 return new ilObjWorkspaceFolder();
252
253 case 'cat':
254 case 'root':
255 return new ilObjCategory();
256
257 case 'fold':
258 case 'crs':
259
260 default:
261 return new ilObjFolder();
262 }
263 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isWorkspace()
Returns whether the current context is workspace.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
$type

References $type, 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 176 of file class.ilObjFileAbstractZipProcessor.php.

176 : Generator
177 {
178 $directories = [];
179 foreach ($this->getZipPaths() as $path) {
180 if (substr($path, -1) === "/" || substr($path, -1) === "\\") {
181 $directories[] = $path;
182 }
183 }
184
185 $directories_with_parents = [];
186
187 foreach ($directories as $directory) {
188 $parent = dirname($directory) . '/';
189 if ($parent !== './' && !in_array($parent, $directories)) {
190 $directories_with_parents[] = $parent;
191 }
192 $directories_with_parents[] = $directory;
193 }
194
195 $directories_with_parents = array_unique($directories_with_parents);
196 sort($directories_with_parents);
197 yield from $directories_with_parents;
198 }
getZipPaths()
Yields all paths of the currently open zip-archive (without some macos stuff).
$path
Definition: ltiservices.php:32

References $path, and getZipPaths().

Referenced by hasMultipleRootEntriesInZip(), and ilObjFileUnzipRecursiveProcessor\process().

+ 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 138 of file class.ilObjFileAbstractZipProcessor.php.

138 : Generator
139 {
140 foreach ($this->getZipPaths() as $path) {
141 if (substr($path, -1) !== "/" && substr($path, -1) !== "\\") {
142 yield $path;
143 }
144 }
145 }

References $path, and getZipPaths().

Referenced by hasMultipleRootEntriesInZip(), ilObjFileUnzipFlatProcessor\process(), and ilObjFileUnzipRecursiveProcessor\process().

+ 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 118 of file class.ilObjFileAbstractZipProcessor.php.

118 : Generator
119 {
120 if (null === $this->archive) {
121 throw new LogicException("cannot read content of unopened zip archive");
122 }
123
124 for ($i = 0, $i_max = $this->archive->count(); $i < $i_max; $i++) {
125 $path = $this->archive->getNameIndex($i, ZipArchive::FL_UNCHANGED);
126 if (strpos($path, '__MACOSX') !== false || strpos($path, '.DS_') !== false) {
127 continue;
128 }
129
130 yield $path;
131 }
132 }
$i
Definition: metadata.php:41

References $i, and $path.

Referenced by getZipDirectories(), and getZipFiles().

+ Here is the caller graph for this function:

◆ hasMultipleRootEntriesInZip()

ilObjFileAbstractZipProcessor::hasMultipleRootEntriesInZip ( )
protected

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

147 : bool
148 {
149 $amount = 0;
150 foreach ($this->getZipDirectories() as $zip_directory) {
151 $dirname = dirname($zip_directory);
152 if ($dirname === '.') {
153 $amount++;
154 }
155 if ($amount > 1) {
156 return true;
157 }
158 }
159 foreach ($this->getZipFiles() as $zip_file) {
160 $dirname = dirname($zip_file);
161 if ($dirname === '.') {
162 $amount++;
163 }
164 if ($amount > 1) {
165 return true;
166 }
167 }
168 return false;
169 }
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().

Referenced by ilObjFileUnzipRecursiveProcessor\process().

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

◆ isWorkspace()

ilObjFileAbstractZipProcessor::isWorkspace ( )
protected

Returns whether the current context is workspace.

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

230 : bool
231 {
232 return (ilObject2GUI::WORKSPACE_NODE_ID === $this->id_type);
233 }

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 103 of file class.ilObjFileAbstractZipProcessor.php.

103 : void
104 {
105 if (null !== $this->archive) {
106 throw new LogicException("openZip() can only be called once, yet it was called again.");
107 }
108
109 $file_uri = $this->storage->consume()->stream($rid)->getStream()->getMetadata(self::IRSS_FILEPATH_KEY);
110 $this->archive = new ZipArchive();
111 $this->archive->open($file_uri);
112 }

Referenced by ilObjFileUnzipFlatProcessor\process(), and ilObjFileUnzipRecursiveProcessor\process().

+ Here is the caller graph for this function:

◆ storeZippedFile()

ilObjFileAbstractZipProcessor::storeZippedFile ( string  $file_path)
protected

Creates an IRSS resource from the given filepath.

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

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

Referenced by ilObjFileUnzipFlatProcessor\process(), and ilObjFileUnzipRecursiveProcessor\process().

+ Here is the caller graph for this function:

Field Documentation

◆ $archive

ZipArchive ilObjFileAbstractZipProcessor::$archive = null
private

Definition at line 41 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 51 of file class.ilObjFileAbstractZipProcessor.php.

◆ $id_type

int ilObjFileAbstractZipProcessor::$id_type
private

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

◆ $tree

ilObjFileAbstractZipProcessor::$tree
private

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

Referenced by __construct().

◆ 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: