Commit 82ff6466 authored by Penny Leach's avatar Penny Leach Committed by Andrew Robert Nicols
Browse files

Bug #841694: Add uninstall_from_xmldb support



This is the corrollary of install_from_xmldb_file, except it reverses
the order of anything and removes all keys, indexes and drops the table.

Change-Id: I2568a7b9dd1f7fe1a5ba0f8751434fd0caf7328a
Signed-off-by: default avatarPenny Leach <penny@mjollnir.org>
parent 41707745
......@@ -545,6 +545,57 @@ function find_sequence_name($table) {
return $sequencename;
}
/**
* This function will load one entire XMLDB file, generating all the needed
* SQL statements, specific for each RDBMS ($CFG->dbtype) and, finally, it
* will execute all those statements against the DB, to drop all tables.
*
* @param $file full path to the XML file to be used
* @return boolean (true on success, false on error)
*/
function uninstall_from_xmldb_file($file) {
global $CFG, $db;
$status = true;
$xmldb_file = new XMLDBFile($file);
if (!$xmldb_file->fileExists()) {
throw new InstallationException($xmldb_file->path . " doesn't exist.");
}
$loaded = $xmldb_file->loadXMLStructure();
if (!$loaded || !$xmldb_file->isLoaded()) {
throw new InstallationException("Could not load " . $xmldb_file->path);
}
$structure = $xmldb_file->getStructure();
if ($tables = array_reverse($structure->getTables())) {
foreach ($tables as $table) {
if ($indexes = $table->getIndexes()) {
foreach (array_reverse($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
// and i can't find a nice way to do it.
execute_sql('DROP INDEX {usr_use_uix}');
continue;
}
drop_index($table, $index);
}
}
if ($keys = $table->getKeys()) {
foreach (array_reverse($keys) as $key) {
drop_key($table, $key);
}
}
drop_table($table);
}
}
return true;
}
/**
* This function will load one entire XMLDB file, generating all the needed
* SQL statements, specific for each RDBMS ($CFG->dbtype) and, finally, it
......
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