ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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
 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.

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

57  {
58  parent::__construct($stakeholder, $gui_object, $storage, $settings);
59 
60  $this->id_type = $gui_object->getIdType();
61  }
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ closeZip()

ilObjFileAbstractZipProcessor::closeZip ( )
protected

Closes the currently open zip-archive.

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

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

216  : void
217  {
218  if ($this->archive instanceof \ZipArchive) {
219  $this->archive->close();
220  }
221  }
+ Here is the caller graph for this function:

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

References getPossibleContainerObj().

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

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.
+ 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.

References createContainerObj().

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

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.
+ 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.

Returns
ilObject

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

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

Referenced by createContainerObj().

236  : ilObject
237  {
238  $type = ($this->isWorkspace()) ?
239  ilObject::_lookupType($this->tree->lookupObjectId($parent_id)) :
240  ilObject::_lookupType($parent_id, true);
241 
242  return match ($type) {
243  'wfld', 'wsrt' => new ilObjWorkspaceFolder(),
244  'cat', 'root' => new ilObjCategory(),
245  default => new ilObjFolder(),
246  };
247  }
Class ilObjFolder.
isWorkspace()
Returns whether the current context is workspace.
Class ilObjCategory.
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)
+ 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.

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

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

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  }
180  }
181 
182  $directories_with_parents = [];
183 
184  foreach ($directories as $directory) {
185  $parent = dirname($directory) . '/';
186  if ($parent !== './' && !in_array($parent, $directories)) {
187  $directories_with_parents[] = $parent;
188  }
189  $directories_with_parents[] = $directory;
190  }
191 
192  $directories_with_parents = array_unique($directories_with_parents);
193  sort($directories_with_parents);
194  yield from $directories_with_parents;
195  }
sort()
description: > Example for rendering a Sort Glyph.
Definition: sort.php:41
$path
Definition: ltiservices.php:29
getZipPaths()
Yields all paths of the currently open zip-archive (without some macos stuff).
+ 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.

References $path, and getZipPaths().

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

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  }
$path
Definition: ltiservices.php:29
getZipPaths()
Yields all paths of the currently open zip-archive (without some macos stuff).
+ 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.

References $path.

Referenced by getZipDirectories(), and getZipFiles().

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  }
$path
Definition: ltiservices.php:29
+ Here is the caller graph for this function:

◆ hasMultipleRootEntriesInZip()

ilObjFileAbstractZipProcessor::hasMultipleRootEntriesInZip ( )
protected

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

References getZipDirectories(), and getZipFiles().

Referenced by ilObjFileUnzipRecursiveProcessor\process().

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  }
getZipFiles()
Yields the file-paths of the currently open zip-archive.
getZipDirectories()
Yields the directory-paths of the currently open zip-archive.
+ 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 226 of file class.ilObjFileAbstractZipProcessor.php.

References ilObject2GUI\WORKSPACE_NODE_ID.

Referenced by getPossibleContainerObj().

226  : bool
227  {
228  return (ilObject2GUI::WORKSPACE_NODE_ID === $this->id_type);
229  }
+ 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.

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

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

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

201  {
202  if (!$this->archive instanceof \ZipArchive) {
203  throw new LogicException("No archive has been opened yet, call openZip() first in order to read files.");
204  }
205 
206  return $this->storage->manage()->stream(
207  Streams::ofString($this->archive->getFromName($file_path)),
208  $this->stakeholder,
209  basename($file_path)
210  );
211  }
+ Here is the caller graph for this function:

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

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: