ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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
mixed 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 ($a_ref_ids, &$a_file_size)
 Calculates the number and size of the files being downloaded recursively. More...
 
 validateAccess ($ref_id)
 Check file access. More...
 
- Protected Member Functions inherited from ILIAS\BackgroundTasks\Implementation\Tasks\AbstractTask
 checkTypes ($values)
 
 extractType ($value)
 

Protected Attributes

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

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

Constructor & Destructor Documentation

◆ __construct()

ilCheckSumOfFileSizesJob::__construct ( )

Construct.

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

References $GLOBALS, and settings().

31  {
32  $this->logger = $GLOBALS['DIC']->logger()->cal();
33  $this->settings = new ilSetting("fold");
34  }
settings()
Definition: settings.php:2
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
+ Here is the call graph for this function:

Member Function Documentation

◆ calculateRecursive()

ilCheckSumOfFileSizesJob::calculateRecursive (   $a_ref_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 107 of file class.ilCheckSumOfFileSizesJob.php.

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

Referenced by run().

108  {
109  global $DIC;
110  $tree = $DIC['tree'];
111 
112  include_once("./Modules/File/classes/class.ilObjFileAccess.php");
113 
114  // parse folders
115  foreach ($a_ref_ids as $ref_id) {
116  if (!$this->validateAccess($ref_id)) {
117  continue;
118  }
119 
120  // we are only interested in folders and files
121  switch (ilObject::_lookupType($ref_id, true)) {
122  case "fold":
123  // get child objects
124  $subtree = $tree->getChildsByTypeFilter($ref_id, array("fold", "file"));
125  if (count($subtree) > 0) {
126  $child_ref_ids = array();
127  foreach ($subtree as $child) {
128  $child_ref_ids[] = $child["ref_id"];
129  }
130  $this->calculateRecursive($child_ref_ids, $a_file_size);
131  }
132  break;
133 
134  case "file":
136  break;
137  }
138  }
139  }
static _lookupFileSize($a_id)
static _lookupObjId($a_id)
global $DIC
Definition: goto.php:24
validateAccess($ref_id)
Check file access.
static _lookupType($a_id, $a_reference=false)
lookup object type
calculateRecursive($a_ref_ids, &$a_file_size)
Calculates the number and size of the files being downloaded recursively.
+ 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.

170  {
171  return 30;
172  }

◆ getInputTypes()

ilCheckSumOfFileSizesJob::getInputTypes ( )

Implements ILIAS\BackgroundTasks\Task.

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

41  {
42  return
43  [
44  new SingleType(ilCopyDefinition::class),
45  ];
46  }

◆ getOutputType()

ilCheckSumOfFileSizesJob::getOutputType ( )

Implements ILIAS\BackgroundTasks\Task.

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

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

◆ isStateless()

ilCheckSumOfFileSizesJob::isStateless ( )

Implements ILIAS\BackgroundTasks\Task\Job.

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

62  {
63  return true;
64  }

◆ run()

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

Todo:
use filesystem service

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

References calculateRecursive(), and settings().

72  {
73  $this->logger->debug('Start checking adherence to maxsize!');
74  $this->logger->dump($input);
75  $definition = $input[0];
76  $object_ref_ids = $definition->getObjectRefIds();
77 
78  // get global limit (max sum of individual file-sizes) from file settings
79  $size_limit = (int) $this->settings->get("bgtask_download_limit", 0);
80  $size_limit_bytes = $size_limit * 1024 * 1024;
81  $this->logger->debug('Global limit (max sum of all file-sizes) in file-settings: ' . $size_limit_bytes . ' bytes');
82  // get sum of individual file-sizes
83  $total_bytes = 0;
84  $this->calculateRecursive($object_ref_ids, $total_bytes);
85  $this->logger->debug('Calculated sum of all file-sizes: ' . $total_bytes . 'MB');
86  // check if calculated total size adheres top global limit
87  $adheres_to_limit = new BooleanValue();
88  $adheres_to_limit->setValue(true);
89  if ($total_bytes > $size_limit_bytes) {
90  $adheres_to_limit->setValue(false);
91  }
92 
93  $definition->setSumFileSizes($total_bytes);
94  $definition->setAdheresToLimit($adheres_to_limit);
95 
96  return $definition;
97  }
settings()
Definition: settings.php:2
calculateRecursive($a_ref_ids, &$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 (   $ref_id)
protected

Check file access.

Parameters
int$ref_id
Returns
boolean

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

References $DIC, and ilObject\_isInTrash().

Referenced by calculateRecursive().

150  {
151  global $DIC;
152  $ilAccess = $DIC['ilAccess'];
153 
154  if (!$ilAccess->checkAccess("read", "", $ref_id)) {
155  return false;
156  }
157 
158  if (ilObject::_isInTrash($ref_id)) {
159  return false;
160  }
161 
162  return true;
163  }
static _isInTrash($a_ref_id)
checks wether object is in trash
global $DIC
Definition: goto.php:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $logger

ilCheckSumOfFileSizesJob::$logger = null
private

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

◆ $settings

ilCheckSumOfFileSizesJob::$settings
protected

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


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