ILIAS  release_7 Revision v7.30-3-g800a261c036
ilCheckSumOfWorkspaceFileSizesJob Class Reference

Description of class class. More...

+ Inheritance diagram for ilCheckSumOfWorkspaceFileSizesJob:
+ Collaboration diagram for ilCheckSumOfWorkspaceFileSizesJob:

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 Member Functions

 calculateRecursive ($object_wps_ids, &$a_file_size)
 Calculates the number and size of the files being downloaded recursively. More...
 
 validateAccess ($wsp_id)
 Check file access. More...
 
- Protected Member Functions inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask
 checkTypes ($values)
 
 extractType ($value)
 

Protected Attributes

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

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'
 

Detailed Description

Description of class class.

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

Definition at line 14 of file class.ilCheckSumOfWorkspaceFilesJob.php.

Constructor & Destructor Documentation

◆ __construct()

ilCheckSumOfWorkspaceFileSizesJob::__construct ( )

Construct.

Definition at line 34 of file class.ilCheckSumOfWorkspaceFilesJob.php.

35 {
36 global $DIC;
37
38 $user = $DIC->user();
39
40 $this->logger = ilLoggerFactory::getLogger("pwsp");
41 $this->settings = new ilSetting("fold");
42 $this->tree = new ilWorkspaceTree($user->getId());
43 }
static getLogger($a_component_id)
Get component logger.
ILIAS Setting Class.
Tree handler for personal workspace.
global $DIC
Definition: goto.php:24
settings()
Definition: settings.php:2

References $DIC, ilLoggerFactory\getLogger(), and settings().

+ Here is the call graph for this function:

Member Function Documentation

◆ calculateRecursive()

ilCheckSumOfWorkspaceFileSizesJob::calculateRecursive (   $object_wps_ids,
$a_file_size 
)
protected

Calculates the number and size of the files being downloaded recursively.

Parameters
array$a_ref_ids
int& $a_file_count
int& $a_file_size

Definition at line 116 of file class.ilCheckSumOfWorkspaceFilesJob.php.

117 {
118 global $DIC;
119 $tree = $DIC['tree'];
120
121 // parse folders
122 foreach ($object_wps_ids as $object_wps_id) {
123 if (!$this->validateAccess($object_wps_id)) {
124 continue;
125 }
126
127 // we are only interested in folders and files
128 $obj_id = $this->tree->lookupObjectId($object_wps_id);
129 $type = ilObject::_lookupType($obj_id);
130 switch ($type) {
131 case "wfld":
132 // get child objects
133 $subtree = $tree->getChildsByTypeFilter($object_wps_id, array("wfld", "file"));
134 if (count($subtree) > 0) {
135 $child_ref_ids = array();
136 foreach ($subtree as $child) {
137 $child_wsp_ids[] = $child["child"];
138 }
139 $this->calculateRecursive($child_wsp_ids, $a_file_size);
140 }
141 break;
142
143 case "file":
144 $a_file_size += ilObjFileAccess::_lookupFileSize($obj_id);
145 break;
146 }
147 }
148 }
calculateRecursive($object_wps_ids, &$a_file_size)
Calculates the number and size of the files being downloaded recursively.
static _lookupFileSize($a_id)
static _lookupType($a_id, $a_reference=false)
lookup object type
$type

References $DIC, $tree, $type, ilObjFileAccess\_lookupFileSize(), ilObject\_lookupType(), calculateRecursive(), and validateAccess().

Referenced by calculateRecursive(), and run().

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

◆ getExpectedTimeOfTaskInSeconds()

ilCheckSumOfWorkspaceFileSizesJob::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 173 of file class.ilCheckSumOfWorkspaceFilesJob.php.

174 {
175 return 30;
176 }

◆ getInputTypes()

ilCheckSumOfWorkspaceFileSizesJob::getInputTypes ( )

@inheritDoc

Implements ILIAS\BackgroundTasks\Task.

Definition at line 49 of file class.ilCheckSumOfWorkspaceFilesJob.php.

50 {
51 return
52 [
53 new SingleType(ilWorkspaceCopyDefinition::class),
54 ];
55 }

◆ getOutputType()

ilCheckSumOfWorkspaceFileSizesJob::getOutputType ( )

@inheritDoc

Implements ILIAS\BackgroundTasks\Task.

Definition at line 61 of file class.ilCheckSumOfWorkspaceFilesJob.php.

62 {
63 return new SingleType(ilWorkspaceCopyDefinition::class);
64 }

◆ isStateless()

ilCheckSumOfWorkspaceFileSizesJob::isStateless ( )

@inheritDoc

Implements ILIAS\BackgroundTasks\Task\Job.

Definition at line 70 of file class.ilCheckSumOfWorkspaceFilesJob.php.

71 {
72 return true;
73 }

◆ run()

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

@inheritDoc

Todo:
use filesystem service

Definition at line 80 of file class.ilCheckSumOfWorkspaceFilesJob.php.

81 {
82 $this->logger->debug('Start checking adherence to maxsize!');
83 $this->logger->dump($input);
84 $definition = $input[0];
85 $object_wps_ids = $definition->getObjectWspIds();
86
87 // get global limit (max sum of individual file-sizes) from file settings
88 $size_limit = (int) $this->settings->get("bgtask_download_limit", 0);
89 $size_limit_bytes = $size_limit * 1024 * 1024;
90 $this->logger->debug('Global limit (max sum of all file-sizes) in file-settings: ' . $size_limit_bytes . ' bytes');
91 // get sum of individual file-sizes
92 $total_bytes = 0;
93 $this->calculateRecursive($object_wps_ids, $total_bytes);
94 $this->logger->debug('Calculated sum of all file-sizes: ' . $total_bytes . 'MB');
95 // check if calculated total size adheres top global limit
96 $adheres_to_limit = new BooleanValue();
97 $adheres_to_limit->setValue(true);
98 if ($total_bytes > $size_limit_bytes) {
99 $adheres_to_limit->setValue(false);
100 }
101
102 $definition->setSumFileSizes($total_bytes);
103 $definition->setAdheresToLimit($adheres_to_limit);
104
105 return $definition;
106 }

References ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask\$input, calculateRecursive(), and settings().

+ Here is the call graph for this function:

◆ validateAccess()

ilCheckSumOfWorkspaceFileSizesJob::validateAccess (   $wsp_id)
protected

Check file access.

Parameters
int$wsp_id
Returns
boolean

Definition at line 158 of file class.ilCheckSumOfWorkspaceFilesJob.php.

159 {
160 $ilAccess = new ilWorkspaceAccessHandler($this->tree);
161
162 if (!$ilAccess->checkAccess("read", "", $wsp_id)) {
163 return false;
164 }
165
166 return true;
167 }
Access handler for personal workspace.

Referenced by calculateRecursive().

+ Here is the caller graph for this function:

Field Documentation

◆ $logger

ilCheckSumOfWorkspaceFileSizesJob::$logger = null
private

Definition at line 20 of file class.ilCheckSumOfWorkspaceFilesJob.php.

◆ $settings

ilCheckSumOfWorkspaceFileSizesJob::$settings
protected

Definition at line 24 of file class.ilCheckSumOfWorkspaceFilesJob.php.

◆ $tree

ilCheckSumOfWorkspaceFileSizesJob::$tree
protected

Definition at line 29 of file class.ilCheckSumOfWorkspaceFilesJob.php.

Referenced by calculateRecursive().


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