mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue