ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilObjFileAbstractZipDelegate Class Reference

Class ilObjFileAbstractZipDelegate. More...

+ Inheritance diagram for ilObjFileAbstractZipDelegate:
+ Collaboration diagram for ilObjFileAbstractZipDelegate:

Public Member Functions

 __construct (object $access_checker, int $node_type, ilTree $tree)
 ilObjFileAbstractZipDelegate constructor. More...
 
 getUploadedSuffixes ()
 
- Public Member Functions inherited from ilObjUploadDelegateInterface
 handle (int $parent_id, array $post_data, UploadResult $result, ilObjFileGUI $gui)
 

Protected Member Functions

 createSurroundingContainer (UploadResult $result, int $parent_id)
 
 tearDown ()
 
 initZip (UploadResult $result)
 
 isInWorkspace ()
 
 createContainer (string $original_path, int $parent_id)
 
 createFile (string $original_path, int $parent_id)
 
 getNextPath ()
 
 hasMultipleRootEntriesInZip ()
 

Protected Attributes

 $access_handler
 
 $node_type
 
 $tree
 
 $path_map = []
 
 $zip
 
 $uploaded_suffixes = []
 
 $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...
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilObjFileAbstractZipDelegate::__construct ( object  $access_checker,
int  $node_type,
ilTree  $tree 
)

ilObjFileAbstractZipDelegate constructor.

Parameters
ilAccess | ilWorkspaceAccessHandler$access_checker
int$node_type
ilTree$tree

Definition at line 69 of file class.ilObjFileAbstractZipDelegate.php.

References $node_type, and $tree.

70  {
71  $this->access_handler = $access_checker;
72  $this->node_type = $node_type;
73  $this->tree = $tree;
74  }

Member Function Documentation

◆ createContainer()

ilObjFileAbstractZipDelegate::createContainer ( string  $original_path,
int  $parent_id 
)
protected
Parameters
string$original_path
int$parent_id
Returns
ilObject

Definition at line 113 of file class.ilObjFileAbstractZipDelegate.php.

References $DIC, $lng, and isInWorkspace().

Referenced by createSurroundingContainer(), and ilObjFileUnzipRecursiveDelegate\handle().

113  : ilObject
114  {
115  // Create folder or cat or WorkspaceFolder
116  $obj = $this->getPossibleContainer($parent_id);
117  $obj->setTitle(basename($original_path));
118  $obj->create();
119 
120  if (!$this->isInWorkspace()) {
121  $obj->createReference();
122  $obj->putInTree($parent_id);
123  $obj->setPermissions($parent_id);
124  } else {
125  $node_id = $this->tree->insertObject($parent_id, $obj->getId());
126  $this->access_handler->setPermissions($parent_id, $node_id);
127  $obj->setRefId($node_id);
128  }
129 
130  if ($obj->getType() === "cat") {
131  global $DIC;
132 
133  $lng = $DIC->language();
134  $obj->addTranslation(basename($original_path), "", $lng->getLangKey(), $lng->getLangKey());
135  }
136 
137  return $obj;
138  }
$lng
global $DIC
Definition: goto.php:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createFile()

ilObjFileAbstractZipDelegate::createFile ( string  $original_path,
int  $parent_id 
)
protected
Parameters
string$original_path
int$parent_id
Returns
ilObjFile

Definition at line 146 of file class.ilObjFileAbstractZipDelegate.php.

References isInWorkspace().

Referenced by ilObjFileUnzipFlatDelegate\handle(), and ilObjFileUnzipRecursiveDelegate\handle().

146  : ilObjFile
147  {
148  $obj = new ilObjFile();
149  $obj->setTitle(basename($original_path));
150  $obj->create();
151 
152  $obj->appendStream(Streams::ofString($this->zip->getFromName($original_path)), basename($original_path));
153 
154  if (!$this->isInWorkspace()) {
155  $obj->createReference();
156  $obj->putInTree($parent_id);
157  $obj->setPermissions($parent_id);
158  } else {
159  $node_id = $this->tree->insertObject($parent_id, $obj->getId());
160  $this->access_handler->setPermissions($parent_id, $node_id);
161  $obj->setRefId($node_id);
162  }
163 
164  $this->uploaded_suffixes[] = $obj->getFileExtension();
165 
166  return $obj;
167  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createSurroundingContainer()

ilObjFileAbstractZipDelegate::createSurroundingContainer ( UploadResult  $result,
int  $parent_id 
)
protected

Definition at line 76 of file class.ilObjFileAbstractZipDelegate.php.

References createContainer(), and ILIAS\FileUpload\DTO\UploadResult\getName().

Referenced by ilObjFileUnzipRecursiveDelegate\handle().

76  : int
77  {
78  // create one base container with the name of the zip itself, all other containers will be created inside this one
79  $info = new SplFileInfo($result->getName());
80  $base_path = $info->getBasename("." . $info->getExtension());
81  $base_container = $this->createContainer($base_path, $parent_id);
82 
83  return (int) $base_container->getRefId();
84  }
createContainer(string $original_path, int $parent_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNextPath()

ilObjFileAbstractZipDelegate::getNextPath ( )
protected
Returns
Generator|string[]

Definition at line 172 of file class.ilObjFileAbstractZipDelegate.php.

References $i.

Referenced by ilObjFileUnzipFlatDelegate\handle(), ilObjFileUnzipRecursiveDelegate\handle(), and hasMultipleRootEntriesInZip().

172  : Generator
173  {
174  $paths = [];
175 
176  for ($i = 0; $i < $this->zip->numFiles; $i++) {
177  $original_path = $this->zip->getNameIndex($i, ZipArchive::FL_UNCHANGED);
178  if (strpos($original_path, '__MACOSX') !== false || strpos($original_path, '.DS_') !== false) {
179  continue;
180  }
181  $paths[] = $original_path;
182  }
183 
184  $path_with_root_folders = [];
185 
186  foreach ($paths as $path) {
187  $parent = dirname($path) . '/';
188  if ($parent !== './' && !in_array($parent, $paths)) {
189  $path_with_root_folders[] = $parent;
190  }
191  $path_with_root_folders[] = $path;
192  }
193 
194  $path_with_root_folders = array_unique($path_with_root_folders);
195  sort($path_with_root_folders);
196 
197  yield from $path_with_root_folders;
198  }
$i
Definition: metadata.php:24
+ Here is the caller graph for this function:

◆ getUploadedSuffixes()

ilObjFileAbstractZipDelegate::getUploadedSuffixes ( )

Implements ilObjUploadDelegateInterface.

Definition at line 215 of file class.ilObjFileAbstractZipDelegate.php.

215  : array
216  {
217  return array_map('strtolower', $this->uploaded_suffixes);
218  }

◆ hasMultipleRootEntriesInZip()

ilObjFileAbstractZipDelegate::hasMultipleRootEntriesInZip ( )
protected

Definition at line 200 of file class.ilObjFileAbstractZipDelegate.php.

References getNextPath().

Referenced by ilObjFileUnzipRecursiveDelegate\handle().

200  : bool
201  {
202  $amount = 0;
203  foreach ($this->getNextPath() as $zip_directory) {
204  $dirname = dirname($zip_directory);
205  if ($dirname === '.') {
206  $amount++;
207  }
208  if ($amount > 1) {
209  return true;
210  }
211  }
212  return false;
213  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initZip()

ilObjFileAbstractZipDelegate::initZip ( UploadResult  $result)
protected
Parameters
UploadResult$result

Definition at line 96 of file class.ilObjFileAbstractZipDelegate.php.

References ILIAS\FileUpload\DTO\UploadResult\getPath().

Referenced by ilObjFileUnzipFlatDelegate\handle(), and ilObjFileUnzipRecursiveDelegate\handle().

96  : void
97  {
98  $this->zip = new ZipArchive();
99  $this->zip->open($result->getPath());
100  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isInWorkspace()

ilObjFileAbstractZipDelegate::isInWorkspace ( )
protected

Definition at line 103 of file class.ilObjFileAbstractZipDelegate.php.

References ilObject2GUI\WORKSPACE_NODE_ID.

Referenced by createContainer(), createFile(), ilObjFileUnzipRecursiveDelegate\getPossibleContainer(), and ilObjFileUnzipRecursiveDelegate\handle().

103  : bool
104  {
105  return $this->node_type === ilObjFileGUI::WORKSPACE_NODE_ID;
106  }
+ Here is the caller graph for this function:

◆ tearDown()

ilObjFileAbstractZipDelegate::tearDown ( )
protected

Definition at line 88 of file class.ilObjFileAbstractZipDelegate.php.

Referenced by ilObjFileUnzipFlatDelegate\handle(), and ilObjFileUnzipRecursiveDelegate\handle().

88  : void
89  {
90  $this->zip->close();
91  }
+ Here is the caller graph for this function:

Field Documentation

◆ $access_handler

ilObjFileAbstractZipDelegate::$access_handler
protected

Definition at line 32 of file class.ilObjFileAbstractZipDelegate.php.

◆ $create_base_container_for_multiple_root_entries

ilObjFileAbstractZipDelegate::$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 61 of file class.ilObjFileAbstractZipDelegate.php.

◆ $node_type

ilObjFileAbstractZipDelegate::$node_type
protected

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

Referenced by __construct().

◆ $path_map

ilObjFileAbstractZipDelegate::$path_map = []
protected

Definition at line 44 of file class.ilObjFileAbstractZipDelegate.php.

◆ $tree

ilObjFileAbstractZipDelegate::$tree
protected

Definition at line 40 of file class.ilObjFileAbstractZipDelegate.php.

Referenced by __construct().

◆ $uploaded_suffixes

ilObjFileAbstractZipDelegate::$uploaded_suffixes = []
protected

Definition at line 52 of file class.ilObjFileAbstractZipDelegate.php.

◆ $zip

ilObjFileAbstractZipDelegate::$zip
protected

Definition at line 48 of file class.ilObjFileAbstractZipDelegate.php.


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