ILIAS  release_8 Revision v8.24
ilCollectFilesJob Class Reference

Description of class class. More...

+ Inheritance diagram for ilCollectFilesJob:
+ Collaboration diagram for ilCollectFilesJob:

Public Member Functions

 __construct ()
 Construct. More...
 
 getInputTypes ()
 @inheritDoc More...
 
 getOutputType ()
 @inheritDoc More...
 
 isStateless ()
 @inheritDoc More...
 
 run (array $input, \ILIAS\BackgroundTasks\Observer $observer)
 @inheritDoc More...
 
 getExpectedTimeOfTaskInSeconds ()
 
Returns
int the amount of seconds this task usually taskes. If your task-duration scales with the the amount of data, try to set a possible high value of try to calculate it. If a task duration exceeds this value, it will be displayed as "possibly failed" to the user
More...
 
- Public Member Functions inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractJob
 getInput ()
 
Returns
Value[]
More...
 
- Public Member Functions inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask
 setInput (array $values)
 
 getOutput ()
 
 getInput ()
 
 getType ()
 
 unfoldTask ()
 Unfold the task. More...
 
 getRemoveOption ()
 
Returns
Option An Option to remove the current task and do some cleanup if possible. This Option is displayed if the Bucket is completed. You do not have to provide an additional Option to remove in your UserInteraction, the remove-Option is added to the list of Options (last position)
See also
self::getAbortOption();
More...
 
 getAbortOption ()
 
Returns
Option In case a Job is failed or did not respond for some time, an Abort-Option is displayed. There is already a Standard-Abort-Option registered, you can override with your own and do some cleanup if possible.
More...
 
 getType ()
 
 getInputTypes ()
 
 getOutputType ()
 
 getOutput ()
 
 setInput (array $values)
 
 getInput ()
 
 unfoldTask ()
 
 getRemoveOption ()
 
 getAbortOption ()
 
- Public Member Functions inherited from ILIAS\BackgroundTasks\Task\Job
 run (array $input, Observer $observer)
 
 isStateless ()
 
 getInput ()
 
 getExpectedTimeOfTaskInSeconds ()
 

Static Private Member Functions

static getFileDirs ($a_ref_id, $a_file_name, $a_temp_dir)
 
static recurseFolder ($a_ref_id, $a_folder_name, $a_temp_dir, $a_num_recursions, $a_initiated_by_folder_action)
 

Private Attributes

ilLogger $logger
 

Static Private Attributes

static array $targets = []
 

Additional Inherited Members

- Data Fields inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask
const MAIN_REMOVE = 'bt_main_remove'
 
const MAIN_ABORT = 'bt_main_abort'
 
- Protected Member Functions inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask
 checkTypes ($values)
 
 extractType ($value)
 
- Protected Attributes inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask
array $input = []
 
ILIAS BackgroundTasks Value $output
 

Detailed Description

Description of class class.

Author
Lukas Zehnder lz@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 30 of file class.ilCollectFilesJob.php.

Constructor & Destructor Documentation

◆ __construct()

ilCollectFilesJob::__construct ( )

Construct.

Definition at line 43 of file class.ilCollectFilesJob.php.

44 {
45 global $DIC;
46 $this->logger = $DIC->logger()->cal();
47 }
global $DIC
Definition: feed.php:28

References $DIC, and ILIAS\Repository\logger().

+ Here is the call graph for this function:

Member Function Documentation

◆ getExpectedTimeOfTaskInSeconds()

ilCollectFilesJob::getExpectedTimeOfTaskInSeconds ( )

Returns
int the amount of seconds this task usually taskes. If your task-duration scales with the the amount of data, try to set a possible high value of try to calculate it. If a task duration exceeds this value, it will be displayed as "possibly failed" to the user

Implements ILIAS\BackgroundTasks\Task\Job.

Definition at line 232 of file class.ilCollectFilesJob.php.

232 : int
233 {
234 return 30;
235 }

◆ getFileDirs()

static ilCollectFilesJob::getFileDirs (   $a_ref_id,
  $a_file_name,
  $a_temp_dir 
)
staticprivate
Returns
bool|array<string, string> Please note that this method must only be called ONCE in order to detect duplicate entries. DO NOT call this method e.g. in an if condition and then again in its body.

Definition at line 139 of file class.ilCollectFilesJob.php.

140 {
141 global $DIC;
142
143 $user = $DIC->user();
144 $ilAccess = $DIC->access();
145 if ($ilAccess->checkAccessOfUser($user->getId(), "read", "", $a_ref_id)) {
146 $file = new ilObjFile($a_ref_id);
147 $source_dir = $file->getFile();
148 if (@!is_file($source_dir)) {
149 return false;
150 }
151 $target_dir = $a_temp_dir . '/' . ilFileUtils::getASCIIFilename($a_file_name);
152
153 // #25025: allow duplicate filenames by appending an incrementing
154 // number per duplicate in brackets to the name.
155 // Example: test.txt, test (1).txt, test (2).txt, ...
156 if (isset(self::$targets[$target_dir])) {
157 $target_info = pathinfo($target_dir);
158 $filename = $target_info["filename"];
159 $extension = isset($target_info["extension"]) ? "." . $target_info["extension"] : "";
160 $target_dir = $a_temp_dir . $filename . " (" . ++self::$targets[$target_dir] . ")" . $extension;
161 } else {
162 self::$targets[$target_dir] = 0;
163 }
164
165 return [
166 "source_dir" => $source_dir,
167 "target_dir" => $target_dir,
168 ];
169 }
170
171 return false;
172 }
$filename
Definition: buildRTE.php:78
static getASCIIFilename(string $a_filename)
Class ilObjFile.

References $DIC, $filename, and ilFileUtils\getASCIIFilename().

+ Here is the call graph for this function:

◆ getInputTypes()

ilCollectFilesJob::getInputTypes ( )

@inheritDoc

Implements ILIAS\BackgroundTasks\Task.

Definition at line 53 of file class.ilCollectFilesJob.php.

53 : array
54 {
55 return
56 [
57 new SingleType(ilCopyDefinition::class),
58 new SingleType(BooleanValue::class),
59 ];
60 }

◆ getOutputType()

ilCollectFilesJob::getOutputType ( )

@inheritDoc

Implements ILIAS\BackgroundTasks\Task.

Definition at line 66 of file class.ilCollectFilesJob.php.

66 : Type
67 {
68 return new SingleType(ilCopyDefinition::class);
69 }

◆ isStateless()

ilCollectFilesJob::isStateless ( )

@inheritDoc

Implements ILIAS\BackgroundTasks\Task\Job.

Definition at line 75 of file class.ilCollectFilesJob.php.

75 : bool
76 {
77 return true;
78 }

◆ recurseFolder()

static ilCollectFilesJob::recurseFolder (   $a_ref_id,
  $a_folder_name,
  $a_temp_dir,
  $a_num_recursions,
  $a_initiated_by_folder_action 
)
staticprivate
Parameters
$ref_id
$title
$tmpdir
Returns
mixed[]

Definition at line 182 of file class.ilCollectFilesJob.php.

