From 13a0d3d3c9afa7f0b3997e6cff488a24fa017d22 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Fri, 10 Jul 2009 05:58:59 +0000 Subject: [PATCH] blocks MDL-19536: rename block_instances.contextid to parentcontextid to avoid gross confusion --- lib/accesslib.php | 6 +++--- lib/blocklib.php | 25 +++++++++++++++++-------- lib/db/install.xml | 14 +++++++------- lib/db/upgrade.php | 27 ++++++++++++++++++++------- version.php | 2 +- 5 files changed, 48 insertions(+), 26 deletions(-) diff --git a/lib/accesslib.php b/lib/accesslib.php index 900148dfe1..325bd485b5 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -2224,7 +2224,7 @@ function create_context($contextlevel, $instanceid) { // Only non-pinned & course-page based $sql = "SELECT ctx.path, ctx.depth FROM {context} ctx - JOIN {block_instances} bi ON (bi.contextid=ctx.id) + JOIN {block_instances} bi ON (bi.parentcontextid=ctx.id) WHERE bi.id=? AND ctx.contextlevel=?"; $params = array($instanceid, CONTEXT_COURSE); if ($p = $DB->get_record_sql($sql, $params)) { @@ -2539,7 +2539,7 @@ function preload_course_contexts($courseid) { SELECT x.instanceid, x.id, x.contextlevel, x.path, x.depth FROM {context} px - JOIN {block_instances} bi ON bi.contextid = px.id + JOIN {block_instances} bi ON bi.parentcontextid = px.id JOIN {context} x ON x.instanceid=bi.id WHERE px.instanceid = ? AND px.contextlevel = ".CONTEXT_COURSE." AND x.contextlevel=".CONTEXT_BLOCK." @@ -6076,7 +6076,7 @@ function build_context_path($force=false) { SELECT ctx.id, ".$DB->sql_concat('pctx.path', "'/'", 'ctx.id').", pctx.depth+1 FROM {context} ctx JOIN {block_instances} bi ON ctx.instanceid = bi.id - JOIN {context} pctx ON bi.contextid = pctx.id + JOIN {context} pctx ON bi.parentcontextid = pctx.id WHERE ctx.contextlevel=".CONTEXT_BLOCK." AND NOT EXISTS (SELECT 'x' FROM {context_temp} temp diff --git a/lib/blocklib.php b/lib/blocklib.php index 2cca159d1b..f6cb661198 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -25,21 +25,30 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -/** - * Block Defines +/**#@+ + * @deprecated since Moodle 2.0. No longer used. */ define('BLOCK_MOVE_LEFT', 0x01); define('BLOCK_MOVE_RIGHT', 0x02); define('BLOCK_MOVE_UP', 0x04); define('BLOCK_MOVE_DOWN', 0x08); define('BLOCK_CONFIGURE', 0x10); +/**#@-*/ +/**#@+ + * Default names for the block regions in the standard theme. + */ define('BLOCK_POS_LEFT', 'side-pre'); define('BLOCK_POS_RIGHT', 'side-post'); +/**#@-*/ +/**#@+ + * @deprecated since Moodle 2.0. No longer used. + */ define('BLOCKS_PINNED_TRUE',0); define('BLOCKS_PINNED_FALSE',1); define('BLOCKS_PINNED_BOTH',2); +/**#@-*/ /** * Exception thrown when someone tried to do something with a block that does @@ -379,13 +388,13 @@ class block_manager { } $context = $this->page->context; - $contexttest = 'bi.contextid = :contextid2'; + $contexttest = 'bi.parentcontextid = :contextid2'; $parentcontextparams = array(); $parentcontextids = get_parent_contexts($context); if ($parentcontextids) { list($parentcontexttest, $parentcontextparams) = $DB->get_in_or_equal($parentcontextids, SQL_PARAMS_NAMED, 'parentcontext0000'); - $contexttest = "($contexttest OR (bi.showinsubcontexts = 1 AND bi.contextid $parentcontexttest))"; + $contexttest = "($contexttest OR (bi.showinsubcontexts = 1 AND bi.parentcontextid $parentcontexttest))"; } $pagetypepatterns = $this->matching_page_type_patterns($this->page->pagetype); @@ -403,7 +412,7 @@ class block_manager { bi.id, bp.id AS blockpositionid, bi.blockname, - bi.contextid, + bi.parentcontextid, bi.showinsubcontexts, bi.pagetypepattern, bi.subpagepattern, @@ -473,7 +482,7 @@ class block_manager { $blockinstance = new stdClass; $blockinstance->blockname = $blockname; - $blockinstance->contextid = $this->page->context->id; + $blockinstance->parentcontextid = $this->page->context->id; $blockinstance->showinsubcontexts = !empty($showinsubcontexts); $blockinstance->pagetypepattern = $pagetypepattern; $blockinstance->subpagepattern = $subpagepattern; @@ -902,7 +911,7 @@ function blocks_delete_all_for_context($contextid) { blocks_delete_instance($instance, true); } $instances->close(); - $DB->delete_records('block_instances', array('contextid' => $contextid)); + $DB->delete_records('block_instances', array('parentcontextid' => $contextid)); $DB->delete_records('block_positions', array('contextid' => $contextid)); } @@ -1204,7 +1213,7 @@ function blocks_execute_action($page, &$blockmanager, $blockaction, $instanceori $region = $page->blocks->get_default_region(); $weight = $DB->get_field_sql("SELECT MAX(defaultweight) FROM {block_instances} - WHERE contextid = ? AND defaultregion = ?", array($page->context->id, $region)); + WHERE parentcontextid = ? AND defaultregion = ?", array($page->context->id, $region)); $pagetypepattern = $page->pagetype; if (strpos($pagetypepattern, 'course-view') === 0) { $pagetypepattern = 'course-view-*'; diff --git a/lib/db/install.xml b/lib/db/install.xml index 63412c2575..6188bb2709 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -2177,12 +2177,12 @@ - +
- - - + + + @@ -2190,11 +2190,11 @@ - - + + - +
diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index d6a7f2c9f0..27d603694d 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -23,7 +23,7 @@ function xmldb_main_upgrade($oldversion) { global $CFG, $THEME, $USER, $DB; require_once($CFG->libdir.'/db/upgradelib.php'); // Core Upgrade-related functions - + $result = true; $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes @@ -2229,7 +2229,7 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); } if ($result && $oldversion < 2009061704) { - // change component string in capability records to new "_" format + // change component string in capability records to new "_" format if ($caps = $DB->get_records('capabilities')) { foreach ($caps as $cap) { $cap->component = str_replace('/', '_', $cap->component); @@ -2241,7 +2241,7 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); } if ($result && $oldversion < 2009061705) { - // change component string in events_handlers records to new "_" format + // change component string in events_handlers records to new "_" format if ($handlers = $DB->get_records('events_handlers')) { foreach ($handlers as $handler) { $handler->handlermodule = str_replace('/', '_', $handler->handlermodule); @@ -2253,7 +2253,7 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); } if ($result && $oldversion < 2009061706) { - // change component string in message_providers records to new "_" format + // change component string in message_providers records to new "_" format if ($mps = $DB->get_records('message_providers')) { foreach ($mps as $mp) { $mp->component = str_replace('/', '_', $mp->component); @@ -2263,7 +2263,7 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); unset($caps); upgrade_main_savepoint($result, 2009061706); } - + if ($result && $oldversion < 2009063000) { // upgrade format of _with_advanced settings - quiz only // note: this can be removed later, not needed for upgrades from 1.9.x @@ -2276,10 +2276,10 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); set_config($newname, $value, 'quiz'); unset_config($name, 'quiz'); } - } + } upgrade_main_savepoint($result, 2009063000); } - + if ($result && $oldversion < 2009070100) { // MDL-19677 Change $CFG->bloglevel to BLOG_SITE_LEVEL if BLOG_COURSE_LEVEL or BLOG_GROUP_LEVEL $current_bloglevel = get_config(null, 'bloglevel'); @@ -2289,6 +2289,19 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); } } + if ($result && $oldversion < 2009071000) { + + /// Rename field contextid on table block_instances to parentcontextid + $table = new xmldb_table('block_instances'); + $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'blockname'); + + /// Launch rename field parentcontextid + $dbman->rename_field($table, $field, 'parentcontextid'); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009071000); + } + return $result; } diff --git a/version.php b/version.php index ace646873f..3a8b325677 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 = 2009070100; // YYYYMMDD = date of the last version bump + $version = 2009071000; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20090710)'; // Human-friendly version name -- 2.39.5