ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilCollectWorkspaceFilesJob Class Reference

Description of class class. More...

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

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 ()
 

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.

28 {
29 global $DIC;
30
31 $user = $DIC->user();
32
33 $this->logger = ilLoggerFactory::getLogger("pwsp");
34 $this->tree = new ilWorkspaceTree($user->getId());
35 }
static getLogger($a_component_id)
Get component logger.
Tree handler for personal workspace.
$DIC
Definition: xapitoken.php:46

References $DIC, and ilLoggerFactory\getLogger().

+ 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.

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->getDirectory($file->getVersion()) . "/" . $file->getFileName();
121 if (@!is_file($source_dir)) {
122 $source_dir = $file->getDirectory() . "/" . $file->getFileName();
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 }
Class ilObjFile.
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
Access handler for personal workspace.

References $DIC, and ilUtil\getASCIIFilename().

Referenced by recurseFolder(), and run().

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

◆ getInputTypes()

ilCollectWorkspaceFilesJob::getInputTypes ( )

@inheritDoc

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 ( )

@inheritDoc

Implements ILIAS\BackgroundTasks\Task.

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

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

◆ isStateless()

ilCollectWorkspaceFilesJob::isStateless ( )

@inheritDoc

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.

143 {
144 $num_recursions = $a_num_recursions + 1;
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)
recurseFolder($a_wsp_id, $a_folder_name, $a_temp_dir, $a_num_recursions, $a_initiated_by_folder_action)

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

Referenced by recurseFolder(), and run().

+ 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 
)

@inheritDoc

Todo:
use filsystem service

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

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 }
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type

References ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask\$input, ilObject\_lookupTitle(), ilObject\_lookupType(), getFileDirs(), and recurseFolder().

+ 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: