// 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);
// 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);
// 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);
$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);
}
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;
}
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.