From 3f77c1584c699b3d9255c27e3dfaf9f232e773ed Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sun, 1 Nov 2009 09:10:09 +0000 Subject: [PATCH] MDL-20697 removing duplicate error string, fixing get_site() which is now using exceptions --- auth/ldap/ntlmsso_attempt.php | 8 +------- auth/ldap/ntlmsso_finish.php | 5 +---- backup/backup_check.html | 4 +--- backup/backup_execute.html | 4 +--- backup/backup_form.html | 4 +--- backup/restore_check.html | 4 +--- backup/restore_execute.html | 4 +--- backup/restore_form.html | 4 +--- backup/restore_precheck.html | 4 +--- course/category.php | 6 ++---- course/delete.php | 6 ++---- course/import/activities/index.php | 4 +--- course/index.php | 4 +--- lang/en_utf8/debug.php | 1 - lib/datalib.php | 8 ++++---- login/index.php | 4 +--- 16 files changed, 20 insertions(+), 54 deletions(-) diff --git a/auth/ldap/ntlmsso_attempt.php b/auth/ldap/ntlmsso_attempt.php index 3b1aaaaf1d..eb268bb0f2 100644 --- a/auth/ldap/ntlmsso_attempt.php +++ b/auth/ldap/ntlmsso_attempt.php @@ -8,9 +8,7 @@ httpsrequired(); $PAGE->set_url(new moodle_url($CFG->wwwroot.'/auth/ldap/ntlmsso_attempt.php')); /// Define variables used in page -if (!$site = get_site()) { - print_error("siteisnotdefined"); -} +$site = get_site(); $authsequence = get_enabled_auth_plugins(true); // auths, in sequence if (!in_array('ldap',$authsequence,true)) { @@ -39,7 +37,3 @@ $msg = '

'.get_string('ntlmsso_attempting','auth_ldap').'

