ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilCheckSumOfFileSizesJob Class Reference

Description of class class. More...

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

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

Constructor & Destructor Documentation

◆ __construct()

ilCheckSumOfFileSizesJob::__construct ( )

Construct.

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

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

41  {
42  global $DIC;
43  $this->logger = $DIC->logger()->cal();
44  $this->settings = new ilSetting("fold");
45  }
global $DIC
Definition: feed.php:28
+ 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 116 of file class.ilCheckSumOfFileSizesJob.php.

References $DIC, $ref_id, ilObjFileAccess\_lookupFileSize(), ilObject\_lookupType(), and validateAccess().

Referenced by run().

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

169  : int
170  {
171  return 30;
172  }

◆ getInputTypes()

ilCheckSumOfFileSizesJob::getInputTypes ( )

Implements ILIAS\BackgroundTasks\Task.

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

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

◆ getOutputType()

ilCheckSumOfFileSizesJob::getOutputType ( )

Implements ILIAS\BackgroundTasks\Task.

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

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

◆ isStateless()

ilCheckSumOfFileSizesJob::isStateless ( )

Implements ILIAS\BackgroundTasks\Task\Job.

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

72  : bool
73  {
74  return true;
75  }

◆ run()

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

Todo:
use filesystem service

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

References $general, calculateRecursive(), and ILIAS\Repository\logger().

82  : Value
83  {
84  $this->logger->debug('Start checking adherence to maxsize!');
85  $this->logger->dump($input);
86  $definition = $input[0];
87  $object_ref_ids = $definition->getObjectRefIds();
88 
89  // get global limit (max sum of individual file-sizes) from file settings
90  $general = new General();
91  $size_limit = $general->getDownloadLimitinMB();
92  $size_limit_bytes = $size_limit * 1024 * 1024;
93  $this->logger->debug('Global limit (max sum of all file-sizes) in file-settings: ' . $size_limit_bytes . ' bytes');
94  // get sum of individual file-sizes
95  $total_bytes = 0;
96  $this->calculateRecursive($object_ref_ids, $total_bytes);
97  $this->logger->debug('Calculated sum of all file-sizes: ' . $total_bytes . 'MB');
98  // check if calculated total size adheres top global limit
99  $adheres_to_limit = new BooleanValue();
100  $adheres_to_limit->setValue(true);
101  if ($total_bytes > $size_limit_bytes) {
102  $adheres_to_limit->setValue(false);
103  }
104 
105  $definition->setSumFileSizes($total_bytes);
106  $definition->setAdheresToLimit($adheres_to_limit);
107 
108  return $definition;
109  }
$general
SECTIONS.
calculateRecursive(array $a_ref_ids, int &$a_file_size)
Calculates the number and size of the files being downloaded recursively.
+ Here is the call graph for this function:

◆ validateAccess()

ilCheckSumOfFileSizesJob::validateAccess ( int  $ref_id)
protected

Check file access.

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

References $DIC, and ilObject\_isInTrash().

Referenced by calculateRecursive().

154  : bool
155  {
156  global $DIC;
157  $ilAccess = $DIC['ilAccess'];
158 
159  if (!$ilAccess->checkAccess("read", "", $ref_id)) {
160  return false;
161  }
162  return !ilObject::_isInTrash($ref_id);
163  }
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
static _isInTrash(int $ref_id)
+ 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 33 of file class.ilCheckSumOfFileSizesJob.php.

◆ $settings

ilSetting ilCheckSumOfFileSizesJob::$settings
protected

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


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