Commit fa192d3a authored by Hugh Davenport's avatar Hugh Davenport
Browse files

Add group quota recalculate to existing cron entry



Add a recalculate_group_quota function in the same way existing quotas do it
This allows other plugins to add to the quota as well.

Change-Id: I781c1c421ae13fb0950b29d7beec86d256c24d86
Signed-off-by: default avatarHugh Davenport <hugh@catalyst.net.nz>
parent 09cdc0f0
......@@ -276,6 +276,20 @@ class PluginArtefactFile extends PluginArtefact {
}
return array();
}
public static function recalculate_group_quota() {
$data = get_records_sql_assoc("
SELECT a.group, SUM(f.size) AS bytes
FROM {artefact} a JOIN {artefact_file_files} f ON a.id = f.artefact
WHERE a.artefacttype IN ('file', 'image', 'profileicon', 'archive')
AND a.group IS NOT NULL
GROUP BY a.group", array()
);
if ($data) {
return array_map(create_function('$a', 'return $a->bytes;'), $data);
}
return array();
}
}
abstract class ArtefactTypeFileBase extends ArtefactType {
......
......@@ -2464,6 +2464,7 @@ function recalculate_quota() {
$plugins = plugins_installed('artefact', true);
$userquotas = array();
$groupquotas = array();
foreach ($plugins as $plugin) {
safe_require('artefact', $plugin->name);
......@@ -2479,6 +2480,17 @@ function recalculate_quota() {
}
}
}
if (is_callable($classname . '::recalculate_group_quota')) {
$plugingroupquotas = call_static_method($classname, 'recalculate_group_quota');
foreach ($plugingroupquotas as $groupid => $usage) {
if (!isset($groupquotas[$groupid])) {
$groupquotas[$groupid] = $usage;
}
else {
$groupquotas[$groupid] += $usage;
}
}
}
}
foreach ($userquotas as $user => $quota) {
......@@ -2490,6 +2502,16 @@ function recalculate_quota() {
);
update_record('usr', $data, $where);
}
foreach ($groupquotas as $group => $quota) {
$data = (object) array(
'quotaused' => $quota
);
$where = (object) array(
'id' => $group
);
update_record('group', $data, $where);
}
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment