ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilCheckSumOfWorkspaceFilesJob.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
29 protected $tree;
30
34 public function __construct()
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 }
44
45
49 public function getInputTypes()
50 {
51 return
52 [
53 new SingleType(ilWorkspaceCopyDefinition::class),
54 ];
55 }
56
57
61 public function getOutputType()
62 {
63 return new SingleType(ilWorkspaceCopyDefinition::class);
64 }
65
66
70 public function isStateless()
71 {
72 return true;
73 }
74
75
80 public function run(array $input, \ILIAS\BackgroundTasks\Observer $observer)
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 }
107
108
116 protected function calculateRecursive($object_wps_ids, &$a_file_size)
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 }
149
150
158 protected function validateAccess($wsp_id)
159 {
160 $ilAccess = new ilWorkspaceAccessHandler($this->tree);
161
162 if (!$ilAccess->checkAccess("read", "", $wsp_id)) {
163 return false;
164 }
165
166 return true;
167 }
168
169
174 {
175 return 30;
176 }
177}
An exception for terminatinating execution or to throw for unit testing.
getExpectedTimeOfTaskInSeconds()
int the amount of seconds this task usually taskes. If your task-duration scales with the the amount ...
calculateRecursive($object_wps_ids, &$a_file_size)
Calculates the number and size of the files being downloaded recursively.
run(array $input, \ILIAS\BackgroundTasks\Observer $observer)
@inheritDoc
static getLogger($a_component_id)
Get component logger.
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
ILIAS Setting Class.
Access handler for personal workspace.
Tree handler for personal workspace.
Class ChatMainBarProvider \MainMenu\Provider.
$type
settings()
Definition: settings.php:2
$DIC
Definition: xapitoken.php:46