ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCheckSumOfFileSizesJob.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
7 
15 {
16 
20  private $logger = null;
24  protected $settings; // [ilSetting]
25 
26 
30  public function __construct()
31  {
32  $this->logger = $GLOBALS['DIC']->logger()->cal();
33  $this->settings = new ilSetting("fold");
34  }
35 
36 
40  public function getInputTypes()
41  {
42  return
43  [
44  new SingleType(ilCopyDefinition::class),
45  ];
46  }
47 
48 
52  public function getOutputType()
53  {
54  return new SingleType(ilCopyDefinition::class);
55  }
56 
57 
61  public function isStateless()
62  {
63  return true;
64  }
65 
66 
71  public function run(array $input, \ILIAS\BackgroundTasks\Observer $observer)
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  }
98 
99 
107  protected function calculateRecursive($a_ref_ids, &$a_file_size)
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  }
140 
141 
149  protected function validateAccess($ref_id)
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  }
164 
165 
170  {
171  return 30;
172  }
173 }
settings()
Definition: settings.php:2
Class ChatMainBarProvider .
static _isInTrash($a_ref_id)
checks wether object is in trash
run(array $input, \ILIAS\BackgroundTasks\Observer $observer)
static _lookupFileSize($a_id)
static _lookupObjId($a_id)
getExpectedTimeOfTaskInSeconds()
int the amount of seconds this task usually taskes. If your task-duration scales with the the amount ...
global $DIC
Definition: goto.php:24
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
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.