diff --git a/admin/auth.php b/admin/auth.php
index f501ed7c07acd..a5a88a9d9b2be 100644
--- a/admin/auth.php
+++ b/admin/auth.php
@@ -28,7 +28,7 @@
}
if (!empty($auth) and !exists_auth_plugin($auth)) {
- print_error('pluginnotinstalled', 'auth', $returnurl, $auth);
+ throw new \moodle_exception('pluginnotinstalled', 'auth', $returnurl, $auth);
}
////////////////////////////////////////////////////////////////////////////////
@@ -55,7 +55,7 @@
$key = array_search($auth, $authsenabled);
// check auth plugin is valid
if ($key === false) {
- print_error('pluginnotenabled', 'auth', $returnurl, $auth);
+ throw new \moodle_exception('pluginnotenabled', 'auth', $returnurl, $auth);
}
// move down the list
if ($key < (count($authsenabled) - 1)) {
@@ -72,7 +72,7 @@
$key = array_search($auth, $authsenabled);
// check auth is valid
if ($key === false) {
- print_error('pluginnotenabled', 'auth', $returnurl, $auth);
+ throw new \moodle_exception('pluginnotenabled', 'auth', $returnurl, $auth);
}
// move up the list
if ($key >= 1) {
diff --git a/admin/blocks.php b/admin/blocks.php
index 00132cc855b35..19f5829a704e5 100644
--- a/admin/blocks.php
+++ b/admin/blocks.php
@@ -75,7 +75,7 @@
/// Get and sort the existing blocks
if (!$blocks = $DB->get_records('block', array(), 'name ASC')) {
- print_error('noblocks', 'error'); // Should never happen
+ throw new \moodle_exception('noblocks', 'error'); // Should never happen.
}
$incompatible = array();
diff --git a/admin/category.php b/admin/category.php
index e11507a218a1d..fb37fa1d7e0aa 100644
--- a/admin/category.php
+++ b/admin/category.php
@@ -41,11 +41,11 @@
$settingspage = $adminroot->locate($category, true);
if (empty($settingspage) or !($settingspage instanceof admin_category)) {
- print_error('categoryerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
+ throw new \moodle_exception('categoryerror', 'error', "$CFG->wwwroot/$CFG->admin/");
}
if (!($settingspage->check_access())) {
- print_error('accessdenied', 'admin');
+ throw new \moodle_exception('accessdenied', 'admin');
}
$hassiteconfig = has_capability('moodle/site:config', $PAGE->context);
diff --git a/admin/cli/restore_backup.php b/admin/cli/restore_backup.php
index 6f5de424995a6..46eccb2db4fba 100644
--- a/admin/cli/restore_backup.php
+++ b/admin/cli/restore_backup.php
@@ -69,15 +69,15 @@
}
if (!$admin = get_admin()) {
- print_error('noadmins');
+ throw new \moodle_exception('noadmins');
}
if (!file_exists($options['file'])) {
- print_error('filenotfound');
+ throw new \moodle_exception('filenotfound');
}
if (!$category = $DB->get_record('course_categories', ['id' => $options['categoryid']], 'id')) {
- print_error('invalidcategoryid');
+ throw new \moodle_exception('invalidcategoryid');
}
$backupdir = "restore_" . uniqid();
@@ -102,7 +102,7 @@
} catch (Exception $e) {
cli_heading(get_string('cleaningtempdata'));
fulldelete($path);
- print_error('generalexceptionmessage', 'error', '', $e->getMessage());
+ throw new \moodle_exception('generalexceptionmessage', 'error', '', $e->getMessage());
}
cli_heading(get_string('restoredcourseid', 'backup', $courseid));
diff --git a/admin/contentbank.php b/admin/contentbank.php
index 95a7c4328b89c..98514e2204a00 100644
--- a/admin/contentbank.php
+++ b/admin/contentbank.php
@@ -42,7 +42,7 @@
$sortorder = array_flip(array_keys($plugins));
if (!isset($plugins[$name])) {
- print_error('contenttypenotfound', 'error', $return, $name);
+ throw new \moodle_exception('contenttypenotfound', 'error', $return, $name);
}
switch ($action) {
diff --git a/admin/courseformats.php b/admin/courseformats.php
index 6cf30bd753828..95d40b164ba45 100644
--- a/admin/courseformats.php
+++ b/admin/courseformats.php
@@ -41,7 +41,7 @@
$sortorder = array_flip(array_keys($formatplugins));
if (!isset($formatplugins[$formatname])) {
- print_error('courseformatnotfound', 'error', $return, $formatname);
+ throw new \moodle_exception('courseformatnotfound', 'error', $return, $formatname);
}
switch ($action) {
diff --git a/admin/cron.php b/admin/cron.php
index ed19d46360e8b..df009e255b296 100644
--- a/admin/cron.php
+++ b/admin/cron.php
@@ -58,7 +58,7 @@
// check if execution allowed
if (!empty($CFG->cronclionly)) {
// This script can only be run via the cli.
- print_error('cronerrorclionly', 'admin');
+ throw new \moodle_exception('cronerrorclionly', 'admin');
exit;
}
// This script is being called via the web, so check the password if there is one.
@@ -66,7 +66,7 @@
$pass = optional_param('password', '', PARAM_RAW);
if ($pass != $CFG->cronremotepassword) {
// wrong password.
- print_error('cronerrorpassword', 'admin');
+ throw new \moodle_exception('cronerrorpassword', 'admin');
exit;
}
}
diff --git a/admin/customfields.php b/admin/customfields.php
index 38f917a1ccd14..aa80fd9222e54 100644
--- a/admin/customfields.php
+++ b/admin/customfields.php
@@ -41,7 +41,7 @@
$sortorder = array_flip(array_keys($customfieldplugins));
if (!isset($customfieldplugins[$customfieldname])) {
- print_error('customfieldnotfound', 'error', $return, $customfieldname);
+ throw new \moodle_exception('customfieldnotfound', 'error', $return, $customfieldname);
}
switch ($action) {
diff --git a/admin/dataformats.php b/admin/dataformats.php
index 15c9cf8b0cbb1..26ba215667ca1 100644
--- a/admin/dataformats.php
+++ b/admin/dataformats.php
@@ -42,7 +42,7 @@
$sortorder = array_flip(array_keys($plugins));
if (!isset($plugins[$name])) {
- print_error('courseformatnotfound', 'error', $return, $name);
+ throw new \moodle_exception('courseformatnotfound', 'error', $return, $name);
}
switch ($action) {
diff --git a/admin/environment.php b/admin/environment.php
index 0237e600dfa2b..b1072b3f997a1 100644
--- a/admin/environment.php
+++ b/admin/environment.php
@@ -55,11 +55,11 @@
$a = new stdClass();
$a->url = 'https://download.moodle.org/environment/environment.zip';
$a->dest = $CFG->dataroot . '/';
- print_error($cd->get_error(), 'error', $PAGE->url, $a);
+ throw new \moodle_exception($cd->get_error(), 'error', $PAGE->url, $a);
die();
} else {
- print_error($cd->get_error(), 'error', $PAGE->url);
+ throw new \moodle_exception($cd->get_error(), 'error', $PAGE->url);
die();
}
diff --git a/admin/index.php b/admin/index.php
index 9732be58ddfe4..27f474bae90ca 100644
--- a/admin/index.php
+++ b/admin/index.php
@@ -174,15 +174,17 @@
// Check some PHP server settings
if (ini_get_bool('session.auto_start')) {
- print_error('phpvaroff', 'debug', '', (object)array('name'=>'session.auto_start', 'link'=>$documentationlink));
+ throw new \moodle_exception('phpvaroff', 'debug', '',
+ (object)array('name' => 'session.auto_start', 'link' => $documentationlink));
}
if (!ini_get_bool('file_uploads')) {
- print_error('phpvaron', 'debug', '', (object)array('name'=>'file_uploads', 'link'=>$documentationlink));
+ throw new \moodle_exception('phpvaron', 'debug', '',
+ (object)array('name' => 'file_uploads', 'link' => $documentationlink));
}
if (is_float_problem()) {
- print_error('phpfloatproblem', 'admin', '', $documentationlink);
+ throw new \moodle_exception('phpfloatproblem', 'admin', '', $documentationlink);
}
// Set some necessary variables during set-up to avoid PHP warnings later on this page
@@ -203,7 +205,7 @@
$CFG->target_release = $release; // used during installation and upgrades
if (!$version or !$release) {
- print_error('withoutversion', 'debug'); // without version, stop
+ throw new \moodle_exception('withoutversion', 'debug'); // Without version, stop.
}
if (!core_tables_exist()) {
@@ -275,7 +277,7 @@
if (!$DB->setup_is_unicodedb()) {
if (!$DB->change_db_encoding()) {
// If could not convert successfully, throw error, and prevent installation
- print_error('unicoderequired', 'admin');
+ throw new \moodle_exception('unicoderequired', 'admin');
}
}
@@ -297,7 +299,7 @@
$PAGE->set_context(context_system::instance());
if (empty($CFG->version)) {
- print_error('missingconfigversion', 'debug');
+ throw new \moodle_exception('missingconfigversion', 'debug');
}
// Detect config cache inconsistency, this happens when you switch branches on dev servers.
@@ -748,7 +750,7 @@
redirect("index.php?sessionstarted=1&sessionverify=1&lang=$CFG->lang");
} else {
if (empty($SESSION->sessionverify)) {
- print_error('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang");
+ throw new \moodle_exception('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang");
}
unset($SESSION->sessionverify);
}
@@ -765,7 +767,7 @@
if ($adminuser->password === 'adminsetuppending') {
// prevent installation hijacking
if ($adminuser->lastip !== getremoteaddr()) {
- print_error('installhijacked', 'admin');
+ throw new \moodle_exception('installhijacked', 'admin');
}
// login user and let him set password and admin details
$adminuser->newadminuser = 1;
diff --git a/admin/mnet/access_control.php b/admin/mnet/access_control.php
index edb3b06d32211..c93dc069d7d9a 100644
--- a/admin/mnet/access_control.php
+++ b/admin/mnet/access_control.php
@@ -15,7 +15,7 @@
admin_externalpage_setup('ssoaccesscontrol');
if (!extension_loaded('openssl')) {
- print_error('requiresopenssl', 'mnet');
+ throw new \moodle_exception('requiresopenssl', 'mnet');
}
$sitecontext = context_system::instance();
@@ -35,13 +35,13 @@
// boot if insufficient permission
if (!has_capability('moodle/user:delete', $sitecontext)) {
- print_error('nomodifyacl','mnet');
+ throw new \moodle_exception('nomodifyacl', 'mnet');
}
// fetch the record in question
$id = required_param('id', PARAM_INT);
if (!$idrec = $DB->get_record('mnet_sso_access_control', array('id'=>$id))) {
- print_error('recordnoexists','mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
+ throw new \moodle_exception('recordnoexists', 'mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
}
switch ($action) {
@@ -56,7 +56,7 @@
// require the access parameter, and it must be 'allow' or 'deny'
$accessctrl = trim(strtolower(required_param('accessctrl', PARAM_ALPHA)));
if ($accessctrl != 'allow' and $accessctrl != 'deny') {
- print_error('invalidaccessparam', 'mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
+ throw new \moodle_exception('invalidaccessparam', 'mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
}
if (mnet_update_sso_access_control($idrec->username, $idrec->mnet_host_id, $accessctrl)) {
@@ -71,7 +71,7 @@
break;
default:
- print_error('invalidactionparam', 'mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
+ throw new \moodle_exception('invalidactionparam', 'mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
}
}
@@ -82,7 +82,7 @@
// check permissions and verify form input
if (!has_capability('moodle/user:delete', $sitecontext)) {
- print_error('nomodifyacl','mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
+ throw new \moodle_exception('nomodifyacl', 'mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
}
if (empty($form->username)) {
$formerror['username'] = get_string('enterausername','mnet');
diff --git a/admin/mnet/index.php b/admin/mnet/index.php
index 5e0240b858244..11a9967c41cc7 100644
--- a/admin/mnet/index.php
+++ b/admin/mnet/index.php
@@ -17,13 +17,13 @@
if (!extension_loaded('openssl')) {
echo $OUTPUT->header();
set_config('mnet_dispatcher_mode', 'off');
- print_error('requiresopenssl', 'mnet');
+ throw new \moodle_exception('requiresopenssl', 'mnet');
}
if (!function_exists('curl_init') ) {
echo $OUTPUT->header();
set_config('mnet_dispatcher_mode', 'off');
- print_error('nocurl', 'mnet');
+ throw new \moodle_exception('nocurl', 'mnet');
}
if (!isset($CFG->mnet_dispatcher_mode)) {
@@ -37,7 +37,7 @@
if (set_config('mnet_dispatcher_mode', $form->mode)) {
redirect('index.php', get_string('changessaved'));
} else {
- print_error('invalidaction', '', 'index.php');
+ throw new \moodle_exception('invalidaction', '', 'index.php');
}
}
} elseif (!empty($form->submit) && $form->submit == get_string('delete')) {
@@ -63,13 +63,13 @@
if($time < time() - 60) {
// fail - you're out of time.
- print_error ('deleteoutoftime', 'mnet', 'index.php');
+ throw new \moodle_exception ('deleteoutoftime', 'mnet', 'index.php');
exit;
}
if ($key != md5(sha1($mnet->keypair['keypair_PEM']))) {
// fail - you're being attacked?
- print_error ('deletewrongkeyvalue', 'mnet', 'index.php');
+ throw new \moodle_exception ('deletewrongkeyvalue', 'mnet', 'index.php');
exit;
}
diff --git a/admin/mnet/peers.php b/admin/mnet/peers.php
index 348a6243f867f..b9313e5701d36 100644
--- a/admin/mnet/peers.php
+++ b/admin/mnet/peers.php
@@ -54,15 +54,15 @@
$deprecatenotify = mnet_get_deprecation_notice();
if (!extension_loaded('openssl')) {
- print_error('requiresopenssl', 'mnet');
+ throw new \moodle_exception('requiresopenssl', 'mnet');
}
if (!function_exists('curl_init') ) {
- print_error('nocurl', 'mnet');
+ throw new \moodle_exception('nocurl', 'mnet');
}
if (!function_exists('xmlrpc_encode_request')) {
- print_error('xmlrpc-missing', 'mnet');
+ throw new \moodle_exception('xmlrpc-missing', 'mnet');
}
if (!isset($CFG->mnet_dispatcher_mode)) {
@@ -176,7 +176,7 @@
if ($mnet_peer->commit()) {
redirect(new moodle_url('/admin/mnet/peers.php', array('hostid' => $mnet_peer->id)), get_string('changessaved'));
} else {
- print_error('invalidaction', 'error', 'index.php');
+ throw new \moodle_exception('invalidaction', 'error', 'index.php');
}
} else if ($reviewform->is_submitted()) { // submitted, but errors
echo $OUTPUT->header();
diff --git a/admin/mnet/testclient.php b/admin/mnet/testclient.php
index a12ebb6b71fdb..f370866b0b8b9 100644
--- a/admin/mnet/testclient.php
+++ b/admin/mnet/testclient.php
@@ -18,7 +18,7 @@
include_once($CFG->dirroot.'/mnet/lib.php');
if ($CFG->mnet_dispatcher_mode === 'off') {
- print_error('mnetdisabled', 'mnet');
+ throw new \moodle_exception('mnetdisabled', 'mnet');
}
admin_externalpage_setup('mnettestclient');
@@ -27,7 +27,7 @@
echo $OUTPUT->header();
if (!extension_loaded('openssl')) {
- print_error('requiresopenssl', 'mnet', '', NULL, true);
+ throw new \moodle_exception('requiresopenssl', 'mnet', '', null, true);
}
// optional drilling down parameters
diff --git a/admin/mnet/trustedhosts.php b/admin/mnet/trustedhosts.php
index 5ad348c3b5cac..c72ed8c841f3a 100644
--- a/admin/mnet/trustedhosts.php
+++ b/admin/mnet/trustedhosts.php
@@ -10,7 +10,7 @@
if (!extension_loaded('openssl')) {
echo $OUTPUT->header();
- print_error('requiresopenssl', 'mnet', '', NULL, true);
+ throw new \moodle_exception('requiresopenssl', 'mnet', '', null, true);
}
$site = get_site();
diff --git a/admin/modules.php b/admin/modules.php
index 3a17cf5b78027..b5e61fa276322 100644
--- a/admin/modules.php
+++ b/admin/modules.php
@@ -62,7 +62,7 @@
/// Get and sort the existing modules
if (!$modules = $DB->get_records('modules', array(), 'name ASC')) {
- print_error('moduledoesnotexist', 'error');
+ throw new \moodle_exception('moduledoesnotexist', 'error');
}
/// Print the table of all modules
diff --git a/admin/portfolio.php b/admin/portfolio.php
index 1d5eb691c7943..08939c173d578 100644
--- a/admin/portfolio.php
+++ b/admin/portfolio.php
@@ -116,13 +116,13 @@ function portfolio_action_url($portfolio) {
$instance = portfolio_instance($portfolio);
if ($sure) {
if (!confirm_sesskey()) {
- print_error('confirmsesskeybad', '', $baseurl);
+ throw new \moodle_exception('confirmsesskeybad', '', $baseurl);
}
if ($instance->delete()) {
$deletedstr = get_string('instancedeleted', 'portfolio');
redirect($baseurl, $deletedstr, 1);
} else {
- print_error('instancenotdeleted', 'portfolio', $baseurl);
+ throw new \moodle_exception('instancenotdeleted', 'portfolio', $baseurl);
}
exit;
} else {
diff --git a/admin/qbehaviours.php b/admin/qbehaviours.php
index e8b87b712b3ff..d047669b92201 100644
--- a/admin/qbehaviours.php
+++ b/admin/qbehaviours.php
@@ -84,7 +84,7 @@
// Disable.
if (($disable = optional_param('disable', '', PARAM_PLUGIN)) && confirm_sesskey()) {
if (!isset($behaviours[$disable])) {
- print_error('unknownbehaviour', 'question', $thispageurl, $disable);
+ throw new \moodle_exception('unknownbehaviour', 'question', $thispageurl, $disable);
}
if (array_search($disable, $disabledbehaviours) === false) {
@@ -97,11 +97,11 @@
// Enable.
if (($enable = optional_param('enable', '', PARAM_PLUGIN)) && confirm_sesskey()) {
if (!isset($behaviours[$enable])) {
- print_error('unknownbehaviour', 'question', $thispageurl, $enable);
+ throw new \moodle_exception('unknownbehaviour', 'question', $thispageurl, $enable);
}
if (!$archetypal[$enable]) {
- print_error('cannotenablebehaviour', 'question', $thispageurl, $enable);
+ throw new \moodle_exception('cannotenablebehaviour', 'question', $thispageurl, $enable);
}
if (($key = array_search($enable, $disabledbehaviours)) !== false) {
@@ -114,7 +114,7 @@
// Move up in order.
if (($up = optional_param('up', '', PARAM_PLUGIN)) && confirm_sesskey()) {
if (!isset($behaviours[$up])) {
- print_error('unknownbehaviour', 'question', $thispageurl, $up);
+ throw new \moodle_exception('unknownbehaviour', 'question', $thispageurl, $up);
}
// This function works fine for behaviours, as well as qtypes.
@@ -126,7 +126,7 @@
// Move down in order.
if (($down = optional_param('down', '', PARAM_PLUGIN)) && confirm_sesskey()) {
if (!isset($behaviours[$down])) {
- print_error('unknownbehaviour', 'question', $thispageurl, $down);
+ throw new \moodle_exception('unknownbehaviour', 'question', $thispageurl, $down);
}
// This function works fine for behaviours, as well as qtypes.
diff --git a/admin/qtypes.php b/admin/qtypes.php
index f469eac0e46e7..7f0714feeb77c 100644
--- a/admin/qtypes.php
+++ b/admin/qtypes.php
@@ -106,7 +106,7 @@
// Disable.
if (($disable = optional_param('disable', '', PARAM_PLUGIN)) && confirm_sesskey()) {
if (!isset($qtypes[$disable])) {
- print_error('unknownquestiontype', 'question', $thispageurl, $disable);
+ throw new \moodle_exception('unknownquestiontype', 'question', $thispageurl, $disable);
}
$class = \core_plugin_manager::resolve_plugininfo_class('qtype');
@@ -117,11 +117,11 @@
// Enable.
if (($enable = optional_param('enable', '', PARAM_PLUGIN)) && confirm_sesskey()) {
if (!isset($qtypes[$enable])) {
- print_error('unknownquestiontype', 'question', $thispageurl, $enable);
+ throw new \moodle_exception('unknownquestiontype', 'question', $thispageurl, $enable);
}
if (!$qtypes[$enable]->menu_name()) {
- print_error('cannotenable', 'question', $thispageurl, $enable);
+ throw new \moodle_exception('cannotenable', 'question', $thispageurl, $enable);
}
$class = \core_plugin_manager::resolve_plugininfo_class('qtype');
@@ -132,7 +132,7 @@
// Move up in order.
if (($up = optional_param('up', '', PARAM_PLUGIN)) && confirm_sesskey()) {
if (!isset($qtypes[$up])) {
- print_error('unknownquestiontype', 'question', $thispageurl, $up);
+ throw new \moodle_exception('unknownquestiontype', 'question', $thispageurl, $up);
}
$neworder = question_reorder_qtypes($sortedqtypes, $up, -1);
@@ -143,7 +143,7 @@
// Move down in order.
if (($down = optional_param('down', '', PARAM_PLUGIN)) && confirm_sesskey()) {
if (!isset($qtypes[$down])) {
- print_error('unknownquestiontype', 'question', $thispageurl, $down);
+ throw new \moodle_exception('unknownquestiontype', 'question', $thispageurl, $down);
}
$neworder = question_reorder_qtypes($sortedqtypes, $down, +1);
diff --git a/admin/repository.php b/admin/repository.php
index cf8143480e680..735cbdbca267b 100644
--- a/admin/repository.php
+++ b/admin/repository.php
@@ -152,7 +152,7 @@ function repository_action_url($repository) {
core_plugin_manager::reset_caches();
redirect($baseurl);
} else {
- print_error('instancenotsaved', 'repository', $baseurl);
+ throw new \moodle_exception('instancenotsaved', 'repository', $baseurl);
}
exit;
} else {
@@ -183,14 +183,14 @@ function repository_action_url($repository) {
}
} else if ($action == 'show') {
if (!confirm_sesskey()) {
- print_error('confirmsesskeybad', '', $baseurl);
+ throw new \moodle_exception('confirmsesskeybad', '', $baseurl);
}
$class = \core_plugin_manager::resolve_plugininfo_class('repository');
$class::enable_plugin($repository, 1);
$return = true;
} else if ($action == 'hide') {
if (!confirm_sesskey()) {
- print_error('confirmsesskeybad', '', $baseurl);
+ throw new \moodle_exception('confirmsesskeybad', '', $baseurl);
}
$class = \core_plugin_manager::resolve_plugininfo_class('repository');
$class::enable_plugin($repository, 0);
@@ -200,7 +200,7 @@ function repository_action_url($repository) {
if ($sure) {
$PAGE->set_pagetype('admin-repository-' . $repository);
if (!confirm_sesskey()) {
- print_error('confirmsesskeybad', '', $baseurl);
+ throw new \moodle_exception('confirmsesskeybad', '', $baseurl);
}
if ($repositorytype->delete($downloadcontents)) {
@@ -209,7 +209,7 @@ function repository_action_url($repository) {
core_plugin_manager::reset_caches();
redirect($baseurl);
} else {
- print_error('instancenotdeleted', 'repository', $baseurl);
+ throw new \moodle_exception('instancenotdeleted', 'repository', $baseurl);
}
exit;
} else {
diff --git a/admin/repositoryinstance.php b/admin/repositoryinstance.php
index 70202247f984c..e7b9c77ed1e2a 100644
--- a/admin/repositoryinstance.php
+++ b/admin/repositoryinstance.php
@@ -104,7 +104,7 @@
core_plugin_manager::reset_caches();
redirect($parenturl);
} else {
- print_error('instancenotsaved', 'repository', $parenturl);
+ throw new \moodle_exception('instancenotsaved', 'repository', $parenturl);
}
exit;
} else {
@@ -134,7 +134,7 @@
core_plugin_manager::reset_caches();
redirect($parenturl, $deletedstr, 3);
} else {
- print_error('instancenotdeleted', 'repository', $parenturl);
+ throw new \moodle_exception('instancenotdeleted', 'repository', $parenturl);
}
exit;
}
diff --git a/admin/roles/allow.php b/admin/roles/allow.php
index 824cfa81cca39..3447df48c78a0 100644
--- a/admin/roles/allow.php
+++ b/admin/roles/allow.php
@@ -33,7 +33,7 @@
'view' => 'core_role_allow_view_page'
);
if (!isset($classformode[$mode])) {
- print_error('invalidmode', '', '', $mode);
+ throw new \moodle_exception('invalidmode', '', '', $mode);
}
$baseurl = new moodle_url('/admin/roles/allow.php', array('mode'=>$mode));
diff --git a/admin/roles/assign.php b/admin/roles/assign.php
index 4dcc69b079b2c..42b5e8e5d7cf4 100644
--- a/admin/roles/assign.php
+++ b/admin/roles/assign.php
@@ -75,7 +75,7 @@
$a = new stdClass;
$a->roleid = $roleid;
$a->context = $contextname;
- print_error('cannotassignrolehere', '', $context->get_url(), $a);
+ throw new \moodle_exception('cannotassignrolehere', '', $context->get_url(), $a);
}
// Work out an appropriate page title.
diff --git a/admin/roles/check.php b/admin/roles/check.php
index 23680f7f14185..847898cb5f725 100644
--- a/admin/roles/check.php
+++ b/admin/roles/check.php
@@ -48,7 +48,7 @@
// Security first.
require_login($course, false, $cm);
if (!has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:manage'), $context)) {
- print_error('nopermissions', 'error', '', get_string('checkpermissions', 'core_role'));
+ throw new \moodle_exception('nopermissions', 'error', '', get_string('checkpermissions', 'core_role'));
}
navigation_node::override_active_url($url);
diff --git a/admin/roles/manage.php b/admin/roles/manage.php
index ad35a1cf9368e..d8d8ba77175cb 100644
--- a/admin/roles/manage.php
+++ b/admin/roles/manage.php
@@ -68,7 +68,7 @@
switch ($action) {
case 'delete':
if (isset($undeletableroles[$roleid])) {
- print_error('cannotdeletethisrole', '', $baseurl);
+ throw new \moodle_exception('cannotdeletethisrole', '', $baseurl);
}
if (!$confirmed) {
// Show confirmation.
@@ -89,7 +89,7 @@
}
if (!delete_role($roleid)) {
// The delete failed.
- print_error('cannotdeleterolewithid', 'error', $baseurl, $roleid);
+ throw new \moodle_exception('cannotdeleterolewithid', 'error', $baseurl, $roleid);
}
// Deleted a role sitewide...
redirect($baseurl);
@@ -108,10 +108,10 @@
}
}
if (is_null($thisrole) || is_null($prevrole)) {
- print_error('cannotmoverolewithid', 'error', '', $roleid);
+ throw new \moodle_exception('cannotmoverolewithid', 'error', '', $roleid);
}
if (!switch_roles($thisrole, $prevrole)) {
- print_error('cannotmoverolewithid', 'error', '', $roleid);
+ throw new \moodle_exception('cannotmoverolewithid', 'error', '', $roleid);
}
}
@@ -131,10 +131,10 @@
}
}
if (is_null($nextrole)) {
- print_error('cannotmoverolewithid', 'error', '', $roleid);
+ throw new \moodle_exception('cannotmoverolewithid', 'error', '', $roleid);
}
if (!switch_roles($thisrole, $nextrole)) {
- print_error('cannotmoverolewithid', 'error', '', $roleid);
+ throw new \moodle_exception('cannotmoverolewithid', 'error', '', $roleid);
}
}
diff --git a/admin/roles/override.php b/admin/roles/override.php
index e676a4a08aef8..68a02c4a66ddd 100644
--- a/admin/roles/override.php
+++ b/admin/roles/override.php
@@ -93,7 +93,7 @@
$PAGE->navbar->add($straction);
switch ($context->contextlevel) {
case CONTEXT_SYSTEM:
- print_error('cannotoverridebaserole', 'error');
+ throw new \moodle_exception('cannotoverridebaserole', 'error');
break;
case CONTEXT_USER:
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
@@ -124,7 +124,7 @@
$a = new stdClass;
$a->roleid = $roleid;
$a->context = $contextname;
- print_error('cannotoverriderolehere', '', $context->get_url(), $a);
+ throw new \moodle_exception('cannotoverriderolehere', '', $context->get_url(), $a);
}
// If we are actually overriding a role, create the table object, and save changes if appropriate.
diff --git a/admin/roles/permissions.php b/admin/roles/permissions.php
index 0a2bd3cd57135..2944d2b438a57 100644
--- a/admin/roles/permissions.php
+++ b/admin/roles/permissions.php
@@ -100,7 +100,7 @@
$PAGE->activityheader->disable();
switch ($context->contextlevel) {
case CONTEXT_SYSTEM:
- print_error('cannotoverridebaserole', 'error');
+ throw new \moodle_exception('cannotoverridebaserole', 'error');
break;
case CONTEXT_USER:
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
diff --git a/admin/roles/usersroles.php b/admin/roles/usersroles.php
index 362c4297a12f1..9370bfb64d073 100644
--- a/admin/roles/usersroles.php
+++ b/admin/roles/usersroles.php
@@ -55,7 +55,7 @@
$canview = has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride',
'moodle/role:override', 'moodle/role:manage'), $usercontext);
if (!$canview) {
- print_error('nopermissions', 'error', '', get_string('checkpermissions', 'core_role'));
+ throw new \moodle_exception('nopermissions', 'error', '', get_string('checkpermissions', 'core_role'));
}
if ($userid != $USER->id) {
diff --git a/admin/settings.php b/admin/settings.php
index 19e3acde1b8a6..30c61121b2347 100644
--- a/admin/settings.php
+++ b/admin/settings.php
@@ -23,13 +23,13 @@
if (moodle_needs_upgrading()) {
redirect(new moodle_url('/admin/index.php'));
} else {
- print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
+ throw new \moodle_exception('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
}
die;
}
if (!($settingspage->check_access())) {
- print_error('accessdenied', 'admin');
+ throw new \moodle_exception('accessdenied', 'admin');
die;
}
diff --git a/admin/tool/availabilityconditions/index.php b/admin/tool/availabilityconditions/index.php
index ff18a7211baf4..7ddb049f93a0c 100644
--- a/admin/tool/availabilityconditions/index.php
+++ b/admin/tool/availabilityconditions/index.php
@@ -47,7 +47,7 @@
if (($plugin = optional_param('plugin', '', PARAM_PLUGIN))) {
require_sesskey();
if (!array_key_exists($plugin, $plugins)) {
- print_error('invalidcomponent', 'error', $pageurl);
+ throw new \moodle_exception('invalidcomponent', 'error', $pageurl);
}
$action = required_param('action', PARAM_ALPHA);
switch ($action) {
diff --git a/admin/tool/customlang/classes/form/export.php b/admin/tool/customlang/classes/form/export.php
index 843b09a8fdab8..66ac887951660 100644
--- a/admin/tool/customlang/classes/form/export.php
+++ b/admin/tool/customlang/classes/form/export.php
@@ -44,7 +44,7 @@ public function definition() {
// The export button only appears if a local lang is present.
if (!check_dir_exists($langdir) || !count(glob("$langdir/*"))) {
- print_error('nolocallang', 'tool_customlang');
+ throw new \moodle_exception('nolocallang', 'tool_customlang');
}
$langfiles = scandir($langdir);
diff --git a/admin/tool/customlang/edit.php b/admin/tool/customlang/edit.php
index bfdfd9461a2e0..bcaad8d9f0289 100644
--- a/admin/tool/customlang/edit.php
+++ b/admin/tool/customlang/edit.php
@@ -46,7 +46,7 @@
if (empty($lng)) {
// PARAM_LANG validation failed
- print_error('missingparameter');
+ throw new \moodle_exception('missingparameter');
}
// pre-output processing
diff --git a/admin/tool/customlang/index.php b/admin/tool/customlang/index.php
index 09fc31aebd316..f8530dcb94ee4 100644
--- a/admin/tool/customlang/index.php
+++ b/admin/tool/customlang/index.php
@@ -47,7 +47,7 @@
require_sesskey();
require_capability('tool/customlang:edit', context_system::instance());
if (empty($lng)) {
- print_error('missingparameter');
+ throw new \moodle_exception('missingparameter');
}
$PAGE->set_cacheable(false); // progress bar is used here
@@ -70,7 +70,7 @@
require_sesskey();
require_capability('tool/customlang:edit', context_system::instance());
if (empty($lng)) {
- print_error('missingparameter');
+ throw new \moodle_exception('missingparameter');
}
if (!$confirm) {
diff --git a/admin/tool/dataprivacy/classes/page_helper.php b/admin/tool/dataprivacy/classes/page_helper.php
index e35686a799ea7..924fd00502388 100644
--- a/admin/tool/dataprivacy/classes/page_helper.php
+++ b/admin/tool/dataprivacy/classes/page_helper.php
@@ -53,7 +53,7 @@ public static function setup(moodle_url $url, $title, $attachtoparentnode = '',
require_login();
if (isguestuser()) {
- print_error('noguest');
+ throw new \moodle_exception('noguest');
}
// TODO Check that data privacy is enabled.
diff --git a/admin/tool/dataprivacy/createdatarequest.php b/admin/tool/dataprivacy/createdatarequest.php
index c95898715963f..a6fe9d2b1be5b 100644
--- a/admin/tool/dataprivacy/createdatarequest.php
+++ b/admin/tool/dataprivacy/createdatarequest.php
@@ -35,7 +35,7 @@
require_login();
if (isguestuser()) {
- print_error('noguest');
+ throw new \moodle_exception('noguest');
}
// Return URL and context.
diff --git a/admin/tool/dataprivacy/mydatarequests.php b/admin/tool/dataprivacy/mydatarequests.php
index 037e244708e64..a498c0d66497c 100644
--- a/admin/tool/dataprivacy/mydatarequests.php
+++ b/admin/tool/dataprivacy/mydatarequests.php
@@ -36,7 +36,7 @@
require_login();
if (isguestuser()) {
- print_error('noguest');
+ throw new \moodle_exception('noguest');
}
$usercontext = context_user::instance($USER->id);
diff --git a/admin/tool/generator/classes/testplan_backend.php b/admin/tool/generator/classes/testplan_backend.php
index d4bde532a4a01..3d74e3e3d0861 100644
--- a/admin/tool/generator/classes/testplan_backend.php
+++ b/admin/tool/generator/classes/testplan_backend.php
@@ -186,7 +186,7 @@ protected static function generate_users_file($targetcourseid, $updateuserspassw
$planusers = self::$users[$size] ?? 0;
$users = get_enrolled_users($coursecontext, '', 0, 'u.id, u.username, u.auth', 'u.username ASC', 0, $planusers);
if (!$users) {
- print_error('coursewithoutusers', 'tool_generator');
+ throw new \moodle_exception('coursewithoutusers', 'tool_generator');
}
$lines = array();
@@ -196,7 +196,7 @@ protected static function generate_users_file($targetcourseid, $updateuserspassw
if ($updateuserspassword) {
$userauth = get_auth_plugin($user->auth);
if (!$userauth->user_update_password($user, $CFG->tool_generator_users_password)) {
- print_error('errorpasswordupdate', 'auth');
+ throw new \moodle_exception('errorpasswordupdate', 'auth');
}
}
@@ -249,19 +249,19 @@ protected static function get_course_test_data($targetcourseid) {
// Getting the first page module instance.
if (!$pages = $courseinfo->get_instances_of('page')) {
- print_error('error_nopageinstances', 'tool_generator');
+ throw new \moodle_exception('error_nopageinstances', 'tool_generator');
}
$data->pageid = reset($pages)->id;
// Getting the first forum module instance and it's first discussion and reply as well.
if (!$forums = $courseinfo->get_instances_of('forum')) {
- print_error('error_noforuminstances', 'tool_generator');
+ throw new \moodle_exception('error_noforuminstances', 'tool_generator');
}
$forum = reset($forums);
// Getting the first discussion (and reply).
if (!$discussions = forum_get_discussions($forum, 'd.timemodified ASC', false, -1, 1)) {
- print_error('error_noforumdiscussions', 'tool_generator');
+ throw new \moodle_exception('error_noforumdiscussions', 'tool_generator');
}
$discussion = reset($discussions);
diff --git a/admin/tool/licensemanager/classes/manager.php b/admin/tool/licensemanager/classes/manager.php
index 2f3ad2cee203d..85d37544cf5c8 100644
--- a/admin/tool/licensemanager/classes/manager.php
+++ b/admin/tool/licensemanager/classes/manager.php
@@ -152,14 +152,14 @@ private function edit(string $action, string $licenseshortname) : bool {
if ($action == self::ACTION_CREATE) {
// Check that license shortname isn't already in use.
if (!empty(license_manager::get_license_by_shortname($data->shortname))) {
- print_error('duplicatelicenseshortname', 'tool_licensemanager',
+ throw new \moodle_exception('duplicatelicenseshortname', 'tool_licensemanager',
helper::get_licensemanager_url(),
$data->shortname);
}
$license->shortname = $data->shortname;
} else {
if (empty(license_manager::get_license_by_shortname($licenseshortname))) {
- print_error('licensenotfoundshortname', 'license',
+ throw new \moodle_exception('licensenotfoundshortname', 'license',
helper::get_licensemanager_url(),
$licenseshortname);
}
diff --git a/admin/tool/mobile/logout.php b/admin/tool/mobile/logout.php
index 17a768ac7775a..ebadfec87ed65 100644
--- a/admin/tool/mobile/logout.php
+++ b/admin/tool/mobile/logout.php
@@ -27,7 +27,7 @@
require_once($CFG->dirroot . '/webservice/lib.php');
if (!$CFG->enablemobilewebservice) {
- print_error('enablewsdescription', 'webservice');
+ throw new \moodle_exception('enablewsdescription', 'webservice');
}
require_login(null, false);
diff --git a/admin/tool/mobile/subscription.php b/admin/tool/mobile/subscription.php
index 6dca2c5e00fa7..8eca0d4843125 100644
--- a/admin/tool/mobile/subscription.php
+++ b/admin/tool/mobile/subscription.php
@@ -30,11 +30,11 @@
// Check Mobile web services enabled. This page should not be linked in that case, but avoid just in case.
if (!$CFG->enablemobilewebservice) {
- print_error('enablewsdescription', 'webservice');
+ throw new \moodle_exception('enablewsdescription', 'webservice');
}
// Check is this feature is globaly disabled.
if (!empty($CFG->disablemobileappsubscription)) {
- print_error('disabled', 'admin');
+ throw new \moodle_exception('disabled', 'admin');
}
$subscriptiondata = \tool_mobile\api::get_subscription_information();
diff --git a/admin/tool/monitor/index.php b/admin/tool/monitor/index.php
index 5392fd628054c..2adbd29a3bb7d 100644
--- a/admin/tool/monitor/index.php
+++ b/admin/tool/monitor/index.php
@@ -46,7 +46,7 @@
$choose = true;
} else {
// return error.
- print_error('rulenopermission', 'tool_monitor');
+ throw new \moodle_exception('rulenopermission', 'tool_monitor');
}
}
} else {
diff --git a/admin/tool/moodlenet/import.php b/admin/tool/moodlenet/import.php
index 1b57ce9d6de93..c4a9df2af1f8c 100644
--- a/admin/tool/moodlenet/import.php
+++ b/admin/tool/moodlenet/import.php
@@ -38,7 +38,7 @@
// The integration must be enabled for this import endpoint to be active.
if (!get_config('tool_moodlenet', 'enablemoodlenet')) {
- print_error('moodlenetnotenabled', 'tool_moodlenet');
+ throw new \moodle_exception('moodlenetnotenabled', 'tool_moodlenet');
}
$resourceurl = required_param('resourceurl', PARAM_URL);
@@ -82,4 +82,4 @@
}
// Invalid or missing POST data. Show an error to the user.
-print_error('missinginvalidpostdata', 'tool_moodlenet');
+throw new \moodle_exception('missinginvalidpostdata', 'tool_moodlenet');
diff --git a/admin/tool/moodlenet/index.php b/admin/tool/moodlenet/index.php
index 5680d19a8dc91..5103730e0528a 100644
--- a/admin/tool/moodlenet/index.php
+++ b/admin/tool/moodlenet/index.php
@@ -44,7 +44,7 @@
require_capability('moodle/course:manageactivities', context_course::instance($importinfo->get_config()->course));
}
if (!get_config('tool_moodlenet', 'enablemoodlenet')) {
- print_error('moodlenetnotenabled', 'tool_moodlenet');
+ throw new \moodle_exception('moodlenetnotenabled', 'tool_moodlenet');
}
// Handle the form submits.
@@ -73,7 +73,7 @@
$context = import_backup_helper::get_context_for_user($USER->id);
if (is_null($context)) {
- print_error('nopermissions', 'error', '', get_string('restore:uploadfile', 'core_role'));
+ throw new \moodle_exception('nopermissions', 'error', '', get_string('restore:uploadfile', 'core_role'));
}
} else {
$context = context_course::instance($importinfo->get_config()->course);
diff --git a/admin/tool/moodlenet/options.php b/admin/tool/moodlenet/options.php
index a510f53e20697..2245150439bbc 100644
--- a/admin/tool/moodlenet/options.php
+++ b/admin/tool/moodlenet/options.php
@@ -59,7 +59,7 @@
require_login($config->course, false);
require_capability('moodle/course:manageactivities', context_course::instance($config->course));
if (!get_config('tool_moodlenet', 'enablemoodlenet')) {
- print_error('moodlenetnotenabled', 'tool_moodlenet');
+ throw new \moodle_exception('moodlenetnotenabled', 'tool_moodlenet');
}
// If the user cancelled, break early.
diff --git a/admin/tool/moodlenet/select.php b/admin/tool/moodlenet/select.php
index 704de2ff19c63..1a01ec0e245b0 100644
--- a/admin/tool/moodlenet/select.php
+++ b/admin/tool/moodlenet/select.php
@@ -31,7 +31,7 @@
// Access control.
require_login();
if (!get_config('tool_moodlenet', 'enablemoodlenet')) {
- print_error('moodlenetnotenabled', 'tool_moodlenet');
+ throw new \moodle_exception('moodlenetnotenabled', 'tool_moodlenet');
}
if (is_null($importinfo = import_info::load($id))) {
diff --git a/admin/tool/multilangupgrade/index.php b/admin/tool/multilangupgrade/index.php
index 0cc6b4144f31a..2ca508e579b43 100644
--- a/admin/tool/multilangupgrade/index.php
+++ b/admin/tool/multilangupgrade/index.php
@@ -52,7 +52,7 @@
if (!$tables = $DB->get_tables() ) { // No tables yet at all.
- print_error('notables', 'debug');
+ throw new \moodle_exception('notables', 'debug');
}
echo $OUTPUT->box_start();
diff --git a/admin/tool/oauth2/endpoints.php b/admin/tool/oauth2/endpoints.php
index bb39a821253a6..ac728732a8be0 100644
--- a/admin/tool/oauth2/endpoints.php
+++ b/admin/tool/oauth2/endpoints.php
@@ -45,7 +45,7 @@
$issuer = \core\oauth2\api::get_issuer($issuerid);
if (!$issuer) {
- print_error('invaliddata');
+ throw new \moodle_exception('invaliddata');
}
$PAGE->navbar->override_active_url(new moodle_url('/admin/tool/oauth2/issuers.php'), true);
diff --git a/admin/tool/oauth2/issuers.php b/admin/tool/oauth2/issuers.php
index df19faddcaaa3..dff41e066027b 100644
--- a/admin/tool/oauth2/issuers.php
+++ b/admin/tool/oauth2/issuers.php
@@ -45,7 +45,7 @@
if ($issuerid) {
$issuer = \core\oauth2\api::get_issuer($issuerid);
if (!$issuer) {
- print_error('invaliddata');
+ throw new \moodle_exception('invaliddata');
}
}
diff --git a/admin/tool/oauth2/userfieldmappings.php b/admin/tool/oauth2/userfieldmappings.php
index 28fc5a6feadfd..0a51c365e7342 100644
--- a/admin/tool/oauth2/userfieldmappings.php
+++ b/admin/tool/oauth2/userfieldmappings.php
@@ -45,7 +45,7 @@
$issuer = \core\oauth2\api::get_issuer($issuerid);
if (!$issuer) {
- print_error('invaliddata');
+ throw new \moodle_exception('invaliddata');
}
$PAGE->navbar->override_active_url(new moodle_url('/admin/tool/oauth2/issuers.php'), true);
diff --git a/admin/tool/policy/accept.php b/admin/tool/policy/accept.php
index 42f07603d5834..ed19077e70aed 100644
--- a/admin/tool/policy/accept.php
+++ b/admin/tool/policy/accept.php
@@ -32,7 +32,7 @@
require_login();
if (isguestuser()) {
- print_error('noguest');
+ throw new \moodle_exception('noguest');
}
$context = context_system::instance();
diff --git a/admin/tool/policy/user.php b/admin/tool/policy/user.php
index 104d2591d2887..2e3676a6700db 100644
--- a/admin/tool/policy/user.php
+++ b/admin/tool/policy/user.php
@@ -31,7 +31,7 @@
require_login();
$userid = $userid ?: $USER->id;
if (isguestuser() || isguestuser($userid)) {
- print_error('noguest');
+ throw new \moodle_exception('noguest');
}
$context = context_user::instance($userid);
if ($userid != $USER->id) {
diff --git a/admin/tool/recyclebin/index.php b/admin/tool/recyclebin/index.php
index 1c587ff741e8e..24334b184de97 100644
--- a/admin/tool/recyclebin/index.php
+++ b/admin/tool/recyclebin/index.php
@@ -70,12 +70,12 @@
break;
default:
- print_error('invalidcontext', 'tool_recyclebin');
+ throw new \moodle_exception('invalidcontext', 'tool_recyclebin');
break;
}
if (!$recyclebin::is_enabled()) {
- print_error('notenabled', 'tool_recyclebin');
+ throw new \moodle_exception('notenabled', 'tool_recyclebin');
}
$PAGE->set_url('/admin/tool/recyclebin/index.php', array(
@@ -101,7 +101,7 @@
$recyclebin->restore_item($item);
redirect($PAGE->url, get_string('alertrestored', 'tool_recyclebin', $item), 2);
} else {
- print_error('nopermissions', 'error');
+ throw new \moodle_exception('nopermissions', 'error');
}
break;
@@ -111,7 +111,7 @@
$recyclebin->delete_item($item);
redirect($PAGE->url, get_string('alertdeleted', 'tool_recyclebin', $item), 2);
} else {
- print_error('nopermissions', 'error');
+ throw new \moodle_exception('nopermissions', 'error');
}
break;
diff --git a/admin/tool/task/clear_fail_delay.php b/admin/tool/task/clear_fail_delay.php
index 8f357b8a7ba1d..032be004634fc 100644
--- a/admin/tool/task/clear_fail_delay.php
+++ b/admin/tool/task/clear_fail_delay.php
@@ -36,7 +36,7 @@
$taskname = required_param('task', PARAM_RAW_TRIMMED);
$task = \core\task\manager::get_scheduled_task($taskname);
if (!$task) {
- print_error('cannotfindinfo', 'error', $taskname);
+ throw new \moodle_exception('cannotfindinfo', 'error', $taskname);
}
$returnurl = new moodle_url('/admin/tool/task/scheduledtasks.php',
diff --git a/admin/tool/task/scheduledtasks.php b/admin/tool/task/scheduledtasks.php
index cc8b3105f3d8a..67005fdea2927 100644
--- a/admin/tool/task/scheduledtasks.php
+++ b/admin/tool/task/scheduledtasks.php
@@ -38,7 +38,7 @@
if ($taskname) {
$task = \core\task\manager::get_scheduled_task($taskname);
if (!$task) {
- print_error('invaliddata');
+ throw new \moodle_exception('invaliddata');
}
}
diff --git a/admin/tool/uploadcourse/cli/uploadcourse.php b/admin/tool/uploadcourse/cli/uploadcourse.php
index 1e9394de24de2..5068670d8b2c9 100644
--- a/admin/tool/uploadcourse/cli/uploadcourse.php
+++ b/admin/tool/uploadcourse/cli/uploadcourse.php
@@ -193,9 +193,9 @@
$readcount = $cir->load_csv_content($content, $options['encoding'], $options['delimiter']);
unset($content);
if ($readcount === false) {
- print_error('csvfileerror', 'tool_uploadcourse', '', $cir->get_error());
+ throw new \moodle_exception('csvfileerror', 'tool_uploadcourse', '', $cir->get_error());
} else if ($readcount == 0) {
- print_error('csvemptyfile', 'error', '', $cir->get_error());
+ throw new \moodle_exception('csvemptyfile', 'error', '', $cir->get_error());
}
$processor = new tool_uploadcourse_processor($cir, $processoroptions, $defaults);
$processor->execute(new tool_uploadcourse_tracker(tool_uploadcourse_tracker::OUTPUT_PLAIN));
diff --git a/admin/tool/uploadcourse/index.php b/admin/tool/uploadcourse/index.php
index 8c2ccfd9caa14..8b26e54196d9b 100644
--- a/admin/tool/uploadcourse/index.php
+++ b/admin/tool/uploadcourse/index.php
@@ -42,9 +42,9 @@
$readcount = $cir->load_csv_content($content, $form1data->encoding, $form1data->delimiter_name);
unset($content);
if ($readcount === false) {
- print_error('csvfileerror', 'tool_uploadcourse', $returnurl, $cir->get_error());
+ throw new \moodle_exception('csvfileerror', 'tool_uploadcourse', $returnurl, $cir->get_error());
} else if ($readcount == 0) {
- print_error('csvemptyfile', 'error', $returnurl, $cir->get_error());
+ throw new \moodle_exception('csvemptyfile', 'error', $returnurl, $cir->get_error());
}
} else {
echo $OUTPUT->header();
diff --git a/admin/tool/uploaduser/index.php b/admin/tool/uploaduser/index.php
index a0ef7ab16f4f6..325e24d626591 100644
--- a/admin/tool/uploaduser/index.php
+++ b/admin/tool/uploaduser/index.php
@@ -54,7 +54,7 @@
unset($content);
if (!is_null($csvloaderror)) {
- print_error('csvloaderror', '', $returnurl, $csvloaderror);
+ throw new \moodle_exception('csvloaderror', '', $returnurl, $csvloaderror);
}
// Continue to form2.
diff --git a/admin/tool/uploaduser/locallib.php b/admin/tool/uploaduser/locallib.php
index 607f64bd0040b..0a62791488e89 100644
--- a/admin/tool/uploaduser/locallib.php
+++ b/admin/tool/uploaduser/locallib.php
@@ -192,12 +192,12 @@ function uu_validate_user_upload_columns(csv_import_reader $cir, $stdfields, $pr
if (empty($columns)) {
$cir->close();
$cir->cleanup();
- print_error('cannotreadtmpfile', 'error', $returnurl);
+ throw new \moodle_exception('cannotreadtmpfile', 'error', $returnurl);
}
if (count($columns) < 2) {
$cir->close();
$cir->cleanup();
- print_error('csvfewcolumns', 'error', $returnurl);
+ throw new \moodle_exception('csvfewcolumns', 'error', $returnurl);
}
// test columns
@@ -240,12 +240,12 @@ function uu_validate_user_upload_columns(csv_import_reader $cir, $stdfields, $pr
} else {
$cir->close();
$cir->cleanup();
- print_error('invalidfieldname', 'error', $returnurl, $field);
+ throw new \moodle_exception('invalidfieldname', 'error', $returnurl, $field);
}
if (in_array($newfield, $processed)) {
$cir->close();
$cir->cleanup();
- print_error('duplicatefieldname', 'error', $returnurl, $newfield);
+ throw new \moodle_exception('duplicatefieldname', 'error', $returnurl, $newfield);
}
$processed[$key] = $newfield;
}
diff --git a/admin/tool/uploaduser/picture.php b/admin/tool/uploaduser/picture.php
index a1d0d3de82fd3..6c5923b5e44b3 100644
--- a/admin/tool/uploaduser/picture.php
+++ b/admin/tool/uploaduser/picture.php
@@ -41,7 +41,7 @@
$site = get_site();
if (!$adminuser = get_admin()) {
- print_error('noadmins', 'error');
+ throw new \moodle_exception('noadmins', 'error');
}
$strfile = get_string('file');
diff --git a/admin/tool/xmldb/actions/edit_field_save/edit_field_save.class.php b/admin/tool/xmldb/actions/edit_field_save/edit_field_save.class.php
index 6d0cec5a2b0ec..40bbeee44c910 100644
--- a/admin/tool/xmldb/actions/edit_field_save/edit_field_save.class.php
+++ b/admin/tool/xmldb/actions/edit_field_save/edit_field_save.class.php
@@ -76,7 +76,7 @@ function invoke() {
// Do the job, setting result as needed
if (!data_submitted()) { // Basic prevention
- print_error('wrongcall', 'error');
+ throw new \moodle_exception('wrongcall', 'error');
}
// Get parameters
diff --git a/admin/tool/xmldb/actions/edit_index_save/edit_index_save.class.php b/admin/tool/xmldb/actions/edit_index_save/edit_index_save.class.php
index 515cbbbe7b9db..fb2e55a3e3e90 100644
--- a/admin/tool/xmldb/actions/edit_index_save/edit_index_save.class.php
+++ b/admin/tool/xmldb/actions/edit_index_save/edit_index_save.class.php
@@ -73,7 +73,7 @@ function invoke() {
// Do the job, setting result as needed
if (!data_submitted()) { // Basic prevention
- print_error('wrongcall', 'error');
+ throw new \moodle_exception('wrongcall', 'error');
}
// Get parameters
diff --git a/admin/tool/xmldb/actions/edit_key_save/edit_key_save.class.php b/admin/tool/xmldb/actions/edit_key_save/edit_key_save.class.php
index 378754aa1040d..7dd00e72728b3 100644
--- a/admin/tool/xmldb/actions/edit_key_save/edit_key_save.class.php
+++ b/admin/tool/xmldb/actions/edit_key_save/edit_key_save.class.php
@@ -79,7 +79,7 @@ function invoke() {
// Do the job, setting result as needed
if (!data_submitted()) { // Basic prevention
- print_error('wrongcall', 'error');
+ throw new \moodle_exception('wrongcall', 'error');
}
// Get parameters
diff --git a/admin/tool/xmldb/actions/edit_table_save/edit_table_save.class.php b/admin/tool/xmldb/actions/edit_table_save/edit_table_save.class.php
index 929e26fa0f07f..1332570a8c306 100644
--- a/admin/tool/xmldb/actions/edit_table_save/edit_table_save.class.php
+++ b/admin/tool/xmldb/actions/edit_table_save/edit_table_save.class.php
@@ -67,7 +67,7 @@ function invoke() {
// Do the job, setting result as needed
if (!data_submitted()) { // Basic prevention
- print_error('wrongcall', 'error');
+ throw new \moodle_exception('wrongcall', 'error');
}
// Get parameters
diff --git a/admin/tool/xmldb/actions/edit_xml_file_save/edit_xml_file_save.class.php b/admin/tool/xmldb/actions/edit_xml_file_save/edit_xml_file_save.class.php
index 0a52dffab1896..a117fdfa40112 100644
--- a/admin/tool/xmldb/actions/edit_xml_file_save/edit_xml_file_save.class.php
+++ b/admin/tool/xmldb/actions/edit_xml_file_save/edit_xml_file_save.class.php
@@ -63,7 +63,7 @@ function invoke() {
// Do the job, setting result as needed
if (!data_submitted()) { // Basic prevention
- print_error('wrongcall', 'error');
+ throw new \moodle_exception('wrongcall', 'error');
}
// Get parameters
diff --git a/admin/tool/xmldb/index.php b/admin/tool/xmldb/index.php
index 4dd92102e4b6f..a4336cba678b9 100644
--- a/admin/tool/xmldb/index.php
+++ b/admin/tool/xmldb/index.php
@@ -104,16 +104,16 @@
}
} else {
// TODO: need more detailed error info
- print_error('xmldberror');
+ throw new \moodle_exception('xmldberror');
}
} else {
$a = new stdClass();
$a->action = $action;
$a->actionclass = $actionclass;
- print_error('cannotinstantiateclass', 'tool_xmldb', '', $a);
+ throw new \moodle_exception('cannotinstantiateclass', 'tool_xmldb', '', $a);
}
} else {
- print_error('invalidaction');
+ throw new \moodle_exception('invalidaction');
}
if ($xmldb_action->getDoesGenerate() != ACTION_GENERATE_XML) {
diff --git a/admin/user.php b/admin/user.php
index cc2a6121b48d1..910feed19d08c 100644
--- a/admin/user.php
+++ b/admin/user.php
@@ -27,7 +27,7 @@
$site = get_site();
if (!has_capability('moodle/user:update', $sitecontext) and !has_capability('moodle/user:delete', $sitecontext)) {
- print_error('nopermissions', 'error', '', 'edit/delete users');
+ throw new \moodle_exception('nopermissions', 'error', '', 'edit/delete users');
}
$stredit = get_string('edit');
@@ -50,7 +50,7 @@
if ($confirmuser and confirm_sesskey()) {
require_capability('moodle/user:update', $sitecontext);
if (!$user = $DB->get_record('user', array('id'=>$confirmuser, 'mnethostid'=>$CFG->mnet_localhost_id))) {
- print_error('nousers');
+ throw new \moodle_exception('nousers');
}
$auth = get_auth_plugin($user->auth);
@@ -66,12 +66,12 @@
} else if ($resendemail && confirm_sesskey()) {
if (!$user = $DB->get_record('user', ['id' => $resendemail, 'mnethostid' => $CFG->mnet_localhost_id, 'deleted' => 0])) {
- print_error('nousers');
+ throw new \moodle_exception('nousers');
}
// Prevent spamming users who are already confirmed.
if ($user->confirmed) {
- print_error('alreadyconfirmed');
+ throw new \moodle_exception('alreadyconfirmed', 'moodle');
}
$returnmsg = get_string('emailconfirmsentsuccess');
@@ -88,10 +88,10 @@
$user = $DB->get_record('user', array('id'=>$delete, 'mnethostid'=>$CFG->mnet_localhost_id), '*', MUST_EXIST);
if ($user->deleted) {
- print_error('usernotdeleteddeleted', 'error');
+ throw new \moodle_exception('usernotdeleteddeleted', 'error');
}
if (is_siteadmin($user->id)) {
- print_error('useradminodelete', 'error');
+ throw new \moodle_exception('useradminodelete', 'error');
}
if ($confirm != md5($delete)) {
@@ -118,17 +118,17 @@
}
} else if ($acl and confirm_sesskey()) {
if (!has_capability('moodle/user:update', $sitecontext)) {
- print_error('nopermissions', 'error', '', 'modify the NMET access control list');
+ throw new \moodle_exception('nopermissions', 'error', '', 'modify the NMET access control list');
}
if (!$user = $DB->get_record('user', array('id'=>$acl))) {
- print_error('nousers', 'error');
+ throw new \moodle_exception('nousers', 'error');
}
if (!is_mnet_remote_user($user)) {
- print_error('usermustbemnet', 'error');
+ throw new \moodle_exception('usermustbemnet', 'error');
}
$accessctrl = strtolower(required_param('accessctrl', PARAM_ALPHA));
if ($accessctrl != 'allow' and $accessctrl != 'deny') {
- print_error('invalidaccessparameter', 'error');
+ throw new \moodle_exception('invalidaccessparameter', 'error');
}
$aclrecord = $DB->get_record('mnet_sso_access_control', array('username'=>$user->username, 'mnet_host_id'=>$user->mnethostid));
if (empty($aclrecord)) {
diff --git a/admin/user/user_bulk_message.php b/admin/user/user_bulk_message.php
index 3ef1e5f7242ba..c18c010088af7 100644
--- a/admin/user/user_bulk_message.php
+++ b/admin/user/user_bulk_message.php
@@ -17,7 +17,7 @@
}
if (empty($CFG->messaging)) {
- print_error('messagingdisable', 'error');
+ throw new \moodle_exception('messagingdisable', 'error');
}
$PAGE->set_primary_active_tab('siteadminnode');
diff --git a/analytics/classes/model_config.php b/analytics/classes/model_config.php
index 67218507d9d76..a715a8262ff18 100644
--- a/analytics/classes/model_config.php
+++ b/analytics/classes/model_config.php
@@ -80,7 +80,7 @@ public function export(string $zipfilename, bool $includeweights = true) : strin
$exporttmpdir = make_request_directory();
$jsonfilepath = $exporttmpdir . DIRECTORY_SEPARATOR . 'model-config.json';
if (!file_put_contents($jsonfilepath, json_encode($modeldata))) {
- print_error('errornoexportconfig', 'analytics');
+ throw new \moodle_exception('errornoexportconfig', 'analytics');
}
$zipfiles[self::CONFIG_FILE_NAME] = $jsonfilepath;
diff --git a/auth/db/auth.php b/auth/db/auth.php
index 96aad433f12b2..bb9ed70363d8f 100644
--- a/auth/db/auth.php
+++ b/auth/db/auth.php
@@ -502,7 +502,7 @@ function user_exists($username) {
WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."' ");
if (!$rs) {
- print_error('auth_dbcantconnect','auth_db');
+ throw new \moodle_exception('auth_dbcantconnect', 'auth_db');
} else if (!$rs->EOF) {
// User exists externally.
$result = true;
@@ -525,7 +525,7 @@ function get_userlist() {
FROM {$this->config->table} ");
if (!$rs) {
- print_error('auth_dbcantconnect','auth_db');
+ throw new \moodle_exception('auth_dbcantconnect', 'auth_db');
} else if (!$rs->EOF) {
while ($rec = $rs->FetchRow()) {
$rec = array_change_key_case((array)$rec, CASE_LOWER);
@@ -607,7 +607,7 @@ function user_update($olduser, $newuser) {
SET ".implode(',', $update)."
WHERE {$this->config->fielduser} = ?";
if (!$authdb->Execute($sql, array($this->ext_addslashes($extusername)))) {
- print_error('auth_dbupdateerror', 'auth_db');
+ throw new \moodle_exception('auth_dbupdateerror', 'auth_db');
}
}
$authdb->Close();
diff --git a/auth/email/auth.php b/auth/email/auth.php
index 1998ba0572f3c..42a6e2d99608b 100644
--- a/auth/email/auth.php
+++ b/auth/email/auth.php
@@ -139,7 +139,7 @@ public function user_signup_with_confirmation($user, $notify=true, $confirmation
\core\event\user_created::create_from_userid($user->id)->trigger();
if (! send_confirmation_email($user, $confirmationurl)) {
- print_error('auth_emailnoemail', 'auth_email');
+ throw new \moodle_exception('auth_emailnoemail', 'auth_email');
}
if ($notify) {
diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php
index 9eb3a860421fc..3dfd0564d5a56 100644
--- a/auth/ldap/auth.php
+++ b/auth/ldap/auth.php
@@ -148,7 +148,7 @@ public function auth_plugin_ldap() {
*/
function user_login($username, $password) {
if (! function_exists('ldap_bind')) {
- print_error('auth_ldapnotinstalled', 'auth_ldap');
+ throw new \moodle_exception('auth_ldapnotinstalled', 'auth_ldap');
return false;
}
@@ -450,12 +450,12 @@ function user_create($userobject, $plainpass) {
// strings (UCS-2 Little Endian format) and surrounded with
// double quotes. See http://support.microsoft.com/?kbid=269190
if (!function_exists('mb_convert_encoding')) {
- print_error('auth_ldap_no_mbstring', 'auth_ldap');
+ throw new \moodle_exception('auth_ldap_no_mbstring', 'auth_ldap');
}
// Check for invalid sAMAccountName characters.
if (preg_match('#[/\\[\]:;|=,+*?<>@"]#', $extusername)) {
- print_error ('auth_ldap_ad_invalidchars', 'auth_ldap');
+ throw new \moodle_exception ('auth_ldap_ad_invalidchars', 'auth_ldap');
}
// First create the user account, and mark it as disabled.
@@ -465,7 +465,7 @@ function user_create($userobject, $plainpass) {
AUTH_AD_ACCOUNTDISABLE;
$userdn = 'cn='.ldap_addslashes($extusername).','.$this->config->create_context;
if (!ldap_add($ldapconnection, $userdn, $newuser)) {
- print_error('auth_ldap_ad_create_req', 'auth_ldap');
+ throw new \moodle_exception('auth_ldap_ad_create_req', 'auth_ldap');
}
// Now set the password
@@ -475,12 +475,12 @@ function user_create($userobject, $plainpass) {
if(!ldap_modify($ldapconnection, $userdn, $newuser)) {
// Something went wrong: delete the user account and error out
ldap_delete ($ldapconnection, $userdn);
- print_error('auth_ldap_ad_create_req', 'auth_ldap');
+ throw new \moodle_exception('auth_ldap_ad_create_req', 'auth_ldap');
}
$uadd = true;
break;
default:
- print_error('auth_ldap_unsupportedusertype', 'auth_ldap', '', $this->config->user_type_name);
+ throw new \moodle_exception('auth_ldap_unsupportedusertype', 'auth_ldap', '', $this->config->user_type_name);
}
$this->ldap_close();
return $uadd;
@@ -528,14 +528,14 @@ function user_signup($user, $notify=true) {
require_once($CFG->dirroot.'/user/lib.php');
if ($this->user_exists($user->username)) {
- print_error('auth_ldap_user_exists', 'auth_ldap');
+ throw new \moodle_exception('auth_ldap_user_exists', 'auth_ldap');
}
$plainslashedpassword = $user->password;
unset($user->password);
if (! $this->user_create($user, $plainslashedpassword)) {
- print_error('auth_ldap_create_error', 'auth_ldap');
+ throw new \moodle_exception('auth_ldap_create_error', 'auth_ldap');
}
$user->id = user_create_user($user, false, false);
@@ -558,7 +558,7 @@ function user_signup($user, $notify=true) {
\core\event\user_created::create_from_userid($user->id)->trigger();
if (! send_confirmation_email($user)) {
- print_error('noemail', 'auth_ldap');
+ throw new \moodle_exception('noemail', 'auth_ldap');
}
if ($notify) {
@@ -1018,7 +1018,7 @@ function user_activate($username) {
& (~AUTH_AD_ACCOUNTDISABLE);
break;
default:
- print_error('user_activatenotsupportusertype', 'auth_ldap', '', $this->config->user_type_name);
+ throw new \moodle_exception('user_activatenotsupportusertype', 'auth_ldap', '', $this->config->user_type_name);
}
$result = ldap_modify($ldapconnection, $userdn, $newinfo);
$this->ldap_close();
@@ -1453,7 +1453,7 @@ function ldap_expirationtime2unix ($time, $ldapconnection, $user_dn) {
$result = $this->ldap_get_ad_pwdexpire($time, $ldapconnection, $user_dn);
break;
default:
- print_error('auth_ldap_usertypeundefined', 'auth_ldap');
+ throw new \moodle_exception('auth_ldap_usertypeundefined', 'auth_ldap');
}
return $result;
}
@@ -1474,7 +1474,7 @@ function ldap_unix2expirationtime($time) {
$result = $time ; // Already in correct format
break;
default:
- print_error('auth_ldap_usertypeundefined2', 'auth_ldap');
+ throw new \moodle_exception('auth_ldap_usertypeundefined2', 'auth_ldap');
}
return $result;
@@ -1999,7 +1999,7 @@ function ldap_connect() {
return $ldapconnection;
}
- print_error('auth_ldap_noconnect_all', 'auth_ldap', '', $debuginfo);
+ throw new \moodle_exception('auth_ldap_noconnect_all', 'auth_ldap', '', $debuginfo);
}
/**
diff --git a/auth/ldap/ntlmsso_attempt.php b/auth/ldap/ntlmsso_attempt.php
index ff483a7eefb4b..6f107caba0fa1 100644
--- a/auth/ldap/ntlmsso_attempt.php
+++ b/auth/ldap/ntlmsso_attempt.php
@@ -10,12 +10,12 @@
$authsequence = get_enabled_auth_plugins(); // Auths, in sequence.
if (!in_array('ldap', $authsequence, true)) {
- print_error('ldap_isdisabled', 'auth');
+ throw new \moodle_exception('ldap_isdisabled', 'auth');
}
$authplugin = get_auth_plugin('ldap');
if (empty($authplugin->config->ntlmsso_enabled)) {
- print_error('ntlmsso_isdisabled', 'auth_ldap');
+ throw new \moodle_exception('ntlmsso_isdisabled', 'auth_ldap');
}
$sesskey = sesskey();
diff --git a/auth/ldap/ntlmsso_finish.php b/auth/ldap/ntlmsso_finish.php
index 9a9c415f41071..b0d4d7373b8f5 100644
--- a/auth/ldap/ntlmsso_finish.php
+++ b/auth/ldap/ntlmsso_finish.php
@@ -10,12 +10,12 @@
$authsequence = get_enabled_auth_plugins(); // Auths, in sequence.
if (!in_array('ldap', $authsequence, true)) {
- print_error('ldap_isdisabled', 'auth');
+ throw new \moodle_exception('ldap_isdisabled', 'auth');
}
$authplugin = get_auth_plugin('ldap');
if (empty($authplugin->config->ntlmsso_enabled)) {
- print_error('ntlmsso_isdisabled', 'auth_ldap');
+ throw new \moodle_exception('ntlmsso_isdisabled', 'auth_ldap');
}
// If ntlmsso_finish() succeeds, then the code never returns,
diff --git a/auth/ldap/ntlmsso_magic.php b/auth/ldap/ntlmsso_magic.php
index f8b5fcde855e9..bb1847650ef6a 100644
--- a/auth/ldap/ntlmsso_magic.php
+++ b/auth/ldap/ntlmsso_magic.php
@@ -12,12 +12,12 @@
$authsequence = get_enabled_auth_plugins(); // Auths, in sequence.
if (!in_array('ldap', $authsequence, true)) {
- print_error('ldap_isdisabled', 'auth');
+ throw new \moodle_exception('ldap_isdisabled', 'auth');
}
$authplugin = get_auth_plugin('ldap');
if (empty($authplugin->config->ntlmsso_enabled)) {
- print_error('ntlmsso_isdisabled', 'auth_ldap');
+ throw new \moodle_exception('ntlmsso_isdisabled', 'auth_ldap');
}
$sesskey = required_param('sesskey', PARAM_RAW);
@@ -41,7 +41,7 @@
fclose($handle);
exit;
} else {
- print_error('ntlmsso_iwamagicnotenabled', 'auth_ldap');
+ throw new \moodle_exception('ntlmsso_iwamagicnotenabled', 'auth_ldap');
}
diff --git a/auth/mnet/auth.php b/auth/mnet/auth.php
index d12ef16dd3c31..6816d54692912 100644
--- a/auth/mnet/auth.php
+++ b/auth/mnet/auth.php
@@ -61,7 +61,7 @@ public function auth_plugin_mnet() {
* @return bool Authentication success or failure.
*/
function user_login($username, $password) {
- return false; // print_error("mnetlocal");
+ return false; // Throw moodle_exception("mnetlocal").
}
/**
@@ -152,7 +152,7 @@ function start_jump_session($mnethostid, $wantsurl, $wantsurlbackhere=false) {
require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
if (\core\session\manager::is_loggedinas()) {
- print_error('notpermittedtojumpas', 'mnet');
+ throw new \moodle_exception('notpermittedtojumpas', 'mnet');
}
// check remote login permissions
@@ -160,12 +160,12 @@ function start_jump_session($mnethostid, $wantsurl, $wantsurlbackhere=false) {
or is_mnet_remote_user($USER)
or isguestuser()
or !isloggedin()) {
- print_error('notpermittedtojump', 'mnet');
+ throw new \moodle_exception('notpermittedtojump', 'mnet');
}
// check for SSO publish permission first
if ($this->has_service($mnethostid, 'sso_sp') == false) {
- print_error('hostnotconfiguredforsso', 'mnet');
+ throw new \moodle_exception('hostnotconfiguredforsso', 'mnet');
}
// set RPC timeout to 30 seconds if not configured
@@ -230,7 +230,7 @@ function confirm_mnet_session($token, $remotepeer) {
// verify the remote host is configured locally before attempting RPC call
if (! $remotehost = $DB->get_record('mnet_host', array('wwwroot' => $remotepeer->wwwroot, 'deleted' => 0))) {
- print_error('notpermittedtoland', 'mnet');
+ throw new \moodle_exception('notpermittedtoland', 'mnet');
}
// set up the RPC request
@@ -249,22 +249,23 @@ function confirm_mnet_session($token, $remotepeer) {
list($code, $message) = array_map('trim',explode(':', $errormessage, 2));
if($code == 702) {
$site = get_site();
- print_error('mnet_session_prohibited', 'mnet', $remotepeer->wwwroot, format_string($site->fullname));
+ throw new \moodle_exception('mnet_session_prohibited', 'mnet', $remotepeer->wwwroot,
+ format_string($site->fullname));
exit;
}
$message .= "ERROR $code:
$errormessage
";
}
- print_error("rpcerror", '', '', $message);
+ throw new \moodle_exception("rpcerror", '', '', $message);
}
unset($mnetrequest);
if (empty($remoteuser) or empty($remoteuser->username)) {
- print_error('unknownerror', 'mnet');
+ throw new \moodle_exception('unknownerror', 'mnet');
exit;
}
if (user_not_fully_set_up($remoteuser, false)) {
- print_error('notenoughidpinfo', 'mnet');
+ throw new \moodle_exception('notenoughidpinfo', 'mnet');
exit;
}
@@ -289,7 +290,7 @@ function confirm_mnet_session($token, $remotepeer) {
if (empty($localuser) || ! $localuser->id) {
/*
if (empty($this->config->auto_add_remote_users)) {
- print_error('nolocaluser', 'mnet');
+ throw new \moodle_exception('nolocaluser', 'mnet');
} See MDL-21327 for why this is commented out
*/
$remoteuser->mnethostid = $remotehost->id;
@@ -303,7 +304,8 @@ function confirm_mnet_session($token, $remotepeer) {
// check sso access control list for permission first
if (!$this->can_login_remotely($localuser->username, $remotehost->id)) {
- print_error('sso_mnet_login_refused', 'mnet', '', array('user'=>$localuser->username, 'host'=>$remotehost->name));
+ throw new \moodle_exception('sso_mnet_login_refused', 'mnet', '',
+ array('user' => $localuser->username, 'host' => $remotehost->name));
}
$fs = get_file_storage();
diff --git a/auth/mnet/jump.php b/auth/mnet/jump.php
index 6ee75590033e0..83ad27c63832a 100644
--- a/auth/mnet/jump.php
+++ b/auth/mnet/jump.php
@@ -43,7 +43,7 @@
}
if (!is_enabled_auth('mnet')) {
- print_error('mnetdisable');
+ throw new \moodle_exception('mnetdisable');
}
// If hostid hasn't been specified, try getting it using wwwroot
@@ -63,7 +63,7 @@
$url = $mnetauth->start_jump_session($hostid, $wantsurl);
if (empty($url)) {
- print_error('DEBUG: Jump session was not started correctly or blank URL returned.'); // TODO: errors
+ throw new \moodle_exception('DEBUG: Jump session was not started correctly or blank URL returned.'); // TODO: errors.
}
redirect($url);
diff --git a/auth/mnet/land.php b/auth/mnet/land.php
index 07317d1cd5b1a..3e5fceb64c1c2 100644
--- a/auth/mnet/land.php
+++ b/auth/mnet/land.php
@@ -40,7 +40,7 @@
$site = get_site();
if (!is_enabled_auth('mnet')) {
- print_error('mnetdisable');
+ throw new \moodle_exception('mnetdisable');
}
// confirm the MNET session
diff --git a/auth/oauth2/confirm-account.php b/auth/oauth2/confirm-account.php
index 9b4a129821520..955f44939ebba 100644
--- a/auth/oauth2/confirm-account.php
+++ b/auth/oauth2/confirm-account.php
@@ -58,7 +58,7 @@
// The user has confirmed successfully, let's log them in.
if (!$user = get_complete_user_data('username', $username)) {
- print_error('cannotfinduser', '', '', s($username));
+ throw new \moodle_exception('cannotfinduser', '', '', s($username));
}
if (!$user->suspended) {
diff --git a/auth/oauth2/confirm-linkedlogin.php b/auth/oauth2/confirm-linkedlogin.php
index a05ba2ae0c150..879655ae92bbf 100644
--- a/auth/oauth2/confirm-linkedlogin.php
+++ b/auth/oauth2/confirm-linkedlogin.php
@@ -45,7 +45,7 @@
// The user has confirmed successfully, let's log them in.
if (!$user = get_complete_user_data('id', $userid)) {
- print_error('cannotfinduser', '', '', $userid);
+ throw new \moodle_exception('cannotfinduser', '', '', $userid);
}
if (!$user->suspended) {
diff --git a/auth/shibboleth/auth.php b/auth/shibboleth/auth.php
index 8bedda9d34cc8..f2a57a99f19f4 100644
--- a/auth/shibboleth/auth.php
+++ b/auth/shibboleth/auth.php
@@ -105,7 +105,11 @@ function get_userinfo($username) {
// Check whether we have got all the essential attributes
if ( empty($_SERVER[$this->config->user_attribute]) ) {
- print_error( 'shib_not_all_attributes_error', 'auth_shibboleth' , '', "'".$this->config->user_attribute."' ('".$_SERVER[$this->config->user_attribute]."'), '".$this->config->field_map_firstname."' ('".$_SERVER[$this->config->field_map_firstname]."'), '".$this->config->field_map_lastname."' ('".$_SERVER[$this->config->field_map_lastname]."') and '".$this->config->field_map_email."' ('".$_SERVER[$this->config->field_map_email]."')");
+ throw new \moodle_exception( 'shib_not_all_attributes_error', 'auth_shibboleth' , '',
+ "'".$this->config->user_attribute."' ('".$_SERVER[$this->config->user_attribute]."'), '".
+ $this->config->field_map_firstname."' ('".$_SERVER[$this->config->field_map_firstname]."'), '".
+ $this->config->field_map_lastname."' ('".$_SERVER[$this->config->field_map_lastname]."') and '".
+ $this->config->field_map_email."' ('".$_SERVER[$this->config->field_map_email]."')");
}
$attrmap = $this->get_attributes();
diff --git a/auth/shibboleth/index.php b/auth/shibboleth/index.php
index df0a7c9766871..576d332a686a3 100644
--- a/auth/shibboleth/index.php
+++ b/auth/shibboleth/index.php
@@ -34,7 +34,7 @@
// Check whether Shibboleth is configured properly
$readmeurl = (new moodle_url('/auth/shibboleth/README.txt'))->out();
if (empty($pluginconfig->user_attribute)) {
- print_error('shib_not_set_up_error', 'auth_shibboleth', '', $readmeurl);
+ throw new \moodle_exception('shib_not_set_up_error', 'auth_shibboleth', '', $readmeurl);
}
/// If we can find the Shibboleth attribute, save it in session and return to main login page
@@ -88,14 +88,16 @@
else {
// The Shibboleth user couldn't be mapped to a valid Moodle user
- print_error('shib_invalid_account_error', 'auth_shibboleth');
+ throw new \moodle_exception('shib_invalid_account_error', 'auth_shibboleth');
}
}
// If we can find any (user independent) Shibboleth attributes but no user
// attributes we probably didn't receive any user attributes
elseif (!empty($_SERVER['HTTP_SHIB_APPLICATION_ID']) || !empty($_SERVER['Shib-Application-ID'])) {
- print_error('shib_no_attributes_error', 'auth_shibboleth' , '', '\''.$pluginconfig->user_attribute.'\', \''.$pluginconfig->field_map_firstname.'\', \''.$pluginconfig->field_map_lastname.'\' and \''.$pluginconfig->field_map_email.'\'');
+ throw new \moodle_exception('shib_no_attributes_error', 'auth_shibboleth' , '',
+ '\''.$pluginconfig->user_attribute.'\', \''.$pluginconfig->field_map_firstname.'\', \''.
+ $pluginconfig->field_map_lastname.'\' and \''.$pluginconfig->field_map_email.'\'');
} else {
- print_error('shib_not_set_up_error', 'auth_shibboleth', '', $readmeurl);
+ throw new \moodle_exception('shib_not_set_up_error', 'auth_shibboleth', '', $readmeurl);
}
diff --git a/backup/backup.php b/backup/backup.php
index 12ddbe4a1aef8..364e715f5efb9 100644
--- a/backup/backup.php
+++ b/backup/backup.php
@@ -102,7 +102,7 @@
$heading = get_string('backupactivity', 'backup', $cm->name);
break;
default :
- print_error('unknownbackuptype');
+ throw new \moodle_exception('unknownbackuptype');
}
$PAGE->set_title($heading);
diff --git a/backup/import.php b/backup/import.php
index 679c29a8aa890..402a269b6fc40 100644
--- a/backup/import.php
+++ b/backup/import.php
@@ -147,7 +147,7 @@
// backups don't store resulting files ever
$tempdestination = make_backup_temp_directory($backupid, false);
if (!file_exists($tempdestination) || !is_dir($tempdestination)) {
- print_error('unknownbackupexporterror'); // shouldn't happen ever
+ throw new \moodle_exception('unknownbackupexporterror'); // Shouldn't happen ever.
}
// Prepare the restore controller. We don't need a UI here as we will just use what
diff --git a/badges/alignment.php b/badges/alignment.php
index 71c349b43e8a2..cfd4a460fa878 100644
--- a/badges/alignment.php
+++ b/badges/alignment.php
@@ -33,7 +33,7 @@
require_login();
if (empty($CFG->enablebadges)) {
- print_error('badgesdisabled', 'badges');
+ throw new \moodle_exception('badgesdisabled', 'badges');
}
$badge = new badge($badgeid);
$context = $badge->get_context();
@@ -42,7 +42,7 @@
if ($badge->type == BADGE_TYPE_COURSE) {
if (empty($CFG->badges_allowcoursebadges)) {
- print_error('coursebadgesdisabled', 'badges');
+ throw new \moodle_exception('coursebadgesdisabled', 'badges');
}
require_login($badge->courseid);
$course = get_course($badge->courseid);
diff --git a/badges/assertion.php b/badges/assertion.php
index 29f1d9ec82f13..b6d101cd02e4a 100644
--- a/badges/assertion.php
+++ b/badges/assertion.php
@@ -31,7 +31,7 @@
require_once($CFG->libdir . '/badgeslib.php');
if (empty($CFG->enablebadges)) {
- print_error('badgesdisabled', 'badges');
+ throw new \moodle_exception('badgesdisabled', 'badges');
}
$hash = required_param('b', PARAM_ALPHANUM); // Issued badge unique hash for badge assertion.
diff --git a/badges/award.php b/badges/award.php
index 85caa99ab9b57..b503ac19234e5 100644
--- a/badges/award.php
+++ b/badges/award.php
@@ -36,7 +36,7 @@
require_login();
if (empty($CFG->enablebadges)) {
- print_error('badgesdisabled', 'badges');
+ throw new \moodle_exception('badgesdisabled', 'badges');
}
$badge = new badge($badgeid);
@@ -47,7 +47,7 @@
if ($badge->type == BADGE_TYPE_COURSE) {
if (empty($CFG->badges_allowcoursebadges)) {
- print_error('coursebadgesdisabled', 'badges');
+ throw new \moodle_exception('coursebadgesdisabled', 'badges');
}
require_login($badge->courseid);
$course = get_course($badge->courseid);
diff --git a/badges/criteria.php b/badges/criteria.php
index 72b880b246d9b..f4f6c9502111e 100644
--- a/badges/criteria.php
+++ b/badges/criteria.php
@@ -33,7 +33,7 @@
require_login();
if (empty($CFG->enablebadges)) {
- print_error('badgesdisabled', 'badges');
+ throw new \moodle_exception('badgesdisabled', 'badges');
}
$badge = new badge($badgeid);
@@ -44,7 +44,7 @@
if ($badge->type == BADGE_TYPE_COURSE) {
if (empty($CFG->badges_allowcoursebadges)) {
- print_error('coursebadgesdisabled', 'badges');
+ throw new \moodle_exception('coursebadgesdisabled', 'badges');
}
require_login($badge->courseid);
$course = get_course($badge->courseid);
diff --git a/badges/criteria/award_criteria.php b/badges/criteria/award_criteria.php
index 4519d706371cb..b568df3257e6e 100644
--- a/badges/criteria/award_criteria.php
+++ b/badges/criteria/award_criteria.php
@@ -158,7 +158,7 @@ public static function build($params) {
$types = badges_list_criteria(false);
if (!isset($params['criteriatype']) || !isset($types[$params['criteriatype']])) {
- print_error('error:invalidcriteriatype', 'badges');
+ throw new \moodle_exception('error:invalidcriteriatype', 'badges');
}
$class = 'award_criteria_' . $types[$params['criteriatype']];
diff --git a/badges/edit.php b/badges/edit.php
index 1bbc9e8a76fac..b556c69b3a84a 100644
--- a/badges/edit.php
+++ b/badges/edit.php
@@ -34,7 +34,7 @@
require_login();
if (empty($CFG->enablebadges)) {
- print_error('badgesdisabled', 'badges');
+ throw new \moodle_exception('badgesdisabled', 'badges');
}
$badge = new badge($badgeid);
@@ -49,7 +49,7 @@
if ($badge->type == BADGE_TYPE_COURSE) {
if (empty($CFG->badges_allowcoursebadges)) {
- print_error('coursebadgesdisabled', 'badges');
+ throw new \moodle_exception('coursebadgesdisabled', 'badges');
}
require_login($badge->courseid);
$course = get_course($badge->courseid);
diff --git a/badges/endorsement.php b/badges/endorsement.php
index ba9b7396c21d0..c5abd12cbc9f9 100644
--- a/badges/endorsement.php
+++ b/badges/endorsement.php
@@ -31,7 +31,7 @@
require_login();
if (empty($CFG->enablebadges)) {
- print_error('badgesdisabled', 'badges');
+ throw new \moodle_exception('badgesdisabled', 'badges');
}
$badge = new badge($badgeid);
@@ -41,7 +41,7 @@
if ($badge->type == BADGE_TYPE_COURSE) {
if (empty($CFG->badges_allowcoursebadges)) {
- print_error('coursebadgesdisabled', 'badges');
+ throw new \moodle_exception('coursebadgesdisabled', 'badges');
}
require_login($badge->courseid);
$course = get_course($badge->courseid);
diff --git a/badges/endorsement_json.php b/badges/endorsement_json.php
index 9ecd3ac8f029d..27796ea8c660e 100644
--- a/badges/endorsement_json.php
+++ b/badges/endorsement_json.php
@@ -28,7 +28,7 @@
require_once($CFG->libdir . '/badgeslib.php');
if (empty($CFG->enablebadges)) {
- print_error('badgesdisabled', 'badges');
+ throw new \moodle_exception('badgesdisabled', 'badges');
}
global $DB;
diff --git a/badges/external.php b/badges/external.php
index 39850a25cacea..c9f7b3b9ab542 100644
--- a/badges/external.php
+++ b/badges/external.php
@@ -55,7 +55,7 @@
// If we didn't find any badges then print an error.
if (is_null($out)) {
- print_error('error:externalbadgedoesntexist', 'badges');
+ throw new \moodle_exception('error:externalbadgedoesntexist', 'badges');
}
$badges = $out->badges;
@@ -73,7 +73,7 @@
// If we didn't find the badge a user might be trying to replace the userid parameter.
if (empty($badge)) {
- print_error('error:externalbadgedoesntexist', 'badges');
+ throw new \moodle_exception('error:externalbadgedoesntexist', 'badges');
}
$output = $PAGE->get_renderer('core', 'badges');
diff --git a/badges/image_author_json.php b/badges/image_author_json.php
index 1cfb92e9e7efa..50438dcdc1714 100644
--- a/badges/image_author_json.php
+++ b/badges/image_author_json.php
@@ -29,7 +29,7 @@
require_once($CFG->libdir . '/badgeslib.php');
if (empty($CFG->enablebadges)) {
- print_error('badgesdisabled', 'badges');
+ throw new \moodle_exception('badgesdisabled', 'badges');
}
$id = required_param('id', PARAM_INT); // Unique hash of badge assertion.
diff --git a/badges/index.php b/badges/index.php
index 7b420ba840bdb..772fa0e9752ef 100644
--- a/badges/index.php
+++ b/badges/index.php
@@ -53,11 +53,11 @@
require_login();
if (empty($CFG->enablebadges)) {
- print_error('badgesdisabled', 'badges');
+ throw new \moodle_exception('badgesdisabled', 'badges');
}
if (empty($CFG->badges_allowcoursebadges) && ($type == BADGE_TYPE_COURSE)) {
- print_error('coursebadgesdisabled', 'badges');
+ throw new \moodle_exception('coursebadgesdisabled', 'badges');
}
$err = '';
diff --git a/badges/mybackpack.php b/badges/mybackpack.php
index 89c3ffdba4d36..4220f5eaf9a58 100644
--- a/badges/mybackpack.php
+++ b/badges/mybackpack.php
@@ -30,7 +30,7 @@
require_login();
if (empty($CFG->enablebadges)) {
- print_error('badgesdisabled', 'badges');
+ throw new \moodle_exception('badgesdisabled', 'badges');
}
$context = context_user::instance($USER->id);
@@ -145,7 +145,7 @@
get_string('backpackemailverifypending', 'badges', $data->backpackemail),
null, \core\output\notification::NOTIFY_INFO);
} else {
- print_error ('backpackcannotsendverification', 'badges');
+ throw new \moodle_exception('backpackcannotsendverification', 'badges');
}
}
}
diff --git a/badges/mybadges.php b/badges/mybadges.php
index 42f285ea8c798..b9312f701719e 100644
--- a/badges/mybadges.php
+++ b/badges/mybadges.php
@@ -40,7 +40,7 @@
require_login();
if (empty($CFG->enablebadges)) {
- print_error('badgesdisabled', 'badges');
+ throw new \moodle_exception('badgesdisabled', 'badges');
}
$url = new moodle_url('/badges/mybadges.php');
diff --git a/badges/newbadge.php b/badges/newbadge.php
index b49aff5d11338..d6bbbcdee5fa3 100644
--- a/badges/newbadge.php
+++ b/badges/newbadge.php
@@ -33,11 +33,11 @@
require_login();
if (empty($CFG->enablebadges)) {
- print_error('badgesdisabled', 'badges');
+ throw new \moodle_exception('badgesdisabled', 'badges');
}
if (empty($CFG->badges_allowcoursebadges) && ($type == BADGE_TYPE_COURSE)) {
- print_error('coursebadgesdisabled', 'badges');
+ throw new \moodle_exception('coursebadgesdisabled', 'badges');
}
$title = get_string('create', 'badges');
diff --git a/badges/overview.php b/badges/overview.php
index 52f8949fb45aa..dbf814fc7788e 100644
--- a/badges/overview.php
+++ b/badges/overview.php
@@ -33,7 +33,7 @@
require_login();
if (empty($CFG->enablebadges)) {
- print_error('badgesdisabled', 'badges');
+ throw new \moodle_exception('badgesdisabled', 'badges');
}
$badge = new badge($badgeid);
@@ -42,7 +42,7 @@
if ($badge->type == BADGE_TYPE_COURSE) {
if (empty($CFG->badges_allowcoursebadges)) {
- print_error('coursebadgesdisabled', 'badges');
+ throw new \moodle_exception('coursebadgesdisabled', 'badges');
}
require_login($badge->courseid);
$course = get_course($badge->courseid);
diff --git a/badges/preferences.php b/badges/preferences.php
index 7e01e2c5f2acb..834386656c408 100644
--- a/badges/preferences.php
+++ b/badges/preferences.php
@@ -36,7 +36,7 @@
$PAGE->set_pagelayout('standard');
if (empty($CFG->enablebadges)) {
- print_error('badgesdisabled', 'badges');
+ throw new \moodle_exception('badgesdisabled', 'badges');
}
$mform = new badges_preferences_form();
diff --git a/badges/recipients.php b/badges/recipients.php
index 623d8e64cf464..8a29747e67343 100644
--- a/badges/recipients.php
+++ b/badges/recipients.php
@@ -35,7 +35,7 @@
require_login();
if (empty($CFG->enablebadges)) {
- print_error('badgesdisabled', 'badges');
+ throw new \moodle_exception('badgesdisabled', 'badges');
}
if (!in_array($sortby, array('firstname', 'lastname', 'dateissued'))) {
@@ -56,7 +56,7 @@
if ($badge->type == BADGE_TYPE_COURSE) {
if (empty($CFG->badges_allowcoursebadges)) {
- print_error('coursebadgesdisabled', 'badges');
+ throw new \moodle_exception('coursebadgesdisabled', 'badges');
}
require_login($badge->courseid);
$course = get_course($badge->courseid);
diff --git a/badges/related.php b/badges/related.php
index f817cf6af4fc7..37beb69593e7c 100644
--- a/badges/related.php
+++ b/badges/related.php
@@ -35,7 +35,7 @@
require_login();
if (empty($CFG->enablebadges)) {
- print_error('badgesdisabled', 'badges');
+ throw new \moodle_exception('badgesdisabled', 'badges');
}
$badge = new badge($badgeid);
@@ -45,7 +45,7 @@
if ($badge->type == BADGE_TYPE_COURSE) {
if (empty($CFG->badges_allowcoursebadges)) {
- print_error('coursebadgesdisabled', 'badges');
+ throw new \moodle_exception('coursebadgesdisabled', 'badges');
}
require_login($badge->courseid);
$course = get_course($badge->courseid);
diff --git a/badges/view.php b/badges/view.php
index 527e904d7f250..eabf3b92fc3be 100644
--- a/badges/view.php
+++ b/badges/view.php
@@ -36,11 +36,11 @@
require_login();
if (empty($CFG->enablebadges)) {
- print_error('badgesdisabled', 'badges');
+ throw new \moodle_exception('badgesdisabled', 'badges');
}
if (empty($CFG->badges_allowcoursebadges) && $courseid != 0) {
- print_error('coursebadgesdisabled', 'badges');
+ throw new \moodle_exception('coursebadgesdisabled', 'badges');
}
if (!in_array($sortby, array('name', 'dateissued'))) {
diff --git a/blocks/admin_bookmarks/create.php b/blocks/admin_bookmarks/create.php
index 07ed88f860328..aadcaa48a6fd5 100644
--- a/blocks/admin_bookmarks/create.php
+++ b/blocks/admin_bookmarks/create.php
@@ -37,7 +37,7 @@
$bookmarks = explode(',', get_user_preferences('admin_bookmarks'));
if (in_array($section, $bookmarks)) {
- print_error('bookmarkalreadyexists','admin');
+ throw new \moodle_exception('bookmarkalreadyexists', 'admin');
die;
}
@@ -53,7 +53,7 @@
set_user_preference('admin_bookmarks', $bookmarks);
} else {
- print_error('invalidsection','admin');
+ throw new \moodle_exception('invalidsection', 'admin');
die;
}
@@ -69,7 +69,7 @@
}
} else {
- print_error('invalidsection','admin');
+ throw new \moodle_exception('invalidsection', 'admin');
die;
}
diff --git a/blocks/admin_bookmarks/delete.php b/blocks/admin_bookmarks/delete.php
index a1d8f14ebab19..9343ad26a7f60 100644
--- a/blocks/admin_bookmarks/delete.php
+++ b/blocks/admin_bookmarks/delete.php
@@ -41,7 +41,7 @@
$key = array_search($section, $bookmarks);
if ($key === false) {
- print_error('nonexistentbookmark','admin');
+ throw new \moodle_exception('nonexistentbookmark', 'admin');
die;
}
@@ -65,11 +65,11 @@
}
- print_error('nobookmarksforuser','admin');
+ throw new \moodle_exception('nobookmarksforuser', 'admin');
die;
} else {
- print_error('invalidsection', 'admin');
+ throw new \moodle_exception('invalidsection', 'admin');
die;
}
diff --git a/blocks/completionstatus/details.php b/blocks/completionstatus/details.php
index 33bbe775f85f4..830275fc76ebb 100644
--- a/blocks/completionstatus/details.php
+++ b/blocks/completionstatus/details.php
@@ -44,7 +44,7 @@
require_login();
if (!completion_can_view_data($user->id, $course)) {
- print_error('cannotviewreport');
+ throw new \moodle_exception('cannotviewreport');
}
// Load completion data.
@@ -54,15 +54,15 @@
// Don't display if completion isn't enabled.
if (!$info->is_enabled()) {
- print_error('completionnotenabled', 'completion', $returnurl);
+ throw new \moodle_exception('completionnotenabled', 'completion', $returnurl);
}
// Check this user is enroled.
if (!$info->is_tracked_user($user->id)) {
if ($USER->id == $user->id) {
- print_error('notenroled', 'completion', $returnurl);
+ throw new \moodle_exception('notenroled', 'completion', $returnurl);
} else {
- print_error('usernotenroled', 'completion', $returnurl);
+ throw new \moodle_exception('usernotenroled', 'completion', $returnurl);
}
}
diff --git a/blocks/rss_client/viewfeed.php b/blocks/rss_client/viewfeed.php
index c56eb30a9202e..dc993bb18161b 100644
--- a/blocks/rss_client/viewfeed.php
+++ b/blocks/rss_client/viewfeed.php
@@ -27,7 +27,7 @@
require_login();
if (isguestuser()) {
- print_error('guestsarenotallowed');
+ throw new \moodle_exception('guestsarenotallowed');
}
$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
@@ -62,7 +62,7 @@
if ($rss->error()) {
debugging($rss->error());
- print_error('errorfetchingrssfeed');
+ throw new \moodle_exception('errorfetchingrssfeed');
}
$strviewfeed = get_string('viewfeed', 'block_rss_client');
diff --git a/blog/edit.php b/blog/edit.php
index bf9a166626910..435445d748764 100644
--- a/blog/edit.php
+++ b/blog/edit.php
@@ -55,7 +55,7 @@
if ($id) {
if (!$entry = new blog_entry($id)) {
- print_error('wrongentryid', 'blog');
+ throw new \moodle_exception('wrongentryid', 'blog');
}
$userid = $entry->userid;
} else {
@@ -75,11 +75,11 @@
require_login($courseid);
if (empty($CFG->enableblogs)) {
- print_error('blogdisable', 'blog');
+ throw new \moodle_exception('blogdisable', 'blog');
}
if (isguestuser()) {
- print_error('noguest');
+ throw new \moodle_exception('noguest');
}
$returnurl = new moodle_url('/blog/index.php');
@@ -98,19 +98,19 @@
$blogheaders = blog_get_headers();
if (!has_capability('moodle/blog:create', $sitecontext) && !has_capability('moodle/blog:manageentries', $sitecontext)) {
- print_error('cannoteditentryorblog');
+ throw new \moodle_exception('cannoteditentryorblog');
}
// Make sure that the person trying to edit has access right.
if ($id) {
if (!blog_user_can_edit_entry($entry)) {
- print_error('notallowedtoedit', 'blog');
+ throw new \moodle_exception('notallowedtoedit', 'blog');
}
$entry->subject = clean_text($entry->subject);
$entry->summary = clean_text($entry->summary, $entry->format);
} else {
if (!has_capability('moodle/blog:create', $sitecontext)) {
- print_error('noentry', 'blog'); // The capability "manageentries" is not enough for adding.
+ throw new \moodle_exception('noentry', 'blog'); // The capability "manageentries" is not enough for adding.
}
}
$returnurl->param('userid', $userid);
@@ -125,12 +125,12 @@
comment::init();
if (empty($entry->id)) {
- print_error('wrongentryid', 'blog');
+ throw new \moodle_exception('wrongentryid', 'blog');
}
if (data_submitted() && $confirm && confirm_sesskey()) {
// Make sure the current user is the author of the blog entry, or has some deleteanyentry capability.
if (!blog_user_can_edit_entry($entry)) {
- print_error('nopermissionstodeleteentry', 'blog');
+ throw new \moodle_exception('nopermissionstodeleteentry', 'blog');
} else {
$entry->delete();
blog_rss_delete_file($userid);
@@ -232,14 +232,14 @@
case 'edit':
if (empty($entry->id)) {
- print_error('wrongentryid', 'blog');
+ throw new \moodle_exception('wrongentryid', 'blog');
}
$entry->edit($data, $blogeditform, $summaryoptions, $attachmentoptions);
break;
default :
- print_error('invalidaction');
+ throw new \moodle_exception('invalidaction');
}
redirect($returnurl);
@@ -272,14 +272,14 @@
case 'edit':
if (empty($entry->id)) {
- print_error('wrongentryid', 'blog');
+ throw new \moodle_exception('wrongentryid', 'blog');
}
$strformheading = get_string('updateentrywithid', 'blog');
break;
default :
- print_error('unknowaction');
+ throw new \moodle_exception('unknowaction');
}
$entry->modid = $modid;
diff --git a/blog/external_blog_edit.php b/blog/external_blog_edit.php
index a1a56f1e2e2e5..37fb2a5ce5214 100644
--- a/blog/external_blog_edit.php
+++ b/blog/external_blog_edit.php
@@ -55,7 +55,7 @@
// Retrieve the external blog record.
if (!empty($id)) {
if (!$external = $DB->get_record('blog_external', array('id' => $id, 'userid' => $USER->id))) {
- print_error('wrongexternalid', 'blog');
+ throw new \moodle_exception('wrongexternalid', 'blog');
}
$external->autotags = core_tag_tag::get_item_tags_array('core', 'blog_external', $id);
}
@@ -122,13 +122,13 @@
core_tag_tag::set_item_tags('core', 'blog_external', $external->id,
context_user::instance($external->userid), $data->autotags);
} else {
- print_error('wrongexternalid', 'blog');
+ throw new \moodle_exception('wrongexternalid', 'blog');
}
break;
default :
- print_error('invalidaction');
+ throw new \moodle_exception('invalidaction');
}
redirect($returnurl);
diff --git a/blog/index.php b/blog/index.php
index f8445c08ad202..b3a11a2bc8707 100644
--- a/blog/index.php
+++ b/blog/index.php
@@ -90,7 +90,7 @@
require_login();
if (isguestuser()) {
// They must have entered the url manually.
- print_error('noguest');
+ throw new \moodle_exception('noguest');
}
} else if ($CFG->bloglevel == BLOG_USER_LEVEL) {
@@ -99,11 +99,11 @@
} else {
// Weird!
- print_error('blogdisable', 'blog');
+ throw new \moodle_exception('blogdisable', 'blog');
}
if (empty($CFG->enableblogs)) {
- print_error('blogdisable', 'blog');
+ throw new \moodle_exception('blogdisable', 'blog');
}
list($courseid, $userid) = blog_validate_access($courseid, $modid, $groupid, $entryid, $userid);
diff --git a/blog/lib.php b/blog/lib.php
index f575ff75ac6b9..d8825741307da 100644
--- a/blog/lib.php
+++ b/blog/lib.php
@@ -1204,7 +1204,7 @@ function blog_validate_access($courseid, $modid, $groupid, $entryid, $userid) {
if (!$userid && has_capability('moodle/blog:view', $sitecontext) && $CFG->bloglevel > BLOG_USER_LEVEL) {
if ($entryid) {
if (!$entryobject = $DB->get_record('post', array('id' => $entryid))) {
- print_error('nosuchentry', 'blog');
+ throw new \moodle_exception('nosuchentry', 'blog');
}
$userid = $entryobject->userid;
}
@@ -1214,20 +1214,20 @@ function blog_validate_access($courseid, $modid, $groupid, $entryid, $userid) {
if (!empty($modid)) {
if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
- print_error(get_string('nocourseblogs', 'blog'));
+ throw new \moodle_exception('courseblogdisable', 'blog');
}
if (!$mod = $DB->get_record('course_modules', array('id' => $modid))) {
- print_error(get_string('invalidmodid', 'blog'));
+ throw new \moodle_exception('invalidmoduleid', 'error', $modid);
}
$courseid = $mod->course;
}
if ((empty($courseid) ? true : $courseid == SITEID) && empty($userid)) {
if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
- print_error('siteblogdisable', 'blog');
+ throw new \moodle_exception('siteblogdisable', 'blog');
}
if (!has_capability('moodle/blog:view', $sitecontext)) {
- print_error('cannotviewsiteblog', 'blog');
+ throw new \moodle_exception('cannotviewsiteblog', 'blog');
}
$COURSE = $DB->get_record('course', array('format' => 'site'));
@@ -1236,13 +1236,13 @@ function blog_validate_access($courseid, $modid, $groupid, $entryid, $userid) {
if (!empty($courseid)) {
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
- print_error('invalidcourseid');
+ throw new \moodle_exception('invalidcourseid');
}
$courseid = $course->id;
if (!has_capability('moodle/blog:view', $sitecontext)) {
- print_error('cannotviewcourseblog', 'blog');
+ throw new \moodle_exception('cannotviewcourseblog', 'blog');
}
} else {
$coursecontext = context_course::instance(SITEID);
@@ -1250,54 +1250,54 @@ function blog_validate_access($courseid, $modid, $groupid, $entryid, $userid) {
if (!empty($groupid)) {
if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
- print_error('groupblogdisable', 'blog');
+ throw new \moodle_exception('groupblogdisable', 'blog');
}
if (! $group = groups_get_group($groupid)) {
- print_error(get_string('invalidgroupid', 'blog'));
+ throw new \moodle_exception('invalidgroupid', 'blog');
}
if (!$course = $DB->get_record('course', array('id' => $group->courseid))) {
- print_error('invalidcourseid');
+ throw new \moodle_exception('invalidcourseid');
}
$coursecontext = context_course::instance($course->id);
$courseid = $course->id;
if (!has_capability('moodle/blog:view', $sitecontext)) {
- print_error(get_string('cannotviewcourseorgroupblog', 'blog'));
+ throw new \moodle_exception('cannotviewcourseorgroupblog', 'blog');
}
if (groups_get_course_groupmode($course) == SEPARATEGROUPS &&
!has_capability('moodle/site:accessallgroups', $coursecontext)) {
if (!groups_is_member($groupid)) {
- print_error('notmemberofgroup');
+ throw new \moodle_exception('notmemberofgroup');
}
}
}
if (!empty($userid)) {
if ($CFG->bloglevel < BLOG_USER_LEVEL) {
- print_error('blogdisable', 'blog');
+ throw new \moodle_exception('blogdisable', 'blog');
}
if (!$user = $DB->get_record('user', array('id' => $userid))) {
- print_error('invaliduserid');
+ throw new \moodle_exception('invaliduserid');
}
if ($user->deleted) {
- print_error('userdeleted');
+ throw new \moodle_exception('userdeleted');
}
if ($USER->id == $userid) {
if (!has_capability('moodle/blog:create', $sitecontext)
&& !has_capability('moodle/blog:view', $sitecontext)) {
- print_error('donothaveblog', 'blog');
+ throw new \moodle_exception('donothaveblog', 'blog');
}
} else {
if (!has_capability('moodle/blog:view', $sitecontext) || !blog_user_can_view_user_entry($userid)) {
- print_error('cannotviewcourseblog', 'blog');
+ throw new \moodle_exception('cannotviewcourseblog', 'blog');
}
}
}
diff --git a/blog/preferences.php b/blog/preferences.php
index cd89980dd5dd0..c950f3792552a 100644
--- a/blog/preferences.php
+++ b/blog/preferences.php
@@ -61,11 +61,11 @@
require_login($courseid);
if (empty($CFG->enableblogs)) {
- print_error('blogdisable', 'blog');
+ throw new \moodle_exception('blogdisable', 'blog');
}
if (isguestuser()) {
- print_error('noguest');
+ throw new \moodle_exception('noguest');
}
// The preference is site wide not blog specific. Hence user should have permissions in site level.
@@ -80,7 +80,7 @@
$pagesize = $data->pagesize;
if ($pagesize < 1) {
- print_error('invalidpagesize');
+ throw new \moodle_exception('invalidpagesize');
}
useredit_update_user_preference(['id' => $USER->id,
'preference_blogpagesize' => $pagesize]);
diff --git a/cache/classes/local/administration_display_helper.php b/cache/classes/local/administration_display_helper.php
index 949a3c1b2ebb7..e2c709e0deaed 100644
--- a/cache/classes/local/administration_display_helper.php
+++ b/cache/classes/local/administration_display_helper.php
@@ -444,7 +444,7 @@ public function action_addstore() : array {
$plugin = required_param('plugin', PARAM_PLUGIN);
if (!$storepluginsummaries[$plugin]['canaddinstance']) {
- print_error('ex_unmetstorerequirements', 'cache');
+ throw new \moodle_exception('ex_unmetstorerequirements', 'cache');
}
$mform = $this->get_add_store_form($plugin);
$title = get_string('addstore', 'cache', $storepluginsummaries[$plugin]['name']);
diff --git a/calendar/classes/local/event/forms/create.php b/calendar/classes/local/event/forms/create.php
index 7775e45860f3b..c874d6996e8d3 100644
--- a/calendar/classes/local/event/forms/create.php
+++ b/calendar/classes/local/event/forms/create.php
@@ -71,7 +71,7 @@ public function definition() {
$eventtypes = $this->_customdata['eventtypes'];
if (in_array(true, $eventtypes, true) === false) {
- print_error('nopermissiontoupdatecalendar');
+ throw new \moodle_exception('nopermissiontoupdatecalendar');
}
$mform->setDisableShortforms();
diff --git a/calendar/classes/local/event/forms/managesubscriptions.php b/calendar/classes/local/event/forms/managesubscriptions.php
index 5011f59e30dad..b228914e087b4 100644
--- a/calendar/classes/local/event/forms/managesubscriptions.php
+++ b/calendar/classes/local/event/forms/managesubscriptions.php
@@ -44,7 +44,7 @@ public function definition() {
$mform = $this->_form;
$eventtypes = calendar_get_allowed_event_types();
if (in_array(true, $eventtypes, true) === false) {
- print_error('nopermissiontoupdatecalendar');
+ throw new \moodle_exception('nopermissiontoupdatecalendar');
}
// Name.
diff --git a/calendar/delete.php b/calendar/delete.php
index b27fea73b525d..28af3809c997a 100644
--- a/calendar/delete.php
+++ b/calendar/delete.php
@@ -60,7 +60,7 @@
$title = get_string('deleteevent', 'calendar');
// Check the user has the required capabilities to delete an event
if (!calendar_delete_event_allowed($event)) {
- print_error('nopermissions', 'error', $PAGE->url, $title);
+ throw new \moodle_exception('nopermissions', 'error', $PAGE->url, $title);
}
// Count the repeats, do we need to consider the possibility of deleting repeats
@@ -75,7 +75,7 @@
if ($confirm) {
// Confirm the session key to stop CSRF
if (!confirm_sesskey()) {
- print_error('confirmsesskeybad');
+ throw new \moodle_exception('confirmsesskeybad');
}
// Delete the event and possibly repeats
$event->delete($repeats);
diff --git a/calendar/event.php b/calendar/event.php
index f804b7f19a7d4..425dfb9f7ed99 100644
--- a/calendar/event.php
+++ b/calendar/event.php
@@ -115,7 +115,7 @@
$title = get_string('editevent', 'calendar');
$event = calendar_event::load($eventid);
if (!calendar_edit_event_allowed($event, true)) {
- print_error('nopermissions');
+ throw new \moodle_exception('nopermissions');
}
$event->action = $action;
$event->course = $courseid;
@@ -123,7 +123,7 @@
$event->count_repeats();
if (!calendar_add_event_allowed($event)) {
- print_error('nopermissions');
+ throw new \moodle_exception('nopermissions');
}
// Check to see if this event is part of a subscription or import.
@@ -151,7 +151,7 @@
$event->timestart = $time;
$event = new calendar_event($event);
if (!calendar_add_event_allowed($event)) {
- print_error('nopermissions');
+ throw new \moodle_exception('nopermissions');
}
}
diff --git a/calendar/externallib.php b/calendar/externallib.php
index 46206adfe7cd9..d8eb9b60cb3a2 100644
--- a/calendar/externallib.php
+++ b/calendar/externallib.php
@@ -934,7 +934,7 @@ public static function submit_create_update_form($formdata) {
}
if (!calendar_edit_event_allowed($legacyevent, true)) {
- print_error('nopermissiontoupdatecalendar');
+ throw new \moodle_exception('nopermissiontoupdatecalendar');
}
$legacyevent->update($properties);
@@ -1192,7 +1192,7 @@ public static function update_event_start_day($eventid, $daytimestamp) {
$legacyevent = $mapper->from_event_to_legacy_event($event);
if (!calendar_edit_event_allowed($legacyevent, true)) {
- print_error('nopermissiontoupdatecalendar');
+ throw new \moodle_exception('nopermissiontoupdatecalendar');
}
self::validate_context($legacyevent->context);
diff --git a/calendar/lib.php b/calendar/lib.php
index 9bba24d5e2e06..2edb40fa6a30a 100644
--- a/calendar/lib.php
+++ b/calendar/lib.php
@@ -478,7 +478,7 @@ public function update($data, $checkcapability=true) {
if (empty($this->properties->id) || $this->properties->id < 1) {
if ($checkcapability) {
if (!calendar_add_event_allowed($this->properties)) {
- print_error('nopermissiontoupdatecalendar');
+ throw new \moodle_exception('nopermissiontoupdatecalendar');
}
}
@@ -594,7 +594,7 @@ public function update($data, $checkcapability=true) {
if ($checkcapability) {
if (!calendar_edit_event_allowed($this->properties)) {
- print_error('nopermissiontoupdatecalendar');
+ throw new \moodle_exception('nopermissiontoupdatecalendar');
}
}
@@ -810,7 +810,7 @@ public function properties($prepareeditor = false) {
// First check the course is valid.
$course = $DB->get_record('course', array('id' => $properties->courseid));
if (!$course) {
- print_error('invalidcourse');
+ throw new \moodle_exception('invalidcourse');
}
// Course context.
$this->editorcontext = $this->get_context();
@@ -2875,7 +2875,7 @@ function calendar_add_subscription($sub) {
return $sub->id;
}
} else {
- print_error('errorbadsubscription', 'importcalendar');
+ throw new \moodle_exception('errorbadsubscription', 'importcalendar');
}
}
@@ -3619,7 +3619,7 @@ function calendar_output_fragment_event_form($args) {
$event = calendar_event::load($eventid);
if (!calendar_edit_event_allowed($event)) {
- print_error('nopermissiontoupdatecalendar');
+ throw new \moodle_exception('nopermissiontoupdatecalendar');
}
$mapper = new \core_calendar\local\event\mappers\create_update_form_mapper();
diff --git a/calendar/managesubscriptions.php b/calendar/managesubscriptions.php
index 4cf8854fa97f4..c4c41ea449c87 100644
--- a/calendar/managesubscriptions.php
+++ b/calendar/managesubscriptions.php
@@ -66,7 +66,7 @@
require_login($course, false);
if (!calendar_user_can_add_event($course)) {
- print_error('errorcannotimport', 'calendar');
+ throw new \moodle_exception('errorcannotimport', 'calendar');
}
$PAGE->navbar->add(get_string('managesubscriptions', 'calendar'), $PAGE->url);
diff --git a/cohort/edit.php b/cohort/edit.php
index fe98535e5f25b..ff03dde09d793 100644
--- a/cohort/edit.php
+++ b/cohort/edit.php
@@ -44,7 +44,7 @@
} else {
$context = context::instance_by_id($contextid, MUST_EXIST);
if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
- print_error('invalidcontext');
+ throw new \moodle_exception('invalidcontext');
}
$cohort = new stdClass();
$cohort->id = 0;
diff --git a/cohort/index.php b/cohort/index.php
index a3ce8f6e00a08..c726d29598282 100644
--- a/cohort/index.php
+++ b/cohort/index.php
@@ -40,7 +40,7 @@
}
if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
- print_error('invalidcontext');
+ throw new \moodle_exception('invalidcontext');
}
$category = null;
diff --git a/cohort/upload.php b/cohort/upload.php
index cc1372f959a52..a9a857e07123d 100644
--- a/cohort/upload.php
+++ b/cohort/upload.php
@@ -37,7 +37,7 @@
$context = context_system::instance();
}
if ($context->contextlevel != CONTEXT_COURSECAT && $context->contextlevel != CONTEXT_SYSTEM) {
- print_error('invalidcontext');
+ throw new \moodle_exception('invalidcontext');
}
require_capability('moodle/cohort:manage', $context);
diff --git a/comment/index.php b/comment/index.php
index 77c383a9871a0..8d4bd59cca54e 100644
--- a/comment/index.php
+++ b/comment/index.php
@@ -77,7 +77,7 @@
echo $OUTPUT->heading(get_string('comments'));
echo $OUTPUT->box_start('generalbox commentsreport');
if (!empty($err)) {
- print_error($err, 'error', $CFG->wwwroot.'/comment/');
+ throw new \moodle_exception($err, 'error', $CFG->wwwroot.'/comment/');
}
if (empty($action)) {
echo '