ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCheckSumOfFileSizesJob.php
Go to the documentation of this file.
1<?php
2
26
34{
35 private readonly ?ilLogger $logger;
36 protected \ilSetting $settings;
37
38
42 public function __construct()
43 {
44 global $DIC;
45 $this->logger = $DIC->logger()->cal();
46 $this->settings = new ilSetting("fold");
47 }
48
49
53 public function getInputTypes(): array
54 {
55 return
56 [
57 new SingleType(ilCopyDefinition::class),
58 ];
59 }
60
61
65 public function getOutputType(): Type
66 {
67 return new SingleType(ilCopyDefinition::class);
68 }
69
70
74 public function isStateless(): bool
75 {
76 return true;
77 }
78
79
84 public function run(array $input, Observer $observer): Value
85 {
86 $this->logger->debug('Start checking adherence to maxsize!');
87 $this->logger->dump($input);
88 $definition = $input[0];
89 $object_ref_ids = $definition->getObjectRefIds();
90
91 // get global limit (max sum of individual file-sizes) from file settings
92 $general = new General();
93 $size_limit = $general->getDownloadLimitinMB();
94 $size_limit_bytes = $size_limit * 1024 * 1024;
95 $this->logger->debug('Global limit (max sum of all file-sizes) in file-settings: ' . $size_limit_bytes . ' bytes');
96 // get sum of individual file-sizes
97 $total_bytes = 0;
98 $this->calculateRecursive($object_ref_ids, $total_bytes);
99 $this->logger->debug('Calculated sum of all file-sizes: ' . $total_bytes . 'MB');
100 // check if calculated total size adheres top global limit
101 $adheres_to_limit = new BooleanValue();
102 $adheres_to_limit->setValue(true);
103 if ($total_bytes > $size_limit_bytes) {
104 $adheres_to_limit->setValue(false);
105 }
106
107 $definition->setSumFileSizes($total_bytes);
108 $definition->setAdheresToLimit($adheres_to_limit);
109
110 return $definition;
111 }
112
113
118 protected function calculateRecursive(array $a_ref_ids, int &$a_file_size): void
119 {
120 global $DIC;
121 $tree = $DIC['tree'];
122
123 // parse folders
124 foreach ($a_ref_ids as $ref_id) {
125 if (!$this->validateAccess($ref_id)) {
126 continue;
127 }
128
129 // we are only interested in folders and files
130 switch (ilObject::_lookupType($ref_id, true)) {
131 case "fold":
132 // get child objects
133 $subtree = $tree->getChildsByTypeFilter($ref_id, ["fold", "file"]);
134 if (count($subtree) > 0) {
135 $child_ref_ids = [];
136 foreach ($subtree as $child) {
137 $child_ref_ids[] = $child["ref_id"];
138 }
139 $this->calculateRecursive($child_ref_ids, $a_file_size);
140 }
141 break;
142
143 case "file":
145 break;
146 }
147 }
148 }
149
150
156 protected function validateAccess(int $ref_id): bool
157 {
158 global $DIC;
159 $ilAccess = $DIC['ilAccess'];
160
161 if (!$ilAccess->checkAccess("read", "", $ref_id)) {
162 return false;
163 }
165 }
166
167
172 {
173 return 30;
174 }
175}
$general
SECTIONS.
getExpectedTimeOfTaskInSeconds()
int the amount of seconds this task usually taskes. If your task-duration scales with the the amount ...
validateAccess(int $ref_id)
Check file access.
run(array $input, Observer $observer)
@inheritDoc
calculateRecursive(array $a_ref_ids, int &$a_file_size)
Calculates the number and size of the files being downloaded recursively.
Component logger with individual log levels by component id.
static _lookupFileSize(int $a_id, bool $by_reference=true)
static _lookupType(int $id, bool $reference=false)
static _isInTrash(int $ref_id)
ILIAS Setting Class.
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26