ILIAS  release_8 Revision v8.19
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 ()
 
 getInputTypes ()
 
 getOutputType ()
 
 isStateless ()
 
 run (array $input, \ILIAS\BackgroundTasks\Observer $observer)
 
 getExpectedTimeOfTaskInSeconds ()
 
- Public Member Functions inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractJob
 getInput ()
 
Returns
array 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

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

Private Member Functions

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

Private Attributes

ilLogger $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
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

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

Constructor & Destructor Documentation

◆ __construct()

ilCollectWorkspaceFilesJob::__construct ( )

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

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

36  {
37  global $DIC;
38 
39  $user = $DIC->user();
40 
41  $this->logger = ilLoggerFactory::getLogger("pwsp");
42  $this->tree = new ilWorkspaceTree($user->getId());
43  }
static getLogger(string $a_component_id)
Get component logger.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
+ 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 176 of file class.ilCollectWorkspaceFilesJob.php.

176  : int
177  {
178  return 30;
179  }

◆ getFileDirs()

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

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

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

Referenced by recurseFolder(), and run().

111  : ?array {
112  global $DIC;
113 
114  $user = $DIC->user();
115  $ilAccess = new ilWorkspaceAccessHandler($this->tree);
116  if ($ilAccess->checkAccessOfUser($this->tree, $user->getId(), "read", "", $a_wsp_id)) {
117  $file = new ilObjFile($this->tree->lookupObjectId($a_wsp_id), false);
118  $source_dir = $file->getFile($file->getVersion());
119  if (!is_file($source_dir)) {
120  $source_dir = $file->getFile();
121  }
122  $target_dir = $a_temp_dir . '/' . ilFileUtils::getASCIIFilename($a_file_name);
123 
124  return [
125  "source_dir" => $source_dir,
126  "target_dir" => $target_dir
127  ];
128  }
129  return null;
130  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getASCIIFilename(string $a_filename)
global $DIC
Definition: feed.php:28
Class ilObjFile.
getFile(?int $a_hist_entry_id=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInputTypes()

ilCollectWorkspaceFilesJob::getInputTypes ( )
Returns
Type[] A list of types that are taken as input.

Implements ILIAS\BackgroundTasks\Task.

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

45  : array
46  {
47  return
48  [
49  new SingleType(ilWorkspaceCopyDefinition::class),
50  new SingleType(BooleanValue::class)
51  ];
52  }

◆ getOutputType()

ilCollectWorkspaceFilesJob::getOutputType ( )

Implements ILIAS\BackgroundTasks\Task.

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

54  : Type
55  {
56  return new SingleType(ilWorkspaceCopyDefinition::class);
57  }

◆ isStateless()

ilCollectWorkspaceFilesJob::isStateless ( )
Returns
bool returns true iff the job's output ONLY depends on the input. Stateless task results may be cached!

Implements ILIAS\BackgroundTasks\Task\Job.

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

59  : bool
60  {
61  return true;
62  }

◆ recurseFolder()

ilCollectWorkspaceFilesJob::recurseFolder ( int  $a_wsp_id,
string  $a_folder_name,
string  $a_temp_dir,
int  $a_num_recursions,
bool  $a_initiated_by_folder_action 
)
private

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

References $tree, ilFileUtils\getASCIIFilename(), ilTree\getChildsByTypeFilter(), and getFileDirs().

Referenced by run().

138  : array {
139  $num_recursions = $a_num_recursions + 1;
140  $tree = $this->tree;
141  $ilAccess = new ilWorkspaceAccessHandler($this->tree);
142  $files = array();
143 
144  // Avoid the duplication of the uppermost folder when the download is initiated via a folder's action drop-down
145  // by not including said folders name in the temp_dir path.
146  if (($num_recursions <= 1) and ($a_initiated_by_folder_action)) {
147  $temp_dir = $a_temp_dir;
148  } else {
149  $temp_dir = $a_temp_dir . '/' . ilFileUtils::getASCIIFilename($a_folder_name);
150  }
151 
152 
153  $subtree = $tree->getChildsByTypeFilter($a_wsp_id, array("wfld","file"));
154 
155  foreach ($subtree as $child) {
156  if (!$ilAccess->checkAccess("read", "", $child["child"])) {
157  continue;
158  }
159  if ($child["type"] == "wfld") {
160  $files_from_folder = $this->recurseFolder($child["child"], $child['title'], $temp_dir, $num_recursions, $a_initiated_by_folder_action);
161  $files = array_merge($files, $files_from_folder);
162  } elseif (($child["type"] == "file") and ($this->getFileDirs($child["child"], $child['title'], $temp_dir) != false)) {
163  $files[] = $this->getFileDirs((int) $child["wsp_id"], $child['title'], $temp_dir);
164  }
165  }
166  // ensure that empty folders are also contained in the downloaded zip
167  if (empty($subtree)) {
168  $files[] = [
169  "source_dir" => "",
170  "target_dir" => $temp_dir . '/'
171  ];
172  }
173  return $files;
174  }
recurseFolder(int $a_wsp_id, string $a_folder_name, string $a_temp_dir, int $a_num_recursions, bool $a_initiated_by_folder_action)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getASCIIFilename(string $a_filename)
getFileDirs(int $a_wsp_id, string $a_file_name, string $a_temp_dir)
getChildsByTypeFilter(int $a_node_id, array $a_types, string $a_order="", string $a_direction="ASC")
get child nodes of given node by object type
+ 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 
)

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

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

64  : Value
65  {
66  $this->logger->debug('Start collecting files!');
67  $this->logger->dump($input);
68  $definition = $input[0];
69  $initiated_by_folder_action = $input[1]->getValue();
70  $object_wps_ids = $definition->getObjectWspIds();
71  $files = array();
72 
73  foreach ($object_wps_ids as $object_wps_id) {
74  $obj_id = $this->tree->lookupObjectId($object_wps_id);
75  $object_type = ilObject::_lookupType($obj_id);
76  $object_name = ilObject::_lookupTitle($obj_id);
77  $object_temp_dir = ""; // empty as content will be added in recurseFolder and getFileDirs
78 
79  if ($object_type == "wfld") {
80  $num_recursions = 0;
81  $files_from_folder = $this->recurseFolder($object_wps_id, $object_name, $object_temp_dir, $num_recursions, $initiated_by_folder_action);
82  $files = array_merge($files, $files_from_folder);
83  } elseif (($object_type == "file") and ($this->getFileDirs($object_wps_id, $object_name, $object_temp_dir) != false)) {
84  $files[] = $this->getFileDirs($object_wps_id, $object_name, $object_temp_dir);
85  }
86  }
87  $this->logger->debug('Collected files:');
88  $this->logger->dump($files);
89 
90  $num_files = 0;
91  foreach ($files as $file) {
92  $definition->addCopyDefinition($file['source_dir'], $file['target_dir']);
93  $this->logger->debug('Added new copy definition: ' . $file['source_dir'] . ' -> ' . $file['target_dir']);
94 
95  // count files only (without empty directories)
96  $is_empty_folder = preg_match_all("/\/$/", $file['target_dir']);
97  if (!$is_empty_folder) {
98  $num_files++;
99  }
100  }
101  $definition->setObjectWspIds($object_wps_ids);
102  $definition->setNumFiles($num_files);
103 
104  return $definition;
105  }
recurseFolder(int $a_wsp_id, string $a_folder_name, string $a_temp_dir, int $a_num_recursions, bool $a_initiated_by_folder_action)
getFileDirs(int $a_wsp_id, string $a_file_name, string $a_temp_dir)
static _lookupTitle(int $obj_id)
static _lookupType(int $id, bool $reference=false)
+ Here is the call graph for this function:

Field Documentation

◆ $logger

ilLogger ilCollectWorkspaceFilesJob::$logger = null
private

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

◆ $tree

ilWorkspaceTree ilCollectWorkspaceFilesJob::$tree
protected

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

Referenced by recurseFolder().


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