Commit 142faacc authored by Robert Lyon's avatar Robert Lyon

Bug 1528351: Fixing block order drift in database

Due to a mistake in how blocks were ordered in the system

behatnotneeded - existing tests should be ok

Change-Id: Iac857c85d60e5948b6f95ddccee7a2e8cf43b1b4
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent c742ead0
......@@ -3933,5 +3933,42 @@ function xmldb_core_upgrade($oldversion=0) {
rmdirr(get_config('dataroot') . 'htmlpurifier');
}
if ($oldversion < 2014092333) {
log_debug('Sorting out block_instance sort order drift');
// There was an issue with the sorting of blocks (Bug #1523719) that existed since
// Sept 2007, commit 02fb5d96 where the max order number does not equal the number
// of blocks in the cell
set_time_limit(120);
if ($results = get_records_sql_array('SELECT b.id, b.view, b.row, b.column, b.order, maxorder, countorder
FROM {block_instance} b
JOIN (SELECT view AS sview, "row" AS srow, "column" AS scol, COUNT("order") AS countorder, MAX("order") AS maxorder
FROM {block_instance} GROUP BY view, "row", "column") AS myview
ON myview.sview = b.VIEW AND myview.srow = b.row AND myview.scol = b.column
WHERE maxorder != countorder
ORDER BY b.view, b.row, b.column, b.order', array())) {
// Structure the info into a more usable format
$updates = array();
foreach ($results as $r) {
$updates[$r->view][$r->row][$r->column][] = array('order' => $r->order, 'id' => $r->id);
}
// Now deal with the results
foreach ($updates as $view => $grid) {
foreach ($grid as $row => $columns) {
foreach ($columns as $column => $blocks) {
foreach ($blocks as $key => $block) {
// First move them out of the way to avoid uniqueness clash
execute_sql('UPDATE {block_instance} SET "order" = ? WHERE id = ?', array(($block['order'] * -1), $block['id']));
}
foreach ($blocks as $key => $block) {
// Then update them with true order
execute_sql('UPDATE {block_instance} SET "order" = ? WHERE id = ?', array(($key + 1), $block['id']));
}
}
}
set_time_limit(30);
}
}
}
return $status;
}
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2014092332;
$config->version = 2014092333;
$config->series = '1.10';
$config->release = '1.10.9testing';
$config->minupgradefrom = 2009022600;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment