]> git.mjollnir.org Git - moodle.git/commitdiff
fix for bug #6307, reserved word 'level' changed to 'aggregatelevel' for Oracle....
authortoyomoyo <toyomoyo>
Mon, 21 Aug 2006 05:19:16 +0000 (05:19 +0000)
committertoyomoyo <toyomoyo>
Mon, 21 Aug 2006 05:19:16 +0000 (05:19 +0000)
admin/roles/assign.php
admin/roles/tabs.php
lib/accesslib.php
lib/db/mysql.php
lib/db/mysql.sql
lib/db/postgres7.php
lib/db/postgres7.sql
version.php

index 663685d37402e9fcc4a18e9879140163db62242b..250def848df0928af8b59d5959d1c6679ef399c0 100755 (executable)
@@ -65,9 +65,9 @@
     $participants = get_string("participants");
     $user = get_record('user', 'id', $userid);
     $fullname = fullname($user, isteacher($course->id));
-    
+
     // we got a few tabs there
-    if ($context->level == CONTEXT_USERID) {
+    if ($context->aggregatelevel == CONTEXT_USERID) {
         /// course header
         if ($courseid!= SITEID) {
             print_header("$fullname", "$fullname",
index 264b273e04e0f7c7687bf9e06c3a5a966c156825..9487e9d10c7abaee2b144203647a2990a8ef7050 100755 (executable)
@@ -2,7 +2,7 @@
 // this deals with tabs, as well as print_headers for navigation
 
 if ($currenttab != 'update') {
-    switch ($context->level) {
+    switch ($context->aggregatelevel) {
       
         case CONTEXT_SYSTEM:
             $stradministration = get_string('administration');
@@ -77,7 +77,7 @@ if ($currenttab != 'update') {
 
 
     // Printing the tabs
-    if ($context->level == CONTEXT_MODULE) { // only show update button if module?
+    if ($context->aggregatelevel == CONTEXT_MODULE) { // only show update button if module?
     
         $toprow[] = new tabobject('update', $CFG->wwwroot.'/course/mod.php?update='.$context->instanceid.'&amp;return=true&amp;sesskey='.sesskey(), get_string('update'));
         
@@ -90,7 +90,7 @@ if ($currenttab != 'update') {
 
         $secondrow[] = new tabobject('assign', $CFG->wwwroot.'/admin/roles/assign.php?contextid='.$context->id, get_string('assignroles', 'role')); 
                 
-        if ($context->level == CONTEXT_SYSTEM) {
+        if ($context->aggregatelevel == CONTEXT_SYSTEM) {
             $secondrow[] = new tabobject('override', '', get_string('overrideroles', 'role'));         
         } else {
             $secondrow[] = new tabobject('override', $CFG->wwwroot.'/admin/roles/override.php?contextid='.$context->id,
@@ -113,7 +113,7 @@ if ($currenttab != 'update') {
         $tabs = array($toprow);
     }
     
-    if ($context->level != CONTEXT_SYSTEM) { // do not show tabs otherwise
+    if ($context->aggregatelevel != CONTEXT_SYSTEM) { // do not show tabs otherwise
         print_tabs($tabs, $currenttab, $inactive);
     }
 
index 3356d0384d691ebceca566ee5135a3ba1f14a607..fcdaab999d7b17685189e43b79a3305d5a9d385e 100755 (executable)
@@ -144,7 +144,7 @@ function has_capability($capability, $context=NULL, $userid=NULL) {
         return ($capabilities[$sitecontext->id]['moodle/site:doanything']);
     }
     
-    switch ($context->level) {
+    switch ($context->aggregatelevel) {
         
         case CONTEXT_COURSECAT:
             // Check parent cats.
@@ -262,7 +262,7 @@ function capability_search($capability, $context, $capabilities) {
     /* Then, we check the cache recursively */
     $permission = 0;    
     
-    switch ($context->level) {
+    switch ($context->aggregatelevel) {
 
         case CONTEXT_SYSTEM: // by now it's a definite an inherit
             $permission = 0;
@@ -338,7 +338,7 @@ function capability_search($capability, $context, $capabilities) {
  *                   [273][blah blah blah] = 2
  */
 function load_user_capability($capability='', $context ='', $userid='') {
-    
+
     global $USER, $CFG;
 
     if (empty($userid)) {
@@ -372,7 +372,7 @@ function load_user_capability($capability='', $context ='', $userid='') {
 
     $siteinstance = get_context_instance(CONTEXT_SYSTEM, SITEID);
 
-    $SQL = " SELECT  rc.capability, c1.id, (c1.level * 100) AS aggregatelevel,
+    $SQL = " SELECT  rc.capability, c1.id, (c1.aggregatelevel * 100) AS aggregatelevel,
                      SUM(rc.permission) AS sum
                      FROM
                      {$CFG->prefix}role_assignments AS ra, 
@@ -391,7 +391,7 @@ function load_user_capability($capability='', $context ='', $userid='') {
                      SUM(rc.permission) != 0
               UNION
 
-              SELECT rc.capability, c1.id, (c1.level * 100 + c2.level) AS aggregatelevel,
+              SELECT rc.capability, c1.id, (c1.aggregatelevel * 100 + c2.aggregatelevel) AS aggregatelevel,
                      SUM(rc.permission) AS sum
                      FROM
                      {$CFG->prefix}role_assignments AS ra,
@@ -431,7 +431,7 @@ function load_user_capability($capability='', $context ='', $userid='') {
             $rs->MoveNext();
         }
     }
-
+    
     /* so up to this point we should have somethign like this
      * $capabilities[1]    ->aggregatelevel = 1000
                            ->module = SITEID
@@ -554,7 +554,7 @@ function capability_prohibits($capability, $context, $sum='', $array='') {
             return true;
         }
     }
-    switch ($context->level) {
+    switch ($context->aggregatelevel) {
         
         case CONTEXT_SYSTEM:
             // By now it's a definite an inherit.
@@ -816,10 +816,10 @@ function islegacy($capabilityname) {
  * @param $level
  * @param $instanceid
  */
-function create_context($level, $instanceid) {
-    if (!get_record('context','level',$level,'instanceid',$instanceid)) {
+function create_context($aggregatelevel, $instanceid) {
+    if (!get_record('context','aggregatelevel',$aggregatelevel,'instanceid',$instanceid)) {
         $context = new object;
-        $context->level = $level;
+        $context->aggregatelevel = $aggregatelevel;
         $context->instanceid = $instanceid;
         return insert_record('context',$context);
     }
@@ -832,12 +832,10 @@ function create_context($level, $instanceid) {
  * @param $level
  * @param $instance
  */
-function get_context_instance($level=NULL, $instance=SITEID) {
-
-    global $CONTEXT, $context_cache, $context_cache_id;
+function get_context_instance($aggregatelevel=NULL, $instance=SITEID) {
 
 /// If no level is supplied then return the current global context if there is one
-    if (empty($level)) {
+    if (empty($aggregatelevel)) {
         if (empty($CONTEXT)) {
             if ($CFG->debug > 7) {
                 notify("Error: get_context_instance() called without a context");
@@ -848,18 +846,18 @@ function get_context_instance($level=NULL, $instance=SITEID) {
     }
 
 /// Check the cache
-    if (isset($context_cache[$level][$instance])) {  // Already cached
-        return $context_cache[$level][$instance];
+    if (isset($context_cache[$aggregatelevel][$instance])) {  // Already cached
+        return $context_cache[$aggregatelevel][$instance];
     }
 
 /// Get it from the database, or create it
-    if (!$context = get_record('context', 'level', $level, 'instanceid', $instance)) {
-        create_context($level, $instance);
-        $context = get_record('context', 'level', $level, 'instanceid', $instance);
+    if (!$context = get_record('context', 'aggregatelevel', $aggregatelevel, 'instanceid', $instance)) {
+        create_context($aggregatelevel, $instance);
+        $context = get_record('context', 'aggregatelevel', $aggregatelevel, 'instanceid', $instance);
     }
 
 /// Update the cache
-    $context_cache[$level][$instance] = $context;    // Cache it for later
+    $context_cache[$aggregatelevel][$instance] = $context;    // Cache it for later
     $context_cache_id[$context->id] = $context;      // Cache it for later
 
 
@@ -878,7 +876,7 @@ function get_context_instance_by_id($id) {
     }
 
     if ($context = get_record('context', 'id', $id)) {   // Update the cache and return
-        $context_cache[$context->level][$context->instanceid] = $context;
+        $context_cache[$context->aggregatelevel][$context->instanceid] = $context;
         $context_cache_id[$context->id] = $context;
         return $context;
     }
@@ -1228,7 +1226,7 @@ function capabilities_cleanup($component, $newcapdef=NULL) {
 function print_context_name($context) {
 
     $name = '';
-    switch ($context->level) {
+    switch ($context->aggregatelevel) {
 
         case CONTEXT_SYSTEM: // by now it's a definite an inherit
             $name = get_string('site');
@@ -1309,7 +1307,7 @@ function fetch_context_capabilities($context) {
 
     $sort = 'ORDER BY contextlevel,component,id';   // To group them sensibly for display
       
-    switch ($context->level) {
+    switch ($context->aggregatelevel) {
 
         case CONTEXT_SYSTEM: // all
             $SQL = "select * from {$CFG->prefix}capabilities";
@@ -1384,7 +1382,7 @@ function role_context_capabilities($roleid, $context) {
             where rc.contextid in $contexts
             and rc.roleid = $roleid
             and rc.contextid = c.id
-            ORDER BY c.level DESC, rc.capability DESC";
+            ORDER BY c.aggregatelevel DESC, rc.capability DESC";
             
     $records = get_records_sql($SQL);
     
@@ -1410,7 +1408,7 @@ function role_context_capabilities($roleid, $context) {
  */
 function get_parent_contexts($context) {
   
-    switch ($context->level) {
+    switch ($context->aggregatelevel) {
 
         case CONTEXT_SYSTEM: // no parent
             return null;
index 645f39cfc9056caf0369b1ccfd078e007289afcc..75c932ed16dd34000ff5332a1cdb1d0c9655f22e 100644 (file)
@@ -2127,6 +2127,13 @@ function main_upgrade($oldversion=0) {
                     )", true); 
         
     }
+    
+    if ($oldversion < 2006082100) {
+        execute_sql("ALTER TABLE `{$CFG->prefix}context` DROP INDEX `level-instanceid`;",false);
+        table_column('context', 'level', 'aggregatelevel', 'int', '10', 'unsigned', '0', 'not null', '');
+        execute_sql("ALTER TABLE `{$CFG->prefix}context` ADD UNIQUE INDEX `aggregatelevel-instanceid` (`aggregatelevel`, `instanceid`)",false);
+    }
+    
     return $result;
 }
 
index 5c3e7ee8bec7ebd2c80b496942d3d120a0117482..91eaf980a96aaa3a1c0699ebef2e885e75f0232f 100644 (file)
@@ -914,10 +914,10 @@ CREATE TABLE prefix_role (
 
 CREATE TABLE prefix_context (
   `id` int(10) unsigned NOT NULL auto_increment,
-  `level` int(10) unsigned NOT NULL default '0',
+  `aggregatelevel` int(10) unsigned NOT NULL default '0',
   `instanceid` int(10) unsigned NOT NULL default '0',
   KEY `instanceid` (`instanceid`),
-  UNIQUE KEY `level-instanceid` (`level`, `instanceid`),
+  UNIQUE KEY `aggregatelevel-instanceid` (`aggregatelevel`, `instanceid`),
   PRIMARY KEY  (`id`)
 ) TYPE=MyISAM COMMENT ='one of these must be set';
 
index 685bfe8cf454d1a91a1eb9a2e6d08dfd7bbdb7da..25fc25711561a8c3ccaf3fd3663983b58ee8e3a4 100644 (file)
@@ -1726,6 +1726,12 @@ function main_upgrade($oldversion=0) {
         modify_database('',"CREATE UNIQUE INDEX prefix_role_allow_override_roleidallowoverride_idx ON prefix_role_allow_override (roleid, allowoverride);");
                
     }
+    
+    if ($oldversion < 2006082100) {
+        execute_sql("DROP INDEX {$CFG->prefix}context_levelinstanceid_idx;",false);
+        table_column('context', 'level', 'aggregatelevel', 'integer', '10', 'unsigned', '0', 'not null', '');
+        modify_database('',"CREATE UNIQUE INDEX prefix_context_aggregatelevelinstanceid_idx ON prefix_context (aggregatelevel, instanceid);"); 
+    }
     return $result;
 }
 
index c55650059f8b0ff7be1f16cfcc265e7a592799b5..06892277b3c9a2278705ffc7748a6f3bb9ad0945 100644 (file)
@@ -681,11 +681,11 @@ CREATE INDEX prefix_role_sortorder_idx ON prefix_role (sortorder);
          
 CREATE TABLE prefix_context (    
   id SERIAL PRIMARY KEY,     
-  level integer NOT NULL default 0,      
+  aggregatelevel integer NOT NULL default 0,      
   instanceid integer NOT NULL default 0      
 );
 CREATE INDEX prefix_context_instanceid_idx ON prefix_context (instanceid);
-CREATE UNIQUE INDEX prefix_context_levelinstanceid_idx ON prefix_context (level, instanceid);
+CREATE UNIQUE INDEX prefix_context_aggregatelevelinstanceid_idx ON prefix_context (aggregatelevel, instanceid);
          
 CREATE TABLE prefix_role_assignments (   
   id SERIAL PRIMARY KEY,     
index 931061461e347483550474c4bc6886b07c76554a..cb56c35a40f4d113c1eebb38c96862243c5471a2 100644 (file)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-   $version = 2006081700;  // YYYYMMDD = date
+   $version = 2006082100;  // YYYYMMDD = date
                            //       XY = increments within a single day
 
    $release = '1.7 dev';    // Human-friendly version name