In order to remove all tables of a packet during deinstallation, there is a very simple solution without having to specify all table names individually.

The basic requirement for the solution below is that you have used your own prefix in your package for your tables. If so, you can use the following snippet in 'packages\your_package\controller.php':

public function uninstall() {
      parent::uninstall();

    //***************************************************************************
    //**Remove all tables from a package with the same, package-specific prefix
    //**DO NOT USE IF YOU HAVE NO OWN TABLES PREFIX!
    //***************************************************************************
    $tblprefix = 'TestProject'; //<- enter your package table prefix

    $db = Loader::db();
    $dbname = $db->getDatabase();

    //remove Association Mapping Many-To-Many tables, only works if you use underscores in table names (sample: TestProject_ToDos)
    $sqldrop = $db->fetchColumn("SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' ) AS statement FROM information_schema.tables WHERE table_schema = '".$dbname."' AND table_name LIKE '".$tblprefix."%\_%';");
    $db->query($sqldrop);

    //remove other tables
    $sqldrop = $db->fetchColumn("SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' ) AS statement FROM information_schema.tables WHERE table_schema = '".$dbname."' AND table_name LIKE '".$tblprefix."%';");
    $db->query($sqldrop);
    //***************************************************************************
}
Loading Conversation