From 582ddf7f4067d53c0430e22a584d55ddcbbd0d35 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Mon, 6 May 2013 17:12:48 -0400 Subject: [PATCH] CC-5089: Uninstall with purge won't clear all tables and indexes -fixed --- install_minimal/include/AirtimeInstall.php | 2 +- install_minimal/include/airtime-uninstall.php | 28 +++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/install_minimal/include/AirtimeInstall.php b/install_minimal/include/AirtimeInstall.php index 6e8f4a0fa..caf538409 100644 --- a/install_minimal/include/AirtimeInstall.php +++ b/install_minimal/include/AirtimeInstall.php @@ -115,7 +115,7 @@ class AirtimeInstall public static function DropSequence($p_sequenceName) { - AirtimeInstall::InstallQuery("DROP SEQUENCE IF EXISTS $p_sequenceName"); + AirtimeInstall::InstallQuery("DROP SEQUENCE IF EXISTS $p_sequenceName", false); } /** diff --git a/install_minimal/include/airtime-uninstall.php b/install_minimal/include/airtime-uninstall.php index 118ccc01b..20d323daf 100644 --- a/install_minimal/include/airtime-uninstall.php +++ b/install_minimal/include/airtime-uninstall.php @@ -51,10 +51,10 @@ $command = "su postgres -c \"dropdb ".$CC_CONFIG["dsn"]["database"]."\""; // We do this if dropping the database fails above. //------------------------------------------------------------------------ if ($dbDeleteFailed) { - echo " * Couldn't delete the database, so deleting all the DB tables...".PHP_EOL; $connected = AirtimeInstall::DbConnect(false); if ($connected) { + echo " * Couldn't delete the database, so deleting all the DB tables...".PHP_EOL; $con = Propel::getConnection(); $sql = "select * from pg_tables where tableowner = 'airtime'"; try { @@ -67,11 +67,27 @@ if ($dbDeleteFailed) { $tablename = $row["tablename"]; echo " * Removing database table $tablename..."; - if (AirtimeInstall::DbTableExists($tablename)) { - $sql = "DROP TABLE $tablename CASCADE"; - AirtimeInstall::InstallQuery($sql, false); - AirtimeInstall::DropSequence($tablename."_id"); - } + $sql = "DROP TABLE $tablename CASCADE"; + AirtimeInstall::InstallQuery($sql, false); + AirtimeInstall::DropSequence($tablename."_id"); + echo "done.".PHP_EOL; + } + + + echo " * Deleting database sequences...".PHP_EOL; + $sql = "SELECT c.relname FROM pg_class c WHERE c.relkind = 'S';"; + try { + $rows = $con->query($sql)->fetchAll(); + } catch (Exception $e) { + $rows = array(); + } + + foreach ($rows as $row) { + $sequence = $row["relname"]; + echo " * Removing database sequence $sequence..."; + + $sql = "DROP SEQUENCE $sequence CASCADE"; + AirtimeInstall::InstallQuery($sql, false); echo "done.".PHP_EOL; } }