ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilCheckSumOfWorkspaceFileSizesJob.php
Go to the documentation of this file.
1 <?php
2 
25 
33 {
34  private ?ilLogger $logger = null;
35  protected ilSetting $settings; // [ilSetting]
37 
38  public function __construct()
39  {
40  global $DIC;
41 
42  $user = $DIC->user();
43 
44  $this->logger = ilLoggerFactory::getLogger("pwsp");
45  $this->settings = new ilSetting("fold");
46  $this->tree = new ilWorkspaceTree($user->getId());
47  }
48 
49  public function getInputTypes(): array
50  {
51  return
52  [
53  new SingleType(ilWorkspaceCopyDefinition::class),
54  ];
55  }
56 
57  public function getOutputType(): Type
58  {
59  return new SingleType(ilWorkspaceCopyDefinition::class);
60  }
61 
62  public function isStateless(): bool
63  {
64  return true;
65  }
66 
67  public function run(array $input, \ILIAS\BackgroundTasks\Observer $observer): Value
68  {
69  $this->logger->debug('Start checking adherence to maxsize!');
70  $this->logger->dump($input);
71  $definition = $input[0];
72  $object_wps_ids = $definition->getObjectWspIds();
73 
74  // get global limit (max sum of individual file-sizes) from file settings
75  $general = new General();
76  $size_limit = $general->getDownloadLimitinMB();
77  $size_limit_bytes = $size_limit * 1024 * 1024;
78  $this->logger->debug('Global limit (max sum of all file-sizes) in file-settings: ' . $size_limit_bytes . ' bytes');
79  // get sum of individual file-sizes
80  $total_bytes = 0;
81  $this->calculateRecursive($object_wps_ids, $total_bytes);
82  $this->logger->debug('Calculated sum of all file-sizes: ' . $total_bytes . ' B');
83  // check if calculated total size adheres top global limit
84  $adheres_to_limit = new BooleanValue();
85  $adheres_to_limit->setValue(true);
86  if ($total_bytes > $size_limit_bytes) {
87  $adheres_to_limit->setValue(false);
88  }
89 
90  $definition->setSumFileSizes($total_bytes);
91  $definition->setAdheresToLimit($adheres_to_limit);
92 
93  return $definition;
94  }
95 
96 
100  protected function calculateRecursive(
101  array $object_wps_ids,
102  int &$a_file_size
103  ): void {
104  global $DIC;
105  $tree = $DIC['tree'];
106 
107  // parse folders
108  foreach ($object_wps_ids as $object_wps_id) {
109  if (!$this->validateAccess($object_wps_id)) {
110  continue;
111  }
112 
113  // we are only interested in folders and files
114  $obj_id = $this->tree->lookupObjectId($object_wps_id);
115  $type = ilObject::_lookupType($obj_id);
116  switch ($type) {
117  case "wfld":
118  // get child objects
119  $subtree = $tree->getChildsByTypeFilter($object_wps_id, array("wfld", "file"));
120  if (count($subtree) > 0) {
121  $child_wsp_ids = array();
122  foreach ($subtree as $child) {
123  $child_wsp_ids[] = $child["child"];
124  }
125  $this->calculateRecursive($child_wsp_ids, $a_file_size);
126  }
127  break;
128 
129  case "file":
130  $a_file_size += ilObjFileAccess::_lookupFileSize($obj_id, false);
131  break;
132  }
133  }
134  }
135 
136  protected function validateAccess(int $wsp_id): bool
137  {
138  $ilAccess = new ilWorkspaceAccessHandler($this->tree);
139 
140  if (!$ilAccess->checkAccess("read", "", $wsp_id)) {
141  return false;
142  }
143 
144  return true;
145  }
146 
148  {
149  return 30;
150  }
151 }
static getLogger(string $a_component_id)
Get component logger.
Interface Observer Contains several chained tasks and infos about them.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupFileSize(int $a_id, bool $by_reference=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
run(array $input, \ILIAS\BackgroundTasks\Observer $observer)
calculateRecursive(array $object_wps_ids, int &$a_file_size)
Calculates the number and size of the files being downloaded recursively.
$general
SECTIONS.
global $DIC
Definition: shib_login.php:22
getChildsByTypeFilter(int $a_node_id, array $a_types, string $a_order="", string $a_direction="ASC")
get child nodes of given node by object type
lookupObjectId(int $a_node_id)
Get object id for node id.
static _lookupType(int $id, bool $reference=false)