Commit 077e5988 authored by Andrew Robert Nicols's avatar Andrew Robert Nicols
Browse files

Fix uninstallation in unit tests (Bug #819396)



Change-Id: I79a6d00f7ea31397758722ad240876457db3bced
Signed-off-by: default avatarAndrew Robert Nicols <andrew.nicols@luns.net.uk>
parent d9981b52
......@@ -573,7 +573,12 @@ function uninstall_from_xmldb_file($file) {
if ($tables = array_reverse($structure->getTables())) {
foreach ($tables as $table) {
if ($indexes = $table->getIndexes()) {
foreach (array_reverse($indexes) as $index) {
$sortindexes = array();
foreach ($indexes as $index) {
$sortindexes[] = find_index_name($table, $index);
}
array_multisort($indexes, SORT_DESC, $sortindexes);
foreach ($indexes as $index) {
if ($index->getName() == 'usernameuk' && is_postgres()) {
// this is a giant hack, but adodb cannot handle resolving
// the column for indexes that include lower() or something similar
......@@ -585,7 +590,17 @@ function uninstall_from_xmldb_file($file) {
}
}
if ($keys = $table->getKeys()) {
foreach (array_reverse($keys) as $key) {
$sortkeys = array();
foreach ($keys as $key) {
$sortkeys[] = find_key_name($table, $key);
}
array_multisort($keys, SORT_DESC, $sortkeys);
foreach ($keys as $key) {
if (!is_postgres() && $key->type != XMLDB_KEY_FOREIGN && $key->type != XMLDB_KEY_FOREIGN_UNIQUE) {
// Skip keys for MySQL because these will be
// dropped when the table is dropped
continue;
}
drop_key($table, $key);
}
}
......
......@@ -123,8 +123,14 @@ class UnitTestBootstrap {
// These constraints must be dropped manually as they cannot be
// created with xmldb due to ordering issues
execute_sql('ALTER TABLE {usr} DROP CONSTRAINT {usr_pro_fk}');
execute_sql('ALTER TABLE {institution} DROP CONSTRAINT {inst_log_fk}');
if (is_postgres()) {
execute_sql('ALTER TABLE {usr} DROP CONSTRAINT {usr_pro_fk}');
execute_sql('ALTER TABLE {institution} DROP CONSTRAINT {inst_log_fk}');
}
else {
execute_sql('ALTER TABLE {usr} DROP FOREIGN KEY {usr_pro_fk}');
execute_sql('ALTER TABLE {institution} DROP FOREIGN KEY {inst_log_fk}');
}
uninstall_from_xmldb_file(get_config('docroot') . 'lib/db/install.xml');
}
......
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