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

Description of class class. More...

+ Inheritance diagram for ilCollectWorkspaceFilesJob:
+ Collaboration diagram for ilCollectWorkspaceFilesJob:

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)
 

Protected Attributes

 $tree
 
- Protected Attributes inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask
 $input = []
 
 $output
 

Private Member Functions

 getFileDirs ($a_wsp_id, $a_file_name, $a_temp_dir)
 
 recurseFolder ($a_wsp_id, $a_folder_name, $a_temp_dir, $a_num_recursions, $a_initiated_by_folder_action)
 

Private Attributes

 $logger = null
 

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)
 

Detailed Description

Description of class class.

Author
killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 15 of file class.ilCollectWorkspaceFilesJob.php.

Constructor & Destructor Documentation

◆ __construct()

ilCollectWorkspaceFilesJob::__construct ( )

Construct.

Definition at line 27 of file class.ilCollectWorkspaceFilesJob.php.

References $DIC, and ilLoggerFactory\getLogger().

28  {
29  global $DIC;
30 
31  $user = $DIC->user();
32 
33  $this->logger = ilLoggerFactory::getLogger("pwsp");
34  $this->tree = new ilWorkspaceTree($user->getId());
35  }
Tree handler for personal workspace.
global $DIC
Definition: goto.php:24
static getLogger($a_component_id)
Get component logger.
+ Here is the call graph for this function:

Member Function Documentation

◆ getExpectedTimeOfTaskInSeconds()

ilCollectWorkspaceFilesJob::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 184 of file class.ilCollectWorkspaceFilesJob.php.

185  {
186  return 30;
187  }

◆ getFileDirs()

ilCollectWorkspaceFilesJob::getFileDirs (   $a_wsp_id,
  $a_file_name,
  $a_temp_dir 
)
private

Definition at line 112 of file class.ilCollectWorkspaceFilesJob.php.

References $DIC, ilUtil\getASCIIFilename(), and ilObjFile\getFile().

Referenced by recurseFolder(), and run().

113  {
114  global $DIC;
115 
116  $user = $DIC->user();
117  $ilAccess = new ilWorkspaceAccessHandler($this->tree);
118  if ($ilAccess->checkAccessOfUser($this->tree, $user->getId(), "read", "", $a_wsp_id)) {
119  $file = new ilObjFile($this->tree->lookupObjectId($a_wsp_id), false);
120  $source_dir = $file->getFile($file->getVersion());
121  if (@!is_file($source_dir)) {
122  $source_dir = $file->getFile();
123  }
124  $target_dir = $a_temp_dir . '/' . ilUtil::getASCIIFilename($a_file_name);
125 
126  return $file_dirs = [
127  "source_dir" => $source_dir,
128  "target_dir" => $target_dir
129  ];
130  }
131  return false;
132  }
getFile($a_hist_entry_id=null)
Access handler for personal workspace.
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
global $DIC
Definition: goto.php:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInputTypes()

ilCollectWorkspaceFilesJob::getInputTypes ( )

Implements ILIAS\BackgroundTasks\Task.

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

41  {
42  return
43  [
44  new SingleType(ilWorkspaceCopyDefinition::class),
45  new SingleType(BooleanValue::class)
46  ];
47  }

◆ getOutputType()

ilCollectWorkspaceFilesJob::getOutputType ( )

Implements ILIAS\BackgroundTasks\Task.

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

53  {
54  return new SingleType(ilWorkspaceCopyDefinition::class);
55  }

◆ isStateless()

ilCollectWorkspaceFilesJob::isStateless ( )

Implements ILIAS\BackgroundTasks\Task\Job.

Definition at line 60 of file class.ilCollectWorkspaceFilesJob.php.

61  {
62  return true;
63  }

◆ recurseFolder()

ilCollectWorkspaceFilesJob::recurseFolder (   $a_wsp_id,
  $a_folder_name,
  $a_temp_dir,
  $a_num_recursions,
  $a_initiated_by_folder_action 
)
private
Parameters
$a_wsp_id
$a_folder_name
$a_temp_dir
$a_num_recursions
$a_initiated_by_folder_action
Returns
array

Definition at line 142 of file class.ilCollectWorkspaceFilesJob.php.

References $tree, ilUtil\getASCIIFilename(), and getFileDirs().

Referenced by run().

