mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 00:16:46 +02:00
MDL-47189 my: Fix the addition of default blocks to my/ page
Fixing the upgrade script so that they attach the new blocks to the right my_pages entry. An upgrade script has also been added to fix the existing bad data.
This commit is contained in:
parent
d3ff82257e
commit
00fd3c1aad
6 changed files with 97 additions and 38 deletions
|
@ -49,20 +49,25 @@ function xmldb_block_badges_upgrade($oldversion, $block) {
|
|||
// Add this block the default blocks on /my.
|
||||
$blockname = 'badges';
|
||||
|
||||
$page = new moodle_page();
|
||||
$page->set_context(context_system::instance());
|
||||
// Do not try to add the block if we cannot find the default my_pages entry.
|
||||
// Private => 1 refers to MY_PAGE_PRIVATE.
|
||||
if ($systempage = $DB->get_record('my_pages', array('userid' => null, 'private' => 1))) {
|
||||
$page = new moodle_page();
|
||||
$page->set_context(context_system::instance());
|
||||
|
||||
// Check to see if this block is already on the default /my page.
|
||||
$criteria = array(
|
||||
'blockname' => $blockname,
|
||||
'parentcontextid' => $page->context->id,
|
||||
'pagetypepattern' => 'my-index'
|
||||
);
|
||||
// Check to see if this block is already on the default /my page.
|
||||
$criteria = array(
|
||||
'blockname' => $blockname,
|
||||
'parentcontextid' => $page->context->id,
|
||||
'pagetypepattern' => 'my-index',
|
||||
'subpagepattern' => $systempage->id,
|
||||
);
|
||||
|
||||
if (!$DB->record_exists('block_instances', $criteria)) {
|
||||
// Add the block to the default /my.
|
||||
$page->blocks->add_region(BLOCK_POS_RIGHT);
|
||||
$page->blocks->add_block($blockname, BLOCK_POS_RIGHT, 0, false, 'my-index');
|
||||
if (!$DB->record_exists('block_instances', $criteria)) {
|
||||
// Add the block to the default /my.
|
||||
$page->blocks->add_region(BLOCK_POS_RIGHT);
|
||||
$page->blocks->add_block($blockname, BLOCK_POS_RIGHT, 0, false, 'my-index', $systempage->id);
|
||||
}
|
||||
}
|
||||
|
||||
upgrade_block_savepoint(true, 2014062600, $blockname);
|
||||
|
|
|
@ -49,20 +49,25 @@ function xmldb_block_calendar_month_upgrade($oldversion, $block) {
|
|||
// Add this block the default blocks on /my.
|
||||
$blockname = 'calendar_month';
|
||||
|
||||
$page = new moodle_page();
|
||||
$page->set_context(context_system::instance());
|
||||
// Do not try to add the block if we cannot find the default my_pages entry.
|
||||
// Private => 1 refers to MY_PAGE_PRIVATE.
|
||||
if ($systempage = $DB->get_record('my_pages', array('userid' => null, 'private' => 1))) {
|
||||
$page = new moodle_page();
|
||||
$page->set_context(context_system::instance());
|
||||
|
||||
// Check to see if this block is already on the default /my page.
|
||||
$criteria = array(
|
||||
'blockname' => $blockname,
|
||||
'parentcontextid' => $page->context->id,
|
||||
'pagetypepattern' => 'my-index'
|
||||
);
|
||||
// Check to see if this block is already on the default /my page.
|
||||
$criteria = array(
|
||||
'blockname' => $blockname,
|
||||
'parentcontextid' => $page->context->id,
|
||||
'pagetypepattern' => 'my-index',
|
||||
'subpagepattern' => $systempage->id,
|
||||
);
|
||||
|
||||
if (!$DB->record_exists('block_instances', $criteria)) {
|
||||
// Add the block to the default /my.
|
||||
$page->blocks->add_region(BLOCK_POS_RIGHT);
|
||||
$page->blocks->add_block($blockname, BLOCK_POS_RIGHT, 0, false, 'my-index');
|
||||
if (!$DB->record_exists('block_instances', $criteria)) {
|
||||
// Add the block to the default /my.
|
||||
$page->blocks->add_region(BLOCK_POS_RIGHT);
|
||||
$page->blocks->add_block($blockname, BLOCK_POS_RIGHT, 0, false, 'my-index', $systempage->id);
|
||||
}
|
||||
}
|
||||
|
||||
upgrade_block_savepoint(true, 2014062600, $blockname);
|
||||
|
|
|
@ -49,20 +49,25 @@ function xmldb_block_calendar_upcoming_upgrade($oldversion, $block) {
|
|||
// Add this block the default blocks on /my.
|
||||
$blockname = 'calendar_upcoming';
|
||||
|
||||
$page = new moodle_page();
|
||||
$page->set_context(context_system::instance());
|
||||
// Do not try to add the block if we cannot find the default my_pages entry.
|
||||
// Private => 1 refers to MY_PAGE_PRIVATE.
|
||||
if ($systempage = $DB->get_record('my_pages', array('userid' => null, 'private' => 1))) {
|
||||
$page = new moodle_page();
|
||||
$page->set_context(context_system::instance());
|
||||
|
||||
// Check to see if this block is already on the default /my page.
|
||||
$criteria = array(
|
||||
'blockname' => $blockname,
|
||||
'parentcontextid' => $page->context->id,
|
||||
'pagetypepattern' => 'my-index'
|
||||
);
|
||||
// Check to see if this block is already on the default /my page.
|
||||
$criteria = array(
|
||||
'blockname' => $blockname,
|
||||
'parentcontextid' => $page->context->id,
|
||||
'pagetypepattern' => 'my-index',
|
||||
'subpagepattern' => $systempage->id,
|
||||
);
|
||||
|
||||
if (!$DB->record_exists('block_instances', $criteria)) {
|
||||
// Add the block to the default /my.
|
||||
$page->blocks->add_region(BLOCK_POS_RIGHT);
|
||||
$page->blocks->add_block($blockname, BLOCK_POS_RIGHT, 0, false, 'my-index');
|
||||
if (!$DB->record_exists('block_instances', $criteria)) {
|
||||
// Add the block to the default /my.
|
||||
$page->blocks->add_region(BLOCK_POS_RIGHT);
|
||||
$page->blocks->add_block($blockname, BLOCK_POS_RIGHT, 0, false, 'my-index', $systempage->id);
|
||||
}
|
||||
}
|
||||
|
||||
upgrade_block_savepoint(true, 2014062600, $blockname);
|
||||
|
|
|
@ -2178,7 +2178,13 @@ function blocks_add_default_system_blocks() {
|
|||
$page->blocks->add_blocks(array(BLOCK_POS_LEFT => array('navigation', 'settings')), '*', null, true);
|
||||
$page->blocks->add_blocks(array(BLOCK_POS_LEFT => array('admin_bookmarks')), 'admin-*', null, null, 2);
|
||||
|
||||
if ($defaultmypage = $DB->get_record('my_pages', array('userid' => null, 'name' => '__default', 'private' => 1))) {
|
||||
$subpagepattern = $defaultmypage->id;
|
||||
} else {
|
||||
$subpagepattern = null;
|
||||
}
|
||||
|
||||
$newblocks = array('private_files', 'online_users', 'badges', 'calendar_month', 'calendar_upcoming');
|
||||
$newcontent = array('course_overview');
|
||||
$page->blocks->add_blocks(array(BLOCK_POS_RIGHT => $newblocks, 'content' => $newcontent), 'my-index');
|
||||
$page->blocks->add_blocks(array(BLOCK_POS_RIGHT => $newblocks, 'content' => $newcontent), 'my-index', $subpagepattern);
|
||||
}
|
||||
|
|
|
@ -3980,5 +3980,43 @@ function xmldb_main_upgrade($oldversion) {
|
|||
upgrade_main_savepoint(true, 2014100800.00);
|
||||
}
|
||||
|
||||
if ($oldversion < 2014101001.00) {
|
||||
// Some blocks added themselves to the my/ home page, but they did not declare the
|
||||
// subpage of the default my home page. While the upgrade script has been fixed, this
|
||||
// upgrade script will fix the data that was wrongly added.
|
||||
|
||||
// We only proceed if we can find the right entry from my_pages. Private => 1 refers to
|
||||
// the constant value MY_PAGE_PRIVATE.
|
||||
if ($systempage = $DB->get_record('my_pages', array('userid' => null, 'private' => 1))) {
|
||||
|
||||
// Select the blocks there could have been automatically added. showinsubcontexts is hardcoded to 0
|
||||
// because it is possible for administrators to have forced it on the my/ page by adding it to the
|
||||
// system directly rather than updating the default my/ page.
|
||||
$blocks = array('course_overview', 'private_files', 'online_users', 'badges', 'calendar_month', 'calendar_upcoming');
|
||||
list($blocksql, $blockparams) = $DB->get_in_or_equal($blocks, SQL_PARAMS_NAMED);
|
||||
$select = "parentcontextid = :contextid
|
||||
AND pagetypepattern = :page
|
||||
AND showinsubcontexts = 0
|
||||
AND subpagepattern IS NULL
|
||||
AND blockname $blocksql";
|
||||
$params = array(
|
||||
'contextid' => context_system::instance()->id,
|
||||
'page' => 'my-index'
|
||||
);
|
||||
$params = array_merge($params, $blockparams);
|
||||
|
||||
$DB->set_field_select(
|
||||
'block_instances',
|
||||
'subpagepattern',
|
||||
$systempage->id,
|
||||
$select,
|
||||
$params
|
||||
);
|
||||
}
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_main_savepoint(true, 2014101001.00);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2014101000.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2014101001.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue