mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
MDL-65809 upgrade: remove upgrade_block_positions
This function was used only by deleted upgrade steps so it's safe to proceed with straight deletion, considering it internal. Deletion has been documented in corresponding upgrade.txt files.
This commit is contained in:
parent
f0d3d50273
commit
6f46aa2040
@ -7,6 +7,7 @@ This files describes API changes in /admin/*.
|
||||
- upgrade_theme_is_from_family()
|
||||
- upgrade_find_theme_location()
|
||||
- linkcoursesectionsupgradescriptwasrun setting
|
||||
- upgrade_block_positions()
|
||||
|
||||
=== 3.8 ===
|
||||
|
||||
|
@ -190,17 +190,6 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2017020200.02);
|
||||
}
|
||||
|
||||
if ($oldversion < 2017020901.00) {
|
||||
|
||||
// Delete "orphaned" block positions. Note, the query does not use indexes (because there are none),
|
||||
// if it runs too long during upgrade you can comment this line - it will leave orphaned records
|
||||
// in the database but they won't bother you.
|
||||
upgrade_block_positions();
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_main_savepoint(true, 2017020901.00);
|
||||
}
|
||||
|
||||
if ($oldversion < 2017021300.00) {
|
||||
unset_config('loginpasswordautocomplete');
|
||||
upgrade_main_savepoint(true, 2017021300.00);
|
||||
|
@ -488,21 +488,6 @@ function upgrade_standardise_score($rawgrade, $sourcemin, $sourcemax, $targetmin
|
||||
return $standardisedvalue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete orphaned records in block_positions
|
||||
*/
|
||||
function upgrade_block_positions() {
|
||||
global $DB;
|
||||
$id = 'id';
|
||||
if ($DB->get_dbfamily() !== 'mysql') {
|
||||
// Field block_positions.subpage has type 'char', it can not be compared to int in db engines except for mysql.
|
||||
$id = $DB->sql_concat('?', 'id');
|
||||
}
|
||||
$sql = "DELETE FROM {block_positions}
|
||||
WHERE pagetype IN ('my-index', 'user-profile') AND subpage NOT IN (SELECT $id FROM {my_pages})";
|
||||
$DB->execute($sql, ['']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a way to check and update a serialized string that uses the deprecated object class.
|
||||
*
|
||||
|
@ -650,49 +650,6 @@ class core_upgradelib_testcase extends advanced_testcase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create two pages with blocks, delete one page and make sure upgrade script deletes orphaned blocks
|
||||
*/
|
||||
public function test_delete_block_positions() {
|
||||
global $DB, $CFG;
|
||||
require_once($CFG->dirroot . '/my/lib.php');
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Make sure each block on system dashboard page has a position.
|
||||
$systempage = $DB->get_record('my_pages', array('userid' => null, 'private' => MY_PAGE_PRIVATE));
|
||||
$systemcontext = context_system::instance();
|
||||
$blockinstances = $DB->get_records('block_instances', array('parentcontextid' => $systemcontext->id,
|
||||
'pagetypepattern' => 'my-index', 'subpagepattern' => $systempage->id));
|
||||
$this->assertNotEmpty($blockinstances);
|
||||
foreach ($blockinstances as $bi) {
|
||||
$DB->insert_record('block_positions', ['subpage' => $systempage->id, 'pagetype' => 'my-index', 'contextid' => $systemcontext->id,
|
||||
'blockinstanceid' => $bi->id, 'visible' => 1, 'weight' => $bi->defaultweight]);
|
||||
}
|
||||
|
||||
// Create two users and make two copies of the system dashboard.
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$page1 = my_copy_page($user1->id, MY_PAGE_PRIVATE, 'my-index');
|
||||
$page2 = my_copy_page($user2->id, MY_PAGE_PRIVATE, 'my-index');
|
||||
|
||||
$context1 = context_user::instance($user1->id);
|
||||
$context2 = context_user::instance($user2->id);
|
||||
|
||||
// Delete second page without deleting block positions.
|
||||
$DB->delete_records('my_pages', ['id' => $page2->id]);
|
||||
|
||||
// Blocks are still here.
|
||||
$this->assertEquals(count($blockinstances), $DB->count_records('block_positions', ['subpage' => $page1->id, 'pagetype' => 'my-index', 'contextid' => $context1->id]));
|
||||
$this->assertEquals(count($blockinstances), $DB->count_records('block_positions', ['subpage' => $page2->id, 'pagetype' => 'my-index', 'contextid' => $context2->id]));
|
||||
|
||||
// Run upgrade script that should delete orphaned block_positions.
|
||||
upgrade_block_positions();
|
||||
|
||||
// First user still has all his block_positions, second user does not.
|
||||
$this->assertEquals(count($blockinstances), $DB->count_records('block_positions', ['subpage' => $page1->id, 'pagetype' => 'my-index', 'contextid' => $context1->id]));
|
||||
$this->assertEquals(0, $DB->count_records('block_positions', ['subpage' => $page2->id, 'pagetype' => 'my-index']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the conversion of auth plugin settings names.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user