Commit 064bf963 authored by Robert Lyon's avatar Robert Lyon Committed by Son Nguyen
Browse files

Adding in possibly missing id column for view_rows_columns (bug 1174623)



The field is currently not being used but because the install.php file
had the id column in it for v1.8 it means sites installed with 1.8
have the column but sites upgraded to 1.8 do not.

Change-Id: If1e52cf68ad18ce730fd2e9be3abf8684a94368d
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent eee4f445
......@@ -2796,6 +2796,42 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
}
if ($oldversion < 2013121300) {
// view_rows_columns can be missing the 'id' column if upgrading from version
// earlier than v1.8 and because we are adding a sequential primary column after
// the table is already made we need to
// - check that the column doesn't exist then add it without key or sequence
// - update the values for the new id column to be sequential
// - then add the primary key and finally make the column sequential
if ($records = get_records_sql_array('SELECT * FROM {view_rows_columns}', array())) {
if (empty($records[0]->id)) {
$table = new XMLDBTable('view_rows_columns');
$field = new XMLDBField('id');
$field->setAttributes(XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, null, null, null, 1, 'view');
add_field($table, $field);
$x = 1;
foreach ($records as $record) {
execute_sql('UPDATE {view_rows_columns} SET id = ? WHERE view = ? AND row = ? AND columns = ?',
array($x, $record->view, $record->row, $record->columns));
$x++;
}
// we can't add a sequence on a field unless it has a primary key
$key = new XMLDBKey('primary');
$key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
add_key($table, $key);
$field = new XMLDBField('id');
$field->setAttributes(XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, XMLDB_SEQUENCE);
change_field_type($table, $field);
// but when we change field type postgres drops the keys for the column so we need
// to add the primary key back again - see line 2205 for more info
if (is_postgres()) {
$key = new XMLDBKey('primary');
$key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
add_key($table, $key);
}
}
}
}
return $status;
}
......@@ -15,7 +15,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/index.php/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2013120200;
$config->version = 2013121300;
$config->release = '1.9.0dev';
$config->minupgradefrom = 2009022600;
$config->minupgraderelease = '1.1.0 (release tag 1.1.0_RELEASE)';
......
Supports Markdown
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