ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilCollectFilesJob Class Reference

Description of class class. More...

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

Public Member Functions

 __construct ()
 Construct. More...
 
 getInputTypes ()
 
 getOutputType ()
 
 isStateless ()
 
 run (array $input, \ILIAS\BackgroundTasks\Observer $observer)
 
 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
mixed returns the input array
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...
 
- Public Member Functions inherited from ILIAS\BackgroundTasks\Task\Job
 run (array $input, Observer $observer)
 

Static Private Member Functions

static getFileDirs ($a_ref_id, $a_file_name, $a_temp_dir)
 Please note that this method must only be called ONCE in order to detect duplicate entries. More...
 
static recurseFolder ($a_ref_id, $a_folder_name, $a_temp_dir, $a_num_recursions, $a_initiated_by_folder_action)
 

Private Attributes

 $logger = null
 

Static Private Attributes

static $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
 $input = []
 
 $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 14 of file class.ilCollectFilesJob.php.

Constructor & Destructor Documentation

◆ __construct()

ilCollectFilesJob::__construct ( )

Construct.

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

References $GLOBALS.

29  {
30  $this->logger = $GLOBALS['DIC']->logger()->cal();
31  }
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64

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 210 of file class.ilCollectFilesJob.php.

211  {
212  return 30;
213  }

◆ getFileDirs()

static ilCollectFilesJob::getFileDirs (   $a_ref_id,
  $a_file_name,
  $a_temp_dir 
)
staticprivate

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 119 of file class.ilCollectFilesJob.php.

References $DIC, and ilUtil\getASCIIFilename().

120  {
121  global $DIC;
122 
123  $user = $DIC->user();
124  $ilAccess = $DIC->access();
125  if ($ilAccess->checkAccessOfUser($user->getId(), "read", "", $a_ref_id)) {
126  $file = new ilObjFile($a_ref_id);
127  $source_dir = $file->getDirectory($file->getVersion()) . "/" . $file->getFileName();
128  if (@!is_file($source_dir)) {
129  $source_dir = $file->getDirectory() . "/" . $file->getFileName();
130  }
131  $target_dir = $a_temp_dir . '/' . ilUtil::getASCIIFilename($a_file_name);
132 
133  // #25025: allow duplicate filenames by appending an incrementing
134  // number per duplicate in brackets to the name.
135  // Example: test.txt, test (1).txt, test (2).txt, ...
136  if (isset(self::$targets[$target_dir])) {
137  $target_info = pathinfo($target_dir);
138  $target_dir = $a_temp_dir . $target_info["filename"] . " (" . ++self::$targets[$target_dir] . ")." . $target_info["extension"];
139  } else {
140  self::$targets[$target_dir] = 0;
141  }
142 
143  return [
144  "source_dir" => $source_dir,
145  "target_dir" => $target_dir,
146  ];
147  }
148 
149  return false;
150  }
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
$DIC
Definition: xapitoken.php:46
+ Here is the call graph for this function:

◆ getInputTypes()

ilCollectFilesJob::getInputTypes ( )

Implements ILIAS\BackgroundTasks\Task.

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

38  {
39  return
40  [
41  new SingleType(ilCopyDefinition::class),
42  new SingleType(BooleanValue::class),
43  ];
44  }

◆ getOutputType()

ilCollectFilesJob::getOutputType ( )

Implements ILIAS\BackgroundTasks\Task.

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

51  {
52  return new SingleType(ilCopyDefinition::class);
53  }

◆ isStateless()

ilCollectFilesJob::isStateless ( )

Implements ILIAS\BackgroundTasks\Task\Job.

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

60  {
61  return true;
62  }

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

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

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

161  {
162  global $DIC;
163 
164  $num_recursions = $a_num_recursions + 1;
165  $tree = $DIC->repositoryTree();
166  $ilAccess = $DIC->access();
167  $files = array();
168 
169  // Avoid the duplication of the uppermost folder when the download is initiated via a folder's action drop-down
170  // by not including said folders name in the temp_dir path.
171  if (($num_recursions <= 1) and ($a_initiated_by_folder_action)) {
172  $temp_dir = $a_temp_dir;
173  } else {
174  $temp_dir = $a_temp_dir . '/' . ilUtil::getASCIIFilename($a_folder_name);
175  }
176 
177  $subtree = $tree->getChildsByTypeFilter($a_ref_id, array("fold", "file"));
178 
179  foreach ($subtree as $child) {
180  if (!$ilAccess->checkAccess("read", "", $child["ref_id"])) {
181  continue;
182  }
183  if (ilObject::_isInTrash($child["ref_id"])) {
184  continue;
185  }
186  if ($child["type"] == "fold") {
187  $files_from_folder = self::recurseFolder($child["ref_id"], $child['title'], $temp_dir, $num_recursions, $a_initiated_by_folder_action);
188  $files = array_merge($files, $files_from_folder);
189  } else {
190  if (($child["type"] == "file") and (($dirs = self::getFileDirs($child["ref_id"], $child['title'], $temp_dir)) != false)) {
191  $files[] = $dirs;
192  }
193  }
194  }
195  // ensure that empty folders are also contained in the downloaded zip
196  if (empty($subtree)) {
197  $files[] = [
198  "source_dir" => "",
199  "target_dir" => $temp_dir . '/',
200  ];
201  }
202 
203  return $files;
204  }
static _isInTrash($a_ref_id)
checks wether object is in trash
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
$DIC
Definition: xapitoken.php:46
+ Here is the call graph for this function:

◆ run()

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

Todo:
use filsystem service

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

References ilObjectFactory\getInstanceByRefId().

70  {
71  $this->logger->debug('Start collecting files!');
72  $this->logger->dump($input);
73  $definition = $input[0];
74  $initiated_by_folder_action = $input[1]->getValue();
75  $object_ref_ids = $definition->getObjectRefIds();
76  $files = array();
77 
78  foreach ($object_ref_ids as $object_ref_id) {
79  $object = ilObjectFactory::getInstanceByRefId($object_ref_id);
80  $object_type = $object->getType();
81  $object_name = $object->getTitle();
82  $object_temp_dir = ""; // empty as content will be added in recurseFolder and getFileDirs
83 
84  if ($object_type == "fold") {
85  $num_recursions = 0;
86  $files_from_folder = self::recurseFolder($object_ref_id, $object_name, $object_temp_dir, $num_recursions, $initiated_by_folder_action);
87  $files = array_merge($files, $files_from_folder);
88  } else {
89  if (($object_type == "file") and (($file_dirs = self::getFileDirs($object_ref_id, $object_name, $object_temp_dir)) != false)) {
90  $files[] = $file_dirs;
91  }
92  }
93  }
94  $this->logger->debug('Collected files:');
95  $this->logger->dump($files);
96 
97  $num_files = 0;
98  foreach ($files as $file) {
99  $definition->addCopyDefinition($file['source_dir'], $file['target_dir']);
100  $this->logger->debug('Added new copy definition: ' . $file['source_dir'] . ' -> ' . $file['target_dir']);
101 
102  // count files only (without empty directories)
103  $is_empty_folder = preg_match_all("/\/$/", $file['target_dir']);
104  if (!$is_empty_folder) {
105  $num_files++;
106  }
107  }
108  $definition->setObjectRefIds($object_ref_ids);
109  $definition->setNumFiles($num_files);
110 
111  return $definition;
112  }
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
+ Here is the call graph for this function:

Field Documentation

◆ $logger

ilCollectFilesJob::$logger = null
private

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

◆ $targets

ilCollectFilesJob::$targets = []
staticprivate

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


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