From: toyomoyo Date: Mon, 21 Aug 2006 05:19:16 +0000 (+0000) Subject: fix for bug #6307, reserved word 'level' changed to 'aggregatelevel' for Oracle.... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d140ad3f7c0134b9ec8b4ba24a205f86921fe4cd;p=moodle.git fix for bug #6307, reserved word 'level' changed to 'aggregatelevel' for Oracle. Some parts could be broken by this. please report breakage asap! Thanks --- diff --git a/admin/roles/assign.php b/admin/roles/assign.php index 663685d374..250def848d 100755 --- a/admin/roles/assign.php +++ b/admin/roles/assign.php @@ -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", diff --git a/admin/roles/tabs.php b/admin/roles/tabs.php index 264b273e04..9487e9d10c 100755 --- a/admin/roles/tabs.php +++ b/admin/roles/tabs.php @@ -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.'&return=true&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); } diff --git a/lib/accesslib.php b/lib/accesslib.php index 3356d0384d..fcdaab999d 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -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; diff --git a/lib/db/mysql.php b/lib/db/mysql.php index 645f39cfc9..75c932ed16 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -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; } diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql index 5c3e7ee8be..91eaf980a9 100644 --- a/lib/db/mysql.sql +++ b/lib/db/mysql.sql @@ -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'; diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index 685bfe8cf4..25fc257115 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -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; } diff --git a/lib/db/postgres7.sql b/lib/db/postgres7.sql index c55650059f..06892277b3 100644 --- a/lib/db/postgres7.sql +++ b/lib/db/postgres7.sql @@ -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, diff --git a/version.php b/version.php index 931061461e..cb56c35a40 100644 --- a/version.php +++ b/version.php @@ -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