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

Merge changes I252c5f76,I042c1127

* changes:
  Quota percent 'divide by zero' error (Bug 1393584)
  Fixing type checking on min/max values (Bug #1394732)
parents db85a8fe f6ff1d28
......@@ -108,7 +108,8 @@ if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionalo
'type' => 'bytes',
'title' => get_string('filequota1','admin'),
'description' => get_string('filequotadescription','admin') . '<br>' . $quotaused,
'rules' => array('integer' => true),
'rules' => array('integer' => true,
'minvalue' => 1),
'defaultvalue' => $user->quota,
);
}
......@@ -353,7 +354,7 @@ function edituser_site_submit(Pieform $form, $values) {
if ($quotanotifylimit <= 0 || $quotanotifylimit >= 100) {
$quotanotifylimit = 100;
}
$user->quotausedpercent = $user->quotaused / $user->quota * 100;
$user->quotausedpercent = empty($user->quota) ? 0 : ($user->quotaused / $user->quota) * 100;
$overlimit = false;
if ($quotanotifylimit <= $user->quotausedpercent) {
$overlimit = true;
......
......@@ -437,8 +437,7 @@ class PluginArtefactFile extends PluginArtefact {
if ($userid !== null) {
$userdata = get_user($userid);
$userdata->quotausedpercent = ($userdata->quotaused + $filesize ) / $userdata->quota * 100;
$userdata->quotausedpercent = empty($userdata->quota) ? 0 : (($userdata->quotaused + $filesize ) / $userdata->quota) * 100;
$overlimit = false;
if ($quotanotifylimit <= $userdata->quotausedpercent) {
$overlimit = true;
......@@ -457,7 +456,7 @@ class PluginArtefactFile extends PluginArtefact {
else if ($group !== null) {
$groupdata = get_record('group', 'id', $group);
$groupdata->quotausedpercent = ($groupdata->quotaused + $filesize ) / $groupdata->quota * 100;
$groupdata->quotausedpercent = empty($groupdata->quota) ? 0 : (($groupdata->quotaused + $filesize ) / $groupdata->quota) * 100;
$overlimit = false;
if ($quotanotifylimit <= $groupdata->quotausedpercent) {
$overlimit = true;
......
......@@ -34,7 +34,7 @@
* @return string The error message, if the value is invalid.
*/
function pieform_rule_maxvalue(Pieform $form, $value, $element, $maxvalue) {/*{{{*/
if ($value != '' && doubleval($value) > $maxvalue) {
if ($value !== '' && doubleval($value) > $maxvalue) {
return sprintf($form->i18n('rule', 'maxvalue', 'maxvalue', $element), $maxvalue);
}
}/*}}}*/
......@@ -34,7 +34,7 @@
* @return string The error message, if the value is invalid.
*/
function pieform_rule_minvalue(Pieform $form, $value, $element, $minvalue) {/*{{{*/
if ($value != '' && doubleval($value) < $minvalue) {
if ($value !== '' && doubleval($value) < $minvalue) {
return sprintf($form->i18n('rule', 'minvalue', 'minvalue', $element), $minvalue);
}
}/*}}}*/
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