Commit 8d7fa0b1 authored by Son Nguyen's avatar Son Nguyen Committed by Gerrit Code Review

Merge changes I1d99b883,I072e7d1b

* changes:
  Update quota notify limit alerts users if they are now over threshold
  Moving the upgrade call to be later (Bug #1367539)
parents 09183dd1 c0af3189
......@@ -43,11 +43,25 @@ $quotasform = pieform(array(
function groupquotasform_submit(Pieform $form, $values) {
global $SESSION;
$oldquota = get_field('group', 'quota', 'id', $values['groupid']);
$group = new StdClass;
$group->id = $values['groupid'];
$group->quota = $values['quota'];
update_record('group', $group);
if (!empty($values['quota']) && $values['quota'] != $oldquota) {
// We need to alert group admins that the group may now be over the threshold
$quotanotifylimit = get_config_plugin('artefact', 'file', 'quotanotifylimit');
$sqlwhere = " ((g.quotaused / g.quota) * 100) ";
if (is_postgres()) {
$sqlwhere = " ((CAST(g.quotaused AS float) / CAST(g.quota AS float)) * 100) ";
}
if ($groups = get_records_sql_assoc("SELECT g.id, g.name, g.quota, " . $sqlwhere . " AS quotausedpercent FROM {group} g WHERE " . $sqlwhere . " >= ? AND id = ?", array($quotanotifylimit, $values['groupid']))) {
require_once(get_config('docroot') . 'artefact/file/lib.php');
ArtefactTypeFile::notify_groups_threshold_exceeded($groups);
}
}
$SESSION->add_ok_msg(get_string('groupquotaupdated', 'admin'));
redirect(get_config('wwwroot').'admin/groups/groups.php');
}
......
......@@ -348,6 +348,26 @@ function edituser_site_submit(Pieform $form, $values) {
if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) {
$user->quota = $values['quota'];
// check if the user has gone over the quota notify limit
$quotanotifylimit = get_config_plugin('artefact', 'file', 'quotanotifylimit');
if ($quotanotifylimit <= 0 || $quotanotifylimit >= 100) {
$quotanotifylimit = 100;
}
$user->quotausedpercent = $user->quotaused / $user->quota * 100;
$overlimit = false;
if ($quotanotifylimit <= $user->quotausedpercent) {
$overlimit = true;
}
$notified = get_field('usr_account_preference', 'value', 'field', 'quota_exceeded_notified', 'usr', $user->id);
if ($overlimit && '1' !== $notified) {
require_once(get_config('docroot') . 'artefact/file/lib.php');
ArtefactTypeFile::notify_users_threshold_exceeded(array($user), false);
// no need to email admin as we can alert them right now
$SESSION->add_error_msg(get_string('useroverquotathreshold', 'artefact.file', display_name($user)));
}
else if ($notified && !$overlimit) {
set_account_preference($user->id, 'quota_exceeded_notified', false);
}
}
$unexpire = $user->expiry && strtotime($user->expiry) < time() && (empty($values['expiry']) || $values['expiry'] > time());
......
......@@ -768,6 +768,33 @@ function institution_submit(Pieform $form, $values) {
"UPDATE {usr} SET quota = ? WHERE id IN (SELECT usr FROM {usr_institution} WHERE institution = ?)",
array($values['defaultquota'], $institution)
);
// get all the users from the institution and make sure that they are still below
// their quota threshold
if ($users = get_records_sql_array('SELECT * FROM {usr} u LEFT JOIN {usr_institution} ui ON u.id = ui.usr AND ui.institution = ?', array($institution))) {
$quotanotifylimit = get_config_plugin('artefact', 'file', 'quotanotifylimit');
if ($quotanotifylimit <= 0 || $quotanotifylimit >= 100) {
$quotanotifylimit = 100;
}
foreach ($users as $user) {
$user->quota = $values['defaultquota'];
// check if the user has gone over the quota notify limit
$user->quotausedpercent = $user->quotaused / $user->quota * 100;
$overlimit = false;
if ($quotanotifylimit <= $user->quotausedpercent) {
$overlimit = true;
}
$notified = get_field('usr_account_preference', 'value', 'field', 'quota_exceeded_notified', 'usr', $user->id);
if ($overlimit && '1' !== $notified) {
require_once(get_config('docroot') . 'artefact/file/lib.php');
ArtefactTypeFile::notify_users_threshold_exceeded(array($user), false);
// no need to email admin as we can alert them right now
$SESSION->add_error_msg(get_string('useroverquotathreshold', 'artefact.file', display_name($user)));
}
else if ($notified && !$overlimit) {
set_account_preference($user->id, 'quota_exceeded_notified', false);
}
}
}
}
$newinstitution->defaultquota = empty($values['defaultquota']) ? get_config_plugin('artefact', 'file', 'defaultquota') : $values['defaultquota'];
}
......
......@@ -304,35 +304,6 @@ function xmldb_artefact_file_upgrade($oldversion=0) {
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/xml'), (object) array('mimetype' => 'application/xml', 'description' => 'xml'));
}
if ($oldversion < 2014041400) {
$events = array(
(object)array(
'plugin' => 'file',
'event' => 'saveartefact',
'callfunction' => 'eventlistener_savedeleteartefact',
),
(object)array(
'plugin' => 'file',
'event' => 'deleteartefact',
'callfunction' => 'eventlistener_savedeleteartefact',
),
(object)array(
'plugin' => 'file',
'event' => 'deleteartefacts',
'callfunction' => 'eventlistener_savedeleteartefact',
),
(object)array(
'plugin' => 'file',
'event' => 'updateuser',
'callfunction' => 'eventlistener_savedeleteartefact',
),
);
foreach ($events as $event) {
ensure_record_exists('artefact_event_subscription', $event, $event);
}
PluginArtefactFile::set_quota_triggers();
}
if ($oldversion < 2014051200) {
require_once(get_config('docroot') . '/lib/file.php');
$mimetypes = get_records_assoc('artefact_file_mime_types', '', '', '', 'description,mimetype');
......@@ -389,5 +360,45 @@ function xmldb_artefact_file_upgrade($oldversion=0) {
$rs->Close();
}
if ($oldversion < 2014060900) {
$events = array(
(object)array(
'plugin' => 'file',
'event' => 'saveartefact',
'callfunction' => 'eventlistener_savedeleteartefact',
),
(object)array(
'plugin' => 'file',
'event' => 'deleteartefact',
'callfunction' => 'eventlistener_savedeleteartefact',
),
(object)array(
'plugin' => 'file',
'event' => 'deleteartefacts',
'callfunction' => 'eventlistener_savedeleteartefact',
),
(object)array(
'plugin' => 'file',
'event' => 'updateuser',
'callfunction' => 'eventlistener_savedeleteartefact',
),
);
foreach ($events as $event) {
ensure_record_exists('artefact_event_subscription', $event, $event);
}
PluginArtefactFile::set_quota_triggers();
}
if ($oldversion < 2014061000) {
// Remove the not needed quota notify on update config trigger from previous update
if (is_postgres()) {
$sql = 'DROP TRIGGER IF EXISTS {unmark_quota_exeed_notified_on_update_setting_trigger} ON {artefact_config};';
}
else {
$sql = 'DROP TRIGGER IF EXISTS {unmark_quota_exeed_notified_on_update_setting_trigger};';
}
execute_sql($sql);
}
return $status;
}
......@@ -184,12 +184,15 @@ $string['quotanotifylimitoutofbounds'] = 'The notification limit is given in per
$string['usernotificationsubject'] = 'Your file storage is almost full';
$string['usernotificationmessage'] = 'You are using %s%% of your %s quota. You should get in touch with your site administrator about having your limit increased.';
$string['adm_notificationsubject'] = 'A user has nearly reached their file quota limit';
$string['adm_notificationmessage'] = 'User %s has reached %s%% percent of their %s quota. ';
$string['adm_notificationmessage'] = 'User %s has arrived at %s%% percent of their %s quota. ';
$string['adm_group_notificationsubject'] = 'A group that you administer has nearly reached their file quota limit';
$string['adm_group_notificationmessage'] = 'Group "%s" has arrived at %s%% percent of their %s quota. ';
$string['textlinktouser'] = 'Edit profile of %s';
$string['quotanotifylimittitle1'] = 'Quota notification threshold';
$string['quotanotifylimitdescr1'] = 'When a user\'s file upload quota is filled to this percentage, they (and the site administrators) will be sent a notification to let them know they are nearing their upload limit. They can then either delete files to free up space or contact their administrator to have their quota increased.';
$string['quotanotifyadmin1'] = 'Site administrator notification';
$string['quotanotifyadmindescr1'] = 'If checked, site administrators are notified when users reach the notification threshold.';
$string['useroverquotathreshold'] = 'User %s has arrived at %s%% percent of their %s quota. ';
// File types
$string['ai'] = 'Postscript document';
......
This diff is collapsed.
......@@ -12,5 +12,6 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2014051200;
$config->release = '1.2.2';
$config->version = 2014061000;
$config->release = '1.2.4';
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