Skip to content

Commit

Permalink
MDL-71062 core: Step 1 deprecation of print_error function
Browse files Browse the repository at this point in the history
  • Loading branch information
sharidas committed Jul 13, 2022
1 parent a23f0bf commit 73d6043
Show file tree
Hide file tree
Showing 506 changed files with 1,511 additions and 1,488 deletions.
6 changes: 3 additions & 3 deletions admin/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -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)) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion admin/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions admin/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions admin/cli/restore_backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion admin/contentbank.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion admin/courseformats.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions admin/cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@
// 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.
if (!empty($CFG->cronremotepassword)) {
$pass = optional_param('password', '', PARAM_RAW);
if ($pass != $CFG->cronremotepassword) {
// wrong password.
print_error('cronerrorpassword', 'admin');
throw new \moodle_exception('cronerrorpassword', 'admin');
exit;
}
}
Expand Down
2 changes: 1 addition & 1 deletion admin/customfields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion admin/dataformats.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions admin/environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
18 changes: 10 additions & 8 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()) {
Expand Down Expand Up @@ -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');
}
}

Expand All @@ -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.
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions admin/mnet/access_control.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand All @@ -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)) {
Expand All @@ -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");
}
}

Expand All @@ -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');
Expand Down
10 changes: 5 additions & 5 deletions admin/mnet/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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')) {
Expand All @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions admin/mnet/peers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions admin/mnet/testclient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion admin/mnet/trustedhosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion admin/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions admin/portfolio.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 73d6043

Please sign in to comment.