Skip to content

Commit

Permalink
MDL-19124 Reimplementing the My Moodle default blocks for upgraded si…
Browse files Browse the repository at this point in the history
…tes, to match new installs
  • Loading branch information
moodler committed May 4, 2010
1 parent 7227d83 commit 0184a3f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/blocklib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
42 changes: 39 additions & 3 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3928,7 +3928,7 @@ function xmldb_main_upgrade($oldversion) {
}


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');
Expand All @@ -3952,7 +3952,7 @@ function xmldb_main_upgrade($oldversion) {
$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';
Expand All @@ -3965,9 +3965,45 @@ function xmldb_main_upgrade($oldversion) {
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);
}


Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0184a3f

Please sign in to comment.