ILIAS  release_8 Revision v8.24
ilCheckSumOfFileSizesJob Class Reference

Description of class class. More...

+ Inheritance diagram for ilCheckSumOfFileSizesJob:
+ Collaboration diagram for ilCheckSumOfFileSizesJob:

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 (array $a_ref_ids, int &$a_file_size)
 Calculates the number and size of the files being downloaded recursively. More...
 
 validateAccess (int $ref_id)
 Check file access. More...
 
- Protected Member Functions inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask
 checkTypes ($values)
 
 extractType ($value)
 

Protected Attributes

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

Private Attributes

ilLogger $logger
 

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
Lukas Zehnder lz@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

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

Constructor & Destructor Documentation

◆ __construct()

ilCheckSumOfFileSizesJob::__construct ( )

Construct.

Definition at line 39 of file class.ilCheckSumOfFileSizesJob.php.

40 {
41 global $DIC;
42 $this->logger = $DIC->logger()->cal();
43 $this->settings = new ilSetting("fold");
44 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28

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

+ Here is the call graph for this function:

Member Function Documentation

◆ calculateRecursive()

ilCheckSumOfFileSizesJob::calculateRecursive ( array  $a_ref_ids,
int &  $a_file_size 
)
protected

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

Definition at line 114 of file class.ilCheckSumOfFileSizesJob.php.

114 : void
115 {
116 global $DIC;
117 $tree = $DIC['tree'];
118
119 // parse folders
120 foreach ($a_ref_ids as $ref_id) {
121 if (!$this->validateAccess($ref_id)) {
122 continue;
123 }
124
125 // we are only interested in folders and files
126 switch (ilObject::_lookupType($ref_id, true)) {
127 case "fold":
128 // get child objects
129 $subtree = $tree->getChildsByTypeFilter($ref_id, array("fold", "file"));
130 if (count($subtree) > 0) {
131 $child_ref_ids = array();
132 foreach ($subtree as $child) {
133 $child_ref_ids[] = $child["ref_id"];
134 }
135 $this->calculateRecursive($child_ref_ids, $a_file_size);
136 }
137 break;
138
139 case "file":
141 break;
142 }
143 }
144 }
validateAccess(int $ref_id)
Check file access.
calculateRecursive(array $a_ref_ids, int &$a_file_size)
Calculates the number and size of the files being downloaded recursively.
static _lookupFileSize(int $a_id, bool $by_reference=true)
static _lookupType(int $id, bool $reference=false)
$ref_id
Definition: ltiauth.php:67

References $DIC, $ref_id, 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()

ilCheckSumOfFileSizesJob::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 167 of file class.ilCheckSumOfFileSizesJob.php.

167 : int
168 {
169 return 30;
170 }

◆ getInputTypes()

ilCheckSumOfFileSizesJob::getInputTypes ( )

@inheritDoc

Implements ILIAS\BackgroundTasks\Task.

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

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

◆ getOutputType()

ilCheckSumOfFileSizesJob::getOutputType ( )

@inheritDoc

Implements ILIAS\BackgroundTasks\Task.

Definition at line 62 of file class.ilCheckSumOfFileSizesJob.php.

62 : Type
63 {
64 return new SingleType(ilCopyDefinition::class);
65 }

◆ isStateless()

ilCheckSumOfFileSizesJob::isStateless ( )

@inheritDoc

Implements ILIAS\BackgroundTasks\Task\Job.

Definition at line 71 of file class.ilCheckSumOfFileSizesJob.php.

71 : bool
72 {
73 return true;
74 }

◆ run()

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

@inheritDoc

Todo:
use filesystem service

Definition at line 81 of file class.ilCheckSumOfFileSizesJob.php.

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

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

+ Here is the call graph for this function:

◆ validateAccess()

ilCheckSumOfFileSizesJob::validateAccess ( int  $ref_id)
protected

Check file access.

Definition at line 152 of file class.ilCheckSumOfFileSizesJob.php.

152 : bool
153 {
154 global $DIC;
155 $ilAccess = $DIC['ilAccess'];
156
157 if (!$ilAccess->checkAccess("read", "", $ref_id)) {
158 return false;
159 }
161 }
static _isInTrash(int $ref_id)

References $DIC, $ref_id, and ilObject\_isInTrash().

Referenced by calculateRecursive().

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

Field Documentation

◆ $logger

ilLogger ilCheckSumOfFileSizesJob::$logger
private

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

◆ $settings

ilSetting ilCheckSumOfFileSizesJob::$settings
protected

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


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