' . ' src="' . $CFG->wwwroot . '/auth/ldap/ntlmsso_magic.php?sesskey=' . $sesskey . '" />'; redirect($CFG->wwwroot . '/auth/ldap/ntlmsso_finish.php', $msg, 3); - - - -?> diff --git a/auth/ldap/ntlmsso_finish.php b/auth/ldap/ntlmsso_finish.php index 0356df34e7..93e7455980 100644 --- a/auth/ldap/ntlmsso_finish.php +++ b/auth/ldap/ntlmsso_finish.php @@ -8,9 +8,7 @@ httpsrequired(); $PAGE->set_url(new moodle_url($CFG->wwwroot.'/auth/ldap/ntlmsso_finish.php')); /// Define variables used in page -if (!$site = get_site()) { - print_error("siteisnotdefined", 'debug'); -} +$site = get_site(); $authsequence = get_enabled_auth_plugins(true); // auths, in sequence if (!in_array('ldap',$authsequence,true)) { @@ -36,4 +34,3 @@ if (!$authplugin->ntlmsso_finish()) { redirect($CFG->httpswwwroot . '/login/index.php?authldap_skipntlmsso=1', get_string('ntlmsso_failed','auth_ldap'), 3); } -?> diff --git a/backup/backup_check.html b/backup/backup_check.html index d5b034554c..0019d537e4 100644 --- a/backup/backup_check.html +++ b/backup/backup_check.html @@ -31,9 +31,7 @@ //Check site - if (!$site = get_site()) { - print_error("siteisnotdefined", 'debug'); - } + $site = get_site(); if ($count == 0) { notice("No backupable modules are installed!"); } diff --git a/backup/backup_execute.html b/backup/backup_execute.html index fd16937f50..44492e9bc9 100644 --- a/backup/backup_execute.html +++ b/backup/backup_execute.html @@ -24,9 +24,7 @@ //Check site - if (!$site = get_site()) { - print_error("siteisnotdefined", 'debug'); - } + $site = get_site(); $preferences = new StdClass; backup_fetch_prefs_from_request($preferences,$count,$course); diff --git a/backup/backup_form.html b/backup/backup_form.html index 2b08ff5f52..a4a70cee97 100644 --- a/backup/backup_form.html +++ b/backup/backup_form.html @@ -24,9 +24,7 @@ } //Check site - if (!$site = get_site()) { - print_error("siteisnotdefined", 'debug'); - } + $site = get_site(); //Checks for the required files/functions to backup every mod //And check if there is data about it diff --git a/backup/restore_check.html b/backup/restore_check.html index 528f3988cb..a00e9cf69f 100644 --- a/backup/restore_check.html +++ b/backup/restore_check.html @@ -212,9 +212,7 @@ } //Check site - if (!$site = get_site()) { - print_error("siteisnotdefined", 'debug'); - } + $site = get_site(); // Non-cached - get accessinfo if (isset($USER->access)) { diff --git a/backup/restore_execute.html b/backup/restore_execute.html index 083cd45bc4..a08418539f 100644 --- a/backup/restore_execute.html +++ b/backup/restore_execute.html @@ -60,9 +60,7 @@ } //Check site - if (!$site = get_site()) { - print_error("siteisnotdefined", 'debug'); - } + $site = get_site(); $errorstr = ''; $status = restore_execute($restore,$info,$course_header,$errorstr); diff --git a/backup/restore_form.html b/backup/restore_form.html index 3e4c90354b..c443edffeb 100644 --- a/backup/restore_form.html +++ b/backup/restore_form.html @@ -39,9 +39,7 @@ } //Check site - if (!$site = get_site()) { - print_error("siteisnotdefined", 'debug'); - } + $site = get_site(); //Checks for the required files/functions to restore every mod $count = 0; diff --git a/backup/restore_precheck.html b/backup/restore_precheck.html index e6cecbab11..20fcaa5577 100644 --- a/backup/restore_precheck.html +++ b/backup/restore_precheck.html @@ -33,9 +33,7 @@ } //Check site - if (!$site = get_site()) { - print_error("siteisnotdefined", 'debug'); - } + $site = get_site(); $errorstr = ''; if (!empty($SESSION->restore->importing)) { diff --git a/course/category.php b/course/category.php index 8b47748d03..1e0ae14397 100644 --- a/course/category.php +++ b/course/category.php @@ -17,10 +17,8 @@ $moveto = optional_param('moveto', 0, PARAM_INT); $resort = optional_param('resort', 0, PARAM_BOOL); - if (!$site = get_site()) { - print_error('siteisnotdefined', 'debug'); - } - + $site = get_site(); + if (empty($id)) { print_error("unknowcategory"); } diff --git a/course/delete.php b/course/delete.php index 567b3d8f88..eac3987abc 100644 --- a/course/delete.php +++ b/course/delete.php @@ -14,10 +14,8 @@ print_error('cannotdeletecourse'); } - if (!$site = get_site()) { - print_error("siteisnotdefined", 'debug'); - } - + $site = get_site(); + $strdeletecourse = get_string("deletecourse"); $stradministration = get_string("administration"); $strcategories = get_string("categories"); diff --git a/course/import/activities/index.php b/course/import/activities/index.php index 6814aab75c..63f942cd31 100644 --- a/course/import/activities/index.php +++ b/course/import/activities/index.php @@ -56,9 +56,7 @@ if (! ($course = $DB->get_record("course", array("id"=>$id)))) { print_error("invalidcourseid"); } -if (!$site = get_site()){ - print_error("siteisnotdefined", 'debug'); -} +$site = get_site(); require_login($course->id); $tocontext = get_context_instance(CONTEXT_COURSE, $id); diff --git a/course/index.php b/course/index.php index 624efb02aa..ff82fd5190 100644 --- a/course/index.php +++ b/course/index.php @@ -36,9 +36,7 @@ $moveto = optional_param('moveto',-1,PARAM_INT); $moveup = optional_param('moveup',0,PARAM_INT); $movedown = optional_param('movedown',0,PARAM_INT); -if (!$site = get_site()) { - print_error('siteisnotdefined', 'debug'); -} +$site = get_site(); $systemcontext = get_context_instance(CONTEXT_SYSTEM); diff --git a/lang/en_utf8/debug.php b/lang/en_utf8/debug.php index 3f7bf2b6f3..8f5f7bcfd9 100644 --- a/lang/en_utf8/debug.php +++ b/lang/en_utf8/debug.php @@ -31,7 +31,6 @@ $string['modulenotexist'] = '$a module doesn\'t exist'; $string['phpvaroff'] = 'The PHP server variable \'$a->name\' should be Off - $a->link'; $string['phpvaron'] = 'The PHP server variable \'$a->name\' is not turned On - $a->link'; $string['sessionmissing'] = '$a object missing from session'; -$string['siteisnotdefined'] = 'Site is not defined!'; $string['sqlrelyonobsoletetable'] = 'This SQL relies on obsolete table(s): $a! Your code must be fixed by a developer.'; $string['withoutversion'] = 'Main version.php file is missing, not readable or broken.'; $string['xmlizeunavailable'] = 'xmlize functions are not available'; diff --git a/lib/datalib.php b/lib/datalib.php index a1fce76084..ab0281194c 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -405,9 +405,7 @@ function get_users_confirmed() { /** * Returns $course object of the top-level site. * - * @global object - * @global object - * @return bool|object A {@link $COURSE} object for the site + * @return object A {@link $COURSE} object for the site, exception if not found */ function get_site() { global $SITE, $DB; @@ -419,7 +417,9 @@ function get_site() { if ($course = $DB->get_record('course', array('category'=>0))) { return $course; } else { - return false; + // course table exists, but the site is not there, + // unfortunately there is no automatic way to recover + throw new moodle_exception('nosite', 'error'); } } diff --git a/login/index.php b/login/index.php index a8c19e43b8..0d03fadf53 100644 --- a/login/index.php +++ b/login/index.php @@ -61,9 +61,7 @@ httpsrequired(); $PAGE->set_url("$CFG->httpswwwroot/login/index.php"); /// Define variables used in page -if (!$site = get_site()) { - print_error('siteisnotdefined', 'debug'); -} +$site = get_site(); if (empty($CFG->langmenu)) { $langmenu = ""; -- 2.39.5