]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17458 $CFG->rolesactive cleanup + other cleanup in upgrade code
authorskodak <skodak>
Thu, 15 Jan 2009 22:09:57 +0000 (22:09 +0000)
committerskodak <skodak>
Thu, 15 Jan 2009 22:09:57 +0000 (22:09 +0000)
admin/settings/top.php
index.php
lib/accesslib.php
lib/adminlib.php
lib/deprecatedlib.php
login/index.php

index b44a58e2a500643b7c0c71d3df6918e62f373bda..f1069217ad583ed35c5a293c894632b91f816ee6 100644 (file)
@@ -6,12 +6,7 @@
 // are added to them.
 
 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
-if (empty($CFG->rolesactive)) {
-    // installation starts - no permission checks
-    $hassiteconfig = true;
-} else {
-    $hassiteconfig = has_capability('moodle/site:config', $systemcontext);
-}
+$hassiteconfig = has_capability('moodle/site:config', $systemcontext);
 
 $ADMIN->add('root', new admin_externalpage('adminnotifications', get_string('notifications'), "$CFG->wwwroot/$CFG->admin/index.php"));
 
index f6449e0643ee7a50d70c58499bf8e068dceed7f0..4f39b5b8b118fcdd56827c5f35e45da4437fcc5a 100644 (file)
--- a/index.php
+++ b/index.php
     require_once($CFG->dirroot .'/course/lib.php');
     require_once($CFG->dirroot .'/lib/blocklib.php');
 
-    if (empty($SITE)) {
-        redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
-    }
-
     // Bounds for block widths
     // more flexible for theme designers taken from theme config.php
     $lmin = (empty($THEME->block_l_min_width)) ? 100 : $THEME->block_l_min_width;
     define('BLOCK_R_MAX_WIDTH', $rmax);
 
     // check if major upgrade needed - also present in login/index.php
