Commit | Line | Data |
---|---|---|
4bcd4c62 TO |
1 | <?php |
2 | /** | |
3 | * @file | |
4 | * | |
5 | * Determine whether Civi has been installed. | |
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.checkInstalled', function (\Civi\Setup\Event\CheckInstalledEvent $e) { | |
14 | \Civi\Setup::log()->info(sprintf('[%s] Handle %s', basename(__FILE__), 'checkInstalled')); | |
15 | $model = $e->getModel(); | |
16 | ||
17 | if ($model->db) { | |
18 | try { | |
19 | $conn = \Civi\Setup\DbUtil::connect($model->db); | |
20 | } | |
21 | catch (\Civi\Setup\Exception\SqlException $exception) { | |
22 | $e->setDatabaseInstalled(FALSE); | |
23 | return; | |
24 | } | |
25 | $found = FALSE; | |
26 | foreach ($conn->query('SHOW TABLES LIKE "civicrm_%"') as $result) { | |
27 | $found = TRUE; | |
28 | } | |
29 | $conn->close(); | |
30 | $e->setDatabaseInstalled($found); | |
31 | } | |
32 | else { | |
33 | throw new \Exception("The \"db\" is unspecified. Cannot determine whether the database schema file exists."); | |
34 | } | |
35 | }); |