Skip to content

Commit 73d6043

Browse files
committed
MDL-71062 core: Step 1 deprecation of print_error function
1 parent a23f0bf commit 73d6043

File tree

506 files changed

+1511
-1488
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

506 files changed

+1511
-1488
lines changed

admin/auth.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
}
2929

3030
if (!empty($auth) and !exists_auth_plugin($auth)) {
31-
print_error('pluginnotinstalled', 'auth', $returnurl, $auth);
31+
throw new \moodle_exception('pluginnotinstalled', 'auth', $returnurl, $auth);
3232
}
3333

3434
////////////////////////////////////////////////////////////////////////////////
@@ -55,7 +55,7 @@
5555
$key = array_search($auth, $authsenabled);
5656
// check auth plugin is valid
5757
if ($key === false) {
58-
print_error('pluginnotenabled', 'auth', $returnurl, $auth);
58+
throw new \moodle_exception('pluginnotenabled', 'auth', $returnurl, $auth);
5959
}
6060
// move down the list
6161
if ($key < (count($authsenabled) - 1)) {
@@ -72,7 +72,7 @@
7272
$key = array_search($auth, $authsenabled);
7373
// check auth is valid
7474
if ($key === false) {
75-
print_error('pluginnotenabled', 'auth', $returnurl, $auth);
75+
throw new \moodle_exception('pluginnotenabled', 'auth', $returnurl, $auth);
7676
}
7777
// move up the list
7878
if ($key >= 1) {

admin/blocks.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
/// Get and sort the existing blocks
7676

7777
if (!$blocks = $DB->get_records('block', array(), 'name ASC')) {
78-
print_error('noblocks', 'error'); // Should never happen
78+
throw new \moodle_exception('noblocks', 'error'); // Should never happen.
7979
}
8080

8181
$incompatible = array();

admin/category.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
$settingspage = $adminroot->locate($category, true);
4242

4343
if (empty($settingspage) or !($settingspage instanceof admin_category)) {
44-
print_error('categoryerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
44+
throw new \moodle_exception('categoryerror', 'error', "$CFG->wwwroot/$CFG->admin/");
4545
}
4646

4747
if (!($settingspage->check_access())) {
48-
print_error('accessdenied', 'admin');
48+
throw new \moodle_exception('accessdenied', 'admin');
4949
}
5050

5151
$hassiteconfig = has_capability('moodle/site:config', $PAGE->context);

admin/cli/restore_backup.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@
6969
}
7070

7171
if (!$admin = get_admin()) {
72-
print_error('noadmins');
72+
throw new \moodle_exception('noadmins');
7373
}
7474

7575
if (!file_exists($options['file'])) {
76-
print_error('filenotfound');
76+
throw new \moodle_exception('filenotfound');
7777
}
7878

7979
if (!$category = $DB->get_record('course_categories', ['id' => $options['categoryid']], 'id')) {
80-
print_error('invalidcategoryid');
80+
throw new \moodle_exception('invalidcategoryid');
8181
}
8282

8383
$backupdir = "restore_" . uniqid();
@@ -102,7 +102,7 @@
102102
} catch (Exception $e) {
103103
cli_heading(get_string('cleaningtempdata'));
104104
fulldelete($path);
105-
print_error('generalexceptionmessage', 'error', '', $e->getMessage());
105+
throw new \moodle_exception('generalexceptionmessage', 'error', '', $e->getMessage());
106106
}
107107

108108
cli_heading(get_string('restoredcourseid', 'backup', $courseid));

admin/contentbank.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
$sortorder = array_flip(array_keys($plugins));
4343

4444
if (!isset($plugins[$name])) {
45-
print_error('contenttypenotfound', 'error', $return, $name);
45+
throw new \moodle_exception('contenttypenotfound', 'error', $return, $name);
4646
}
4747

4848
switch ($action) {

admin/courseformats.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
$sortorder = array_flip(array_keys($formatplugins));
4242

4343
if (!isset($formatplugins[$formatname])) {
44-
print_error('courseformatnotfound', 'error', $return, $formatname);
44+
throw new \moodle_exception('courseformatnotfound', 'error', $return, $formatname);
4545
}
4646

4747
switch ($action) {

admin/cron.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@
5858
// check if execution allowed
5959
if (!empty($CFG->cronclionly)) {
6060
// This script can only be run via the cli.
61-
print_error('cronerrorclionly', 'admin');
61+
throw new \moodle_exception('cronerrorclionly', 'admin');
6262
exit;
6363
}
6464
// This script is being called via the web, so check the password if there is one.
6565
if (!empty($CFG->cronremotepassword)) {
6666
$pass = optional_param('password', '', PARAM_RAW);
6767
if ($pass != $CFG->cronremotepassword) {
6868
// wrong password.
69-
print_error('cronerrorpassword', 'admin');
69+
throw new \moodle_exception('cronerrorpassword', 'admin');
7070
exit;
7171
}
7272
}

admin/customfields.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
$sortorder = array_flip(array_keys($customfieldplugins));
4242

4343
if (!isset($customfieldplugins[$customfieldname])) {
44-
print_error('customfieldnotfound', 'error', $return, $customfieldname);
44+
throw new \moodle_exception('customfieldnotfound', 'error', $return, $customfieldname);
4545
}
4646

4747
switch ($action) {

admin/dataformats.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
$sortorder = array_flip(array_keys($plugins));
4343

4444
if (!isset($plugins[$name])) {
45-
print_error('courseformatnotfound', 'error', $return, $name);
45+
throw new \moodle_exception('courseformatnotfound', 'error', $return, $name);
4646
}
4747

4848
switch ($action) {

admin/environment.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@
5555
$a = new stdClass();
5656
$a->url = 'https://download.moodle.org/environment/environment.zip';
5757
$a->dest = $CFG->dataroot . '/';
58-
print_error($cd->get_error(), 'error', $PAGE->url, $a);
58+
throw new \moodle_exception($cd->get_error(), 'error', $PAGE->url, $a);
5959
die();
6060

6161
} else {
62-
print_error($cd->get_error(), 'error', $PAGE->url);
62+
throw new \moodle_exception($cd->get_error(), 'error', $PAGE->url);
6363
die();
6464
}
6565

admin/index.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,17 @@
174174
// Check some PHP server settings
175175

176176
if (ini_get_bool('session.auto_start')) {
177-
print_error('phpvaroff', 'debug', '', (object)array('name'=>'session.auto_start', 'link'=>$documentationlink));
177+
throw new \moodle_exception('phpvaroff', 'debug', '',
178+
(object)array('name' => 'session.auto_start', 'link' => $documentationlink));
178179
}
179180

180181
if (!ini_get_bool('file_uploads')) {
181-
print_error('phpvaron', 'debug', '', (object)array('name'=>'file_uploads', 'link'=>$documentationlink));
182+
throw new \moodle_exception('phpvaron', 'debug', '',
183+
(object)array('name' => 'file_uploads', 'link' => $documentationlink));
182184
}
183185

184186
if (is_float_problem()) {
185-
print_error('phpfloatproblem', 'admin', '', $documentationlink);
187+
throw new \moodle_exception('phpfloatproblem', 'admin', '', $documentationlink);
186188
}
187189

188190
// Set some necessary variables during set-up to avoid PHP warnings later on this page
@@ -203,7 +205,7 @@
203205
$CFG->target_release = $release; // used during installation and upgrades
204206

205207
if (!$version or !$release) {
206-
print_error('withoutversion', 'debug'); // without version, stop
208+
throw new \moodle_exception('withoutversion', 'debug'); // Without version, stop.
207209
}
208210

209211
if (!core_tables_exist()) {
@@ -275,7 +277,7 @@
275277
if (!$DB->setup_is_unicodedb()) {
276278
if (!$DB->change_db_encoding()) {
277279
// If could not convert successfully, throw error, and prevent installation
278-
print_error('unicoderequired', 'admin');
280+
throw new \moodle_exception('unicoderequired', 'admin');
279281
}
280282
}
281283

@@ -297,7 +299,7 @@
297299
$PAGE->set_context(context_system::instance());
298300

299301
if (empty($CFG->version)) {
300-
print_error('missingconfigversion', 'debug');
302+
throw new \moodle_exception('missingconfigversion', 'debug');
301303
}
302304

303305
// Detect config cache inconsistency, this happens when you switch branches on dev servers.
@@ -748,7 +750,7 @@
748750
redirect("index.php?sessionstarted=1&sessionverify=1&lang=$CFG->lang");
749751
} else {
750752
if (empty($SESSION->sessionverify)) {
751-
print_error('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang");
753+
throw new \moodle_exception('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang");
752754
}
753755
unset($SESSION->sessionverify);
754756
}
@@ -765,7 +767,7 @@
765767
if ($adminuser->password === 'adminsetuppending') {
766768
// prevent installation hijacking
767769
if ($adminuser->lastip !== getremoteaddr()) {
768-
print_error('installhijacked', 'admin');
770+
throw new \moodle_exception('installhijacked', 'admin');
769771
}
770772
// login user and let him set password and admin details
771773
$adminuser->newadminuser = 1;

admin/mnet/access_control.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
admin_externalpage_setup('ssoaccesscontrol');
1616

1717
if (!extension_loaded('openssl')) {
18-
print_error('requiresopenssl', 'mnet');
18+
throw new \moodle_exception('requiresopenssl', 'mnet');
1919
}
2020

2121
$sitecontext = context_system::instance();
@@ -35,13 +35,13 @@
3535

3636
// boot if insufficient permission
3737
if (!has_capability('moodle/user:delete', $sitecontext)) {
38-
print_error('nomodifyacl','mnet');
38+
throw new \moodle_exception('nomodifyacl', 'mnet');
3939
}
4040

4141
// fetch the record in question
4242
$id = required_param('id', PARAM_INT);
4343
if (!$idrec = $DB->get_record('mnet_sso_access_control', array('id'=>$id))) {
44-
print_error('recordnoexists','mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
44+
throw new \moodle_exception('recordnoexists', 'mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
4545
}
4646

4747
switch ($action) {
@@ -56,7 +56,7 @@
5656
// require the access parameter, and it must be 'allow' or 'deny'
5757
$accessctrl = trim(strtolower(required_param('accessctrl', PARAM_ALPHA)));
5858
if ($accessctrl != 'allow' and $accessctrl != 'deny') {
59-
print_error('invalidaccessparam', 'mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
59+
throw new \moodle_exception('invalidaccessparam', 'mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
6060
}
6161

6262
if (mnet_update_sso_access_control($idrec->username, $idrec->mnet_host_id, $accessctrl)) {
@@ -71,7 +71,7 @@
7171
break;
7272

7373
default:
74-
print_error('invalidactionparam', 'mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
74+
throw new \moodle_exception('invalidactionparam', 'mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
7575
}
7676
}
7777

@@ -82,7 +82,7 @@
8282

8383
// check permissions and verify form input
8484
if (!has_capability('moodle/user:delete', $sitecontext)) {
85-
print_error('nomodifyacl','mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
85+
throw new \moodle_exception('nomodifyacl', 'mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
8686
}
8787
if (empty($form->username)) {
8888
$formerror['username'] = get_string('enterausername','mnet');

admin/mnet/index.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
if (!extension_loaded('openssl')) {
1818
echo $OUTPUT->header();
1919
set_config('mnet_dispatcher_mode', 'off');
20-
print_error('requiresopenssl', 'mnet');
20+
throw new \moodle_exception('requiresopenssl', 'mnet');
2121
}
2222

2323
if (!function_exists('curl_init') ) {
2424
echo $OUTPUT->header();
2525
set_config('mnet_dispatcher_mode', 'off');
26-
print_error('nocurl', 'mnet');
26+
throw new \moodle_exception('nocurl', 'mnet');
2727
}
2828

2929
if (!isset($CFG->mnet_dispatcher_mode)) {
@@ -37,7 +37,7 @@
3737
if (set_config('mnet_dispatcher_mode', $form->mode)) {
3838
redirect('index.php', get_string('changessaved'));
3939
} else {
40-
print_error('invalidaction', '', 'index.php');
40+
throw new \moodle_exception('invalidaction', '', 'index.php');
4141
}
4242
}
4343
} elseif (!empty($form->submit) && $form->submit == get_string('delete')) {
@@ -63,13 +63,13 @@
6363

6464
if($time < time() - 60) {
6565
// fail - you're out of time.
66-
print_error ('deleteoutoftime', 'mnet', 'index.php');
66+
throw new \moodle_exception ('deleteoutoftime', 'mnet', 'index.php');
6767
exit;
6868
}
6969

7070
if ($key != md5(sha1($mnet->keypair['keypair_PEM']))) {
7171
// fail - you're being attacked?
72-
print_error ('deletewrongkeyvalue', 'mnet', 'index.php');
72+
throw new \moodle_exception ('deletewrongkeyvalue', 'mnet', 'index.php');
7373
exit;
7474
}
7575

admin/mnet/peers.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@
5454
$deprecatenotify = mnet_get_deprecation_notice();
5555

5656
if (!extension_loaded('openssl')) {
57-
print_error('requiresopenssl', 'mnet');
57+
throw new \moodle_exception('requiresopenssl', 'mnet');
5858
}
5959

6060
if (!function_exists('curl_init') ) {
61-
print_error('nocurl', 'mnet');
61+
throw new \moodle_exception('nocurl', 'mnet');
6262
}
6363

6464
if (!function_exists('xmlrpc_encode_request')) {
65-
print_error('xmlrpc-missing', 'mnet');
65+
throw new \moodle_exception('xmlrpc-missing', 'mnet');
6666
}
6767

6868
if (!isset($CFG->mnet_dispatcher_mode)) {
@@ -176,7 +176,7 @@
176176
if ($mnet_peer->commit()) {
177177
redirect(new moodle_url('/admin/mnet/peers.php', array('hostid' => $mnet_peer->id)), get_string('changessaved'));
178178
} else {
179-
print_error('invalidaction', 'error', 'index.php');
179+
throw new \moodle_exception('invalidaction', 'error', 'index.php');
180180
}
181181
} else if ($reviewform->is_submitted()) { // submitted, but errors
182182
echo $OUTPUT->header();

admin/mnet/testclient.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
include_once($CFG->dirroot.'/mnet/lib.php');
1919

2020
if ($CFG->mnet_dispatcher_mode === 'off') {
21-
print_error('mnetdisabled', 'mnet');
21+
throw new \moodle_exception('mnetdisabled', 'mnet');
2222
}
2323

2424
admin_externalpage_setup('mnettestclient');
@@ -27,7 +27,7 @@
2727

2828
echo $OUTPUT->header();
2929
if (!extension_loaded('openssl')) {
30-
print_error('requiresopenssl', 'mnet', '', NULL, true);
30+
throw new \moodle_exception('requiresopenssl', 'mnet', '', null, true);
3131
}
3232

3333
// optional drilling down parameters

admin/mnet/trustedhosts.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
if (!extension_loaded('openssl')) {
1212
echo $OUTPUT->header();
13-
print_error('requiresopenssl', 'mnet', '', NULL, true);
13+
throw new \moodle_exception('requiresopenssl', 'mnet', '', null, true);
1414
}
1515

1616
$site = get_site();

admin/modules.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
/// Get and sort the existing modules
6363

6464
if (!$modules = $DB->get_records('modules', array(), 'name ASC')) {
65-
print_error('moduledoesnotexist', 'error');
65+
throw new \moodle_exception('moduledoesnotexist', 'error');
6666
}
6767

6868
/// Print the table of all modules

admin/portfolio.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ function portfolio_action_url($portfolio) {
116116
$instance = portfolio_instance($portfolio);
117117
if ($sure) {
118118
if (!confirm_sesskey()) {
119-
print_error('confirmsesskeybad', '', $baseurl);
119+
throw new \moodle_exception('confirmsesskeybad', '', $baseurl);
120120
}
121121
if ($instance->delete()) {
122122
$deletedstr = get_string('instancedeleted', 'portfolio');
123123
redirect($baseurl, $deletedstr, 1);
124124
} else {
125-
print_error('instancenotdeleted', 'portfolio', $baseurl);
125+
throw new \moodle_exception('instancenotdeleted', 'portfolio', $baseurl);
126126
}
127127
exit;
128128
} else {

0 commit comments

Comments
 (0)