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