182 : array
183 {
184 global $DIC;
185
186 $num_recursions = $a_num_recursions + 1;
187 $tree = $DIC->repositoryTree();
188 $ilAccess = $DIC->access();
189 $files = array();
190
191 // Avoid the duplication of the uppermost folder when the download is initiated via a folder's action drop-down
192 // by not including said folders name in the temp_dir path.
193 if ($num_recursions <= 1 && $a_initiated_by_folder_action) {
194 $temp_dir = $a_temp_dir;
195 } else {
196 $temp_dir = $a_temp_dir . '/' . ilFileUtils::getASCIIFilename($a_folder_name);
197 }
198
199 $subtree = $tree->getChildsByTypeFilter($a_ref_id, array("fold", "file"));
200
201 foreach ($subtree as $child) {
202 if (!$ilAccess->checkAccess("read", "", $child["ref_id"])) {
203 continue;
204 }
205 if (ilObject::_isInTrash($child["ref_id"])) {
206 continue;
207 }
208 if ($child["type"] == "fold") {
209 $files_from_folder = self::recurseFolder($child["ref_id"], $child['title'], $temp_dir, $num_recursions, $a_initiated_by_folder_action);
210 $files = array_merge($files, $files_from_folder);
211 } else {
212 if (($child["type"] == "file") && (($dirs = self::getFileDirs($child["ref_id"], $child['title'], $temp_dir)) !== false)) {
213 $files[] = $dirs;
214 }
215 }
216 }
217 // ensure that empty folders are also contained in the downloaded zip
218 if (empty($subtree)) {
219 $files[] = [
220 "source_dir" => "",
221 "target_dir" => $temp_dir . '/',
222 ];
223 }
224
225 return $files;
226 }
static recurseFolder($a_ref_id, $a_folder_name, $a_temp_dir, $a_num_recursions, $a_initiated_by_folder_action)
static _isInTrash(int $ref_id)

References $DIC, ilObject\_isInTrash(), ilFileUtils\getASCIIFilename(), and recurseFolder().

Referenced by recurseFolder(), and run().

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

◆ run()

ilCollectFilesJob::run ( array  $input,
\ILIAS\BackgroundTasks\Observer  $observer 
)

@inheritDoc

Todo:
use filsystem service

Definition at line 85 of file class.ilCollectFilesJob.php.

85 : Value
86 {
87 $this->logger->debug('Start collecting files!');
88 $this->logger->dump($input);
89 $definition = $input[0];
90 $initiated_by_folder_action = $input[1]->getValue();
91 $object_ref_ids = $definition->getObjectRefIds();
92 $files = array();
93
94 foreach ($object_ref_ids as $object_ref_id) {
95 $object = ilObjectFactory::getInstanceByRefId($object_ref_id);
96 $object_type = $object->getType();
97 $object_name = $object->getTitle();
98 $object_temp_dir = ""; // empty as content will be added in recurseFolder and getFileDirs
99
100 if ($object_type == "fold") {
101 $num_recursions = 0;
102 $files_from_folder = self::recurseFolder($object_ref_id, $object_name, $object_temp_dir, $num_recursions, $initiated_by_folder_action);
103 $files = array_merge($files, $files_from_folder);
104 } elseif (($object_type == "file") && (($file_dirs = self::getFileDirs(
105 $object_ref_id,
106 $object_name,
107 $object_temp_dir
108 )) !== false)) {
109 $files[] = $file_dirs;
110 }
111 }
112 $this->logger->debug('Collected files:');
113 $this->logger->dump($files);
114
115 $num_files = 0;
116 foreach ($files as $file) {
117 $definition->addCopyDefinition($file['source_dir'], $file['target_dir']);
118 $this->logger->debug('Added new copy definition: ' . $file['source_dir'] . ' -> ' . $file['target_dir']);
119
120 // count files only (without empty directories)
121 $is_empty_folder = preg_match_all("/\/$/", $file['target_dir']);
122 if (!$is_empty_folder) {
123 $num_files++;
124 }
125 }
126 $definition->setObjectRefIds($object_ref_ids);
127 $definition->setNumFiles($num_files);
128
129 return $definition;
130 }
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id

References ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask\$input, ilObjectFactory\getInstanceByRefId(), ILIAS\Repository\logger(), and recurseFolder().

+ Here is the call graph for this function:

Field Documentation

◆ $logger

ilLogger ilCollectFilesJob::$logger
private

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

◆ $targets

array ilCollectFilesJob::$targets = []
staticprivate

Definition at line 38 of file class.ilCollectFilesJob.php.


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