ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilCheckSumOfWorkspaceFileSizesJob Class Reference

Description of class class. More...

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

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 ($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.

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

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  }
settings()
Definition: settings.php:2
Tree handler for personal workspace.
$DIC
Definition: xapitoken.php:46
static getLogger($a_component_id)
Get component logger.
+ 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.

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

Referenced by run().

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  }
$type
static _lookupFileSize($a_id)
Quickly looks up the file size from the database and returns the number of bytes. ...
static _lookupType($a_id, $a_reference=false)
lookup object type
$DIC
Definition: xapitoken.php:46
calculateRecursive($object_wps_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()

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

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

Implements ILIAS\BackgroundTasks\Task.

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

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

◆ isStateless()

ilCheckSumOfWorkspaceFileSizesJob::isStateless ( )

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 
)

Todo:
use filesystem service

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

References calculateRecursive(), and settings().

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  }
settings()
Definition: settings.php:2
calculateRecursive($object_wps_ids, &$a_file_size)
Calculates the number and size of the files being downloaded recursively.
+ 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.

Referenced by calculateRecursive().

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