143  {
144  $num_recursions = $a_num_recursions + 1;
145  $tree = $this->tree;
146  $ilAccess = new ilWorkspaceAccessHandler($this->tree);
147  $files = array();
148 
149  // Avoid the duplication of the uppermost folder when the download is initiated via a folder's action drop-down
150  // by not including said folders name in the temp_dir path.
151  if (($num_recursions <= 1) and ($a_initiated_by_folder_action)) {
152  $temp_dir = $a_temp_dir;
153  } else {
154  $temp_dir = $a_temp_dir . '/' . ilUtil::getASCIIFilename($a_folder_name);
155  }
156 
157 
158  $subtree = $tree->getChildsByTypeFilter($a_wsp_id, array("wfld","file"));
159 
160  foreach ($subtree as $child) {
161  if (!$ilAccess->checkAccess("read", "", $child["child"])) {
162  continue;
163  }
164  if ($child["type"] == "wfld") {
165  $files_from_folder = $this->recurseFolder($child["child"], $child['title'], $temp_dir, $num_recursions, $a_initiated_by_folder_action);
166  $files = array_merge($files, $files_from_folder);
167  } elseif (($child["type"] == "file") and ($this->getFileDirs($child["child"], $child['title'], $temp_dir) != false)) {
168  $files[] = $this->getFileDirs($child["ref_id"], $child['title'], $temp_dir);
169  }
170  }
171  // ensure that empty folders are also contained in the downloaded zip
172  if (empty($subtree)) {
173  $files[] = [
174  "source_dir" => "",
175  "target_dir" => $temp_dir . '/'
176  ];
177  }
178  return $files;
179  }
getFileDirs($a_wsp_id, $a_file_name, $a_temp_dir)
Access handler for personal workspace.
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
recurseFolder($a_wsp_id, $a_folder_name, $a_temp_dir, $a_num_recursions, $a_initiated_by_folder_action)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

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

Todo:
use filsystem service

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

References ilObject\_lookupTitle(), ilObject\_lookupType(), getFileDirs(), and recurseFolder().

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_wps_ids = $definition->getObjectWspIds();
76  $files = array();
77 
78  foreach ($object_wps_ids as $object_wps_id) {
79  $obj_id = $this->tree->lookupObjectId($object_wps_id);
80  $object_type = ilObject::_lookupType($obj_id);
81  $object_name = ilObject::_lookupTitle($obj_id);
82  $object_temp_dir = ""; // empty as content will be added in recurseFolder and getFileDirs
83 
84  if ($object_type == "wfld") {
85  $num_recursions = 0;
86  $files_from_folder = $this->recurseFolder($object_wps_id, $object_name, $object_temp_dir, $num_recursions, $initiated_by_folder_action);
87  $files = array_merge($files, $files_from_folder);
88  } elseif (($object_type == "file") and ($this->getFileDirs($object_wps_id, $object_name, $object_temp_dir) != false)) {
89  $files[] = $this->getFileDirs($object_wps_id, $object_name, $object_temp_dir);
90  }
91  }
92  $this->logger->debug('Collected files:');
93  $this->logger->dump($files);
94 
95  $num_files = 0;
96  foreach ($files as $file) {
97  $definition->addCopyDefinition($file['source_dir'], $file['target_dir']);
98  $this->logger->debug('Added new copy definition: ' . $file['source_dir'] . ' -> ' . $file['target_dir']);
99 
100  // count files only (without empty directories)
101  $is_empty_folder = preg_match_all("/\/$/", $file['target_dir']);
102  if (!$is_empty_folder) {
103  $num_files++;
104  }
105  }
106  $definition->setObjectWspIds($object_wps_ids);
107  $definition->setNumFiles($num_files);
108 
109  return $definition;
110  }
getFileDirs($a_wsp_id, $a_file_name, $a_temp_dir)
static _lookupTitle($a_id)
lookup object title
recurseFolder($a_wsp_id, $a_folder_name, $a_temp_dir, $a_num_recursions, $a_initiated_by_folder_action)
static _lookupType($a_id, $a_reference=false)
lookup object type
+ Here is the call graph for this function:

Field Documentation

◆ $logger

ilCollectWorkspaceFilesJob::$logger = null
private

Definition at line 17 of file class.ilCollectWorkspaceFilesJob.php.

◆ $tree

ilCollectWorkspaceFilesJob::$tree
protected

Definition at line 22 of file class.ilCollectWorkspaceFilesJob.php.

Referenced by recurseFolder().


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