-    if ((int)$CFG->version < 2006101100) { //1.7 or older
+    if (empty($CFG->version) or (int)$CFG->version < 2009011400) { //1.9 or older
         @require_logout();
         redirect("$CFG->wwwroot/$CFG->admin/");
     }
-    // Trigger 1.9 accesslib upgrade?
-    if ((int)$CFG->version < 2007092000 
-        && isset($USER->id) 
-        && is_siteadmin($USER->id)) { // this test is expensive, but is only triggered during the upgrade
-        redirect("$CFG->wwwroot/$CFG->admin/");
-    }
 
     if ($CFG->forcelogin) {
         require_login();
         user_accesstime_log();
     }
 
-    if (!empty($CFG->rolesactive)) { // if already using roles system
-        if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
-            if (moodle_needs_upgrading()) {
-                redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
-            }
-        } else if (!empty($CFG->mymoodleredirect)) {    // Redirect logged-in users to My Moodle overview if required
-            if (isloggedin() && $USER->username != 'guest') {
-                redirect($CFG->wwwroot .'/my/index.php');
-            }
-        }
-    } else { // if upgrading from 1.6 or below
-        if (is_siteadmin($USER->id) && moodle_needs_upgrading()) {
+    if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
+        if (moodle_needs_upgrading()) {
             redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
         }
+    } else if (!empty($CFG->mymoodleredirect)) {    // Redirect logged-in users to My Moodle overview if required
+        if (isloggedin() && $USER->username != 'guest') {
+            redirect($CFG->wwwroot .'/my/index.php');
+        }
     }
 
 
index 593b4575546909bc0f96d0daa04d2097d294cc18..8b1bfe348a466619c3bcd1d1ac7dc3a133cb3cd8 100755 (executable)
@@ -351,7 +351,16 @@ function get_guest_role() {
  * @return bool
  */
 function has_capability($capability, $context, $userid=NULL, $doanything=true) {
-    global $USER, $ACCESS, $CFG, $DIRTYCONTEXTS, $DB;
+    global $USER, $ACCESS, $CFG, $DIRTYCONTEXTS, $DB, $SCRIPT;
+
+    if (empty($CFG->rolesactive)) {
+        if ($SCRIPT === "/$CFG->admin/index.php" or $SCRIPT === "/$CFG->admin/cliupgrade.php") {
+            // we are in an installer - roles can not work yet
+            return true;
+        } else {
+            return false;
+        }
+    }
 
     // the original $CONTEXT here was hiding serious errors
     // for security reasons do not reuse previous context
@@ -1177,12 +1186,6 @@ function get_user_access_sitewide($userid) {
 
     global $CFG, $DB;
 
-    // this flag has not been set!
-    // (not clean install, or upgraded successfully to 1.7 and up)
-    if (empty($CFG->rolesactive)) {
-        return false;
-    }
-
     /* Get in 3 cheap DB queries...
      * - role assignments - with role_caps
      * - relevant role caps
@@ -1614,6 +1617,7 @@ function compact_rdefs(&$rdefs) {
 function load_all_capabilities() {
     global $USER, $CFG, $DIRTYCONTEXTS;
 
+    // roles not installed yet - we are in the middle of installation
     if (empty($CFG->rolesactive)) {
         return;
     }
index 65fff3e0a4fdc1b2189086219be010a21352ffe3..3b8768293ae3df04a1d5f8ac6fa96e671a3571f6 100644 (file)
@@ -1594,9 +1594,6 @@ class admin_externalpage implements part_of_admin_tree {
      */
     public function check_access() {
         global $CFG;
-        if (empty($CFG->rolesactive)) {
-            return true; // no access check before site is fully set up
-        }
         $context = empty($this->context) ? get_context_instance(CONTEXT_SYSTEM) : $this->context;
         foreach($this->req_capability as $cap) {
             if (is_valid_capability($cap) and has_capability($cap, $context)) {
@@ -1745,9 +1742,6 @@ class admin_settingpage implements part_of_admin_tree {
     // see admin_externalpage
     public function check_access() {
         global $CFG;
-        if (empty($CFG->rolesactive)) {
-            return true; // no access check before site is fully set up
-        }
         $context = empty($this->context) ? get_context_instance(CONTEXT_SYSTEM) : $this->context;
         foreach($this->req_capability as $cap) {
             if (is_valid_capability($cap) and has_capability($cap, $context)) {
index 9a8cfdc3586b0a5b6b985ab1ef03175e4f15214b..cb5ea143687c40ae0565d4f9af26ca7478847de7 100644 (file)
@@ -49,10 +49,6 @@ function isteacher($courseid=0, $userid=0, $obsolete_includeadmin=true) {
 /// Is the user able to access this course as a teacher?
     global $CFG;
 
-    if (empty($CFG->rolesactive)) {     // Teachers are locked out during an upgrade to 1.7
-        return false;
-    }
-
     if ($courseid) {
         $context = get_context_instance(CONTEXT_COURSE, $courseid);
     } else {
@@ -75,10 +71,6 @@ function isteacher($courseid=0, $userid=0, $obsolete_includeadmin=true) {
 function isteacherinanycourse($userid=0, $includeadmin=true) {
     global $USER, $CFG, $DB;
 
-    if (empty($CFG->rolesactive)) {     // Teachers are locked out during an upgrade to 1.7
-        return false;
-    }
-
     if (!$userid) {
         if (empty($USER->id)) {
             return false;
@@ -129,10 +121,6 @@ function isteacherinanycourse($userid=0, $includeadmin=true) {
 function isguest($userid=0) {
     global $CFG;
 
-    if (empty($CFG->rolesactive)) {
-        return false;
-    }
-
     $context = get_context_instance(CONTEXT_SYSTEM);
 
     return has_capability('moodle/legacy:guest', $context, $userid, false);
index 2ddacda86f57484b80a28f4f623583c0c8b4394f..0a67aa89389c81ebaa7c9e8fd05d023a45b9c878 100644 (file)
@@ -4,7 +4,7 @@
     require_once("../config.php");
 
     // check if major upgrade needed - also present in /index.php
-    if ((int)$CFG->version < 2006101100) { //1.7 or older
+    if ((int)$CFG->version < 2009011400) { //1.9 or older
         @require_logout();
         redirect("$CFG->wwwroot/$CFG->admin/");
     }
         $session_has_timed_out = false;
     }
 
-// setup and verify auth settings
-
-if (!isset($CFG->registerauth)) {
-    set_config('registerauth', '');
-}
-
-if (!isset($CFG->auth_instructions)) {
-    set_config('auth_instructions', '');
-}
-
 // auth plugins may override these - SSO anyone?
 $frm  = false;
 $user = false;