Commit 1db00872 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Better error handling when copying a view exceeds file quota

parent bbf747c6
......@@ -292,6 +292,7 @@ $string['Preview'] = 'Preview';
$string['viewscopiedfornewusersmustbecopyable'] = 'You must allow copying before you can set a view to be copied for new users.';
$string['viewscopiedfornewgroupsmustbecopyable'] = 'You must allow copying before you can set a view to be copied for new groups.';
$string['copynewusergroupneedsloggedinaccess'] = 'Views copied for new users or groups must give access to logged-in users.';
$string['viewcopywouldexceedquota'] = 'Copying this View would exceed your file quota.';
$string['blockcopypermission'] = 'Block copy permission';
$string['blockcopypermissiondesc'] = 'If you allow other users to copy this View, you may choose how this block will be copied';
......
......@@ -168,7 +168,14 @@ class View {
$view->set('title', self::new_title(get_string('Copyof', 'mahara', $template->get('title')), (object)$viewdata));
$view->set('dirty', true);
}
$copystatus = $view->copy_contents($template);
try {
$copystatus = $view->copy_contents($template);
}
catch (QuotaExceededException $e) {
db_rollback();
return array(null, $template, array('quotaexceeded' => true));
}
$view->commit();
db_commit();
......@@ -2437,6 +2444,10 @@ function createview_submit(Pieform $form, $values) {
$templateid = $values['usetemplate'];
unset($values['usetemplate']);
list($view, $template, $copystatus) = View::create_from_template($values, $templateid);
if (isset($copystatus['quotaexceeded'])) {
$SESSION->add_error_msg(get_string('viewcopywouldexceedquota', 'view'));
redirect(get_config('wwwroot') . 'view/choosetemplate.php');
}
$SESSION->add_ok_msg(get_string('copiedblocksandartefactsfromtemplate', 'view',
$copystatus['blocks'],
$copystatus['artefacts'],
......
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