/** * Removes all of the tables in the database. * * @uses MpmDbHelper::getTables() * * @return void */ public function destroy() { $db_config = $GLOBALS['db_config']; $migrations_table = $db_config->migrations_table; echo 'Looking for existing tables... '; $tables = MpmDbHelper::getTables($this->dbObj); $totalTables = count($tables); $displayTotal = $totalTables > 1 ? $totalTables - 1 : 0; echo 'found ' . $displayTotal . '.'; if ($totalTables > 1) { echo ' Disabling foreign key restrictions...'; $this->dbObj->exec('SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0'); $this->dbObj->exec('SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0'); $this->dbObj->exec("SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL'"); echo " done.\n"; echo ' Removing:', "\n"; foreach ($tables as $table) { if ($table != $migrations_table) { echo ' ', $table, "\n"; $this->dbObj->exec('DROP TABLE IF EXISTS `' . $table . '`'); } } echo ' Re-enabling foreign key restrictions...'; $this->dbObj->exec('SET SQL_MODE=@OLD_SQL_MODE'); $this->dbObj->exec('SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS'); $this->dbObj->exec('SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS'); echo " done.\n"; } else { echo ' No tables need to be removed.', "\n"; } }
/** * Removes all of the tables in the database. * * @uses MpmDbHelper::getTables() * * @return void */ public function destroy() { echo 'Looking for existing tables... '; $tables = MpmDbHelper::getTables($this->dbObj); $totalTables = count($tables); $displayTotal = $totalTables > 1 ? $totalTables - 1 : 0; echo 'found ' . $displayTotal . '.'; if ($totalTables > 1) { echo ' Removing:', "\n"; foreach ($tables as $table) { if ($table != 'mpm_migrations') { echo ' ', $table, "\n"; $this->dbObj->exec('DROP TABLE IF EXISTS `' . $table . '`'); } } } else { echo ' No tables need to be removed.', "\n"; } }
/** * Checks whether or not the mpm_migrations database table exists. * * @uses MpmDbHelper::getDbObj() * @uses MpmDbHelper::getMethod() * @uses MPM_METHOD_PDO * @uses MPM_METHOD_MYSQLI * * @return bool */ public static function checkForDbTable() { $tables = MpmDbHelper::getTables(); if (count($tables) == 0 || !in_array('mpm_migrations', $tables)) { return false; } return true; }
/** * Checks whether or not the migrations database table exists. * * @uses MpmDbHelper::getDbObj() * @uses MpmDbHelper::getMethod() * @uses MPM_METHOD_PDO * @uses MPM_METHOD_MYSQLI * * @return bool */ public static function checkForDbTable() { $db_config = MpmDbHelper::get_db_config(); if (isset($db_config->migrations_table)) { $migrations_table = $db_config->migrations_table; } $tables = MpmDbHelper::getTables(); if (count($tables) == 0 || !in_array($migrations_table, $tables)) { return false; } return true; }