Commit | Line | Data |
---|---|---|
4bcd4c62 TO |
1 | <?php |
2 | /** | |
3 | * @file | |
4 | * | |
5 | * Populate the database schema. | |
6 | */ | |
7 | ||
8 | if (!defined('CIVI_SETUP')) { | |
9 | exit("Installation plugins must only be loaded by the installer.\n"); | |
10 | } | |
11 | ||
12 | \Civi\Setup::dispatcher() | |
13 | ->addListener('civi.setup.uninstallDatabase', function (\Civi\Setup\Event\UninstallDatabaseEvent $e) { | |
14 | \Civi\Setup::log()->info('[UninstallSchema.civi-setup.php] Remove all tables and views (civicrm_* and log_civicrm_*)'); | |
15 | $model = $e->getModel(); | |
16 | ||
17 | $conn = \Civi\Setup\DbUtil::connect($model->db); | |
18 | \Civi\Setup\DbUtil::execute($conn, 'SET FOREIGN_KEY_CHECKS=0;'); | |
19 | ||
20 | foreach (\Civi\Setup\DbUtil::findViews($conn, $model->db['database']) as $view) { | |
21 | if (preg_match('/^(civicrm_|log_civicrm_)/', $view)) { | |
22 | \Civi\Setup\DbUtil::execute($conn, sprintf('DROP VIEW `%s`', $conn->escape_string($view))); | |
23 | } | |
24 | } | |
25 | ||
26 | foreach (\Civi\Setup\DbUtil::findTables($conn, $model->db['database']) as $table) { | |
27 | if (preg_match('/^(civicrm_|log_civicrm_)/', $table)) { | |
28 | \Civi\Setup\DbUtil::execute($conn, sprintf('DROP TABLE `%s`', $conn->escape_string($table))); | |
29 | } | |
30 | } | |
31 | ||
32 | // TODO Perhaps we should also remove stored-procedures/functions? | |
33 | ||
34 | $conn->close(); | |
35 | }); |