From 0184a3fd45d3a4e8f59cdd396ec1c567374e9e8b Mon Sep 17 00:00:00 2001 From: Martin Dougiamas Date: Tue, 4 May 2010 16:17:41 +0000 Subject: [PATCH] MDL-19124 Reimplementing the My Moodle default blocks for upgraded sites, to match new installs --- lib/blocklib.php | 2 +- lib/db/upgrade.php | 42 +++++++++++++++++++++++++++++++++++++++--- version.php | 2 +- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/lib/blocklib.php b/lib/blocklib.php index da697c11a03..0b0df298317 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -1785,5 +1785,5 @@ function blocks_add_default_system_blocks() { $subpagepattern = null; } - $page->blocks->add_blocks(array(BLOCK_POS_RIGHT => array('myprofile', 'private_files', 'online_users'), 'content' => array('course_overview')), 'my-index', $subpagepattern, false); + $page->blocks->add_blocks(array(BLOCK_POS_RIGHT => array('private_files', 'online_users'), 'content' => array('course_overview')), 'my-index', $subpagepattern, false); } diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 3884eadc63a..40be53e8751 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -3928,7 +3928,7 @@ AND EXISTS (SELECT 'x' } - if ($result && $oldversion < 2010050402) { // my_pages for My Moodle and Public Profile pages + if ($result && $oldversion < 2010050403) { // my_pages for My Moodle and Public Profile pages /// Define table my_pages to be created $table = new xmldb_table('my_pages'); @@ -3952,7 +3952,7 @@ AND EXISTS (SELECT 'x' $dbman->create_table($table); } - /// Add two lines of data into this new table + /// Add two lines of data into this new table. These are the default pages. $mypage = new object(); $mypage->userid = NULL; $mypage->name = '__default'; @@ -3965,9 +3965,45 @@ AND EXISTS (SELECT 'x' if (!$DB->record_exists('my_pages', array('userid'=>NULL, 'private'=>1))) { $result = $result && $DB->insert_record('my_pages', $mypage); } + + /// This bit is a "illegal" hack, unfortunately, but there is not a better way to install default + /// blocks right now, since the upgrade function need to be called after core AND plugins upgrade, + /// and there is no such hook yet. Sigh. + + if ($mypage = $DB->get_record('my_pages', array('userid'=>NULL, 'private'=>1))) { + if (!$DB->record_exists('block_instances', array('pagetypepattern'=>'my-index', 'parentcontextid'=>SITEID, 'subpagepattern'=>$mypage->id))) { + + // No default exist there yet, let's put a few into My Moodle so it's useful. + + $blockinstance = new stdClass; + $blockinstance->parentcontextid = SITEID; + $blockinstance->showinsubcontexts = 0; + $blockinstance->pagetypepattern = 'my-index'; + $blockinstance->subpagepattern = $mypage->id; + $blockinstance->configdata = ''; + + $blockinstance->blockname = 'private_files'; + $blockinstance->defaultregion = 'side-post'; + $blockinstance->defaultweight = 0; + $blockinstanceid = $DB->insert_record('block_instances', $blockinstance); + get_context_instance(CONTEXT_BLOCK, $blockinstanceid); + + $blockinstance->blockname = 'online_users'; + $blockinstance->defaultregion = 'side-post'; + $blockinstance->defaultweight = 1; + $blockinstanceid = $DB->insert_record('block_instances', $blockinstance); + get_context_instance(CONTEXT_BLOCK, $blockinstanceid); + + $blockinstance->blockname = 'course_overview'; + $blockinstance->defaultregion = 'content'; + $blockinstance->defaultweight = 0; + $blockinstanceid = $DB->insert_record('block_instances', $blockinstance); + get_context_instance(CONTEXT_BLOCK, $blockinstanceid); + } + } /// Main savepoint reached - upgrade_main_savepoint($result, 2010050402); + upgrade_main_savepoint($result, 2010050403); } diff --git a/version.php b/version.php index 03b680fb7bb..2f1ada928f4 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 = 2010050402; // YYYYMMDD = date of the last version bump + $version = 2010050403; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20100504)'; // Human-friendly version name