From: Alok Patel Date: Mon, 1 Apr 2019 09:44:30 +0000 (+0530) Subject: CIVICRM-1140: Added a DB check to prevent deleting exisiting CiviCRM data from datbase. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1b4a049e3b916216ed13a91d873d23c391340c90;p=civicrm-core.git CIVICRM-1140: Added a DB check to prevent deleting exisiting CiviCRM data from datbase. --- diff --git a/install/index.php b/install/index.php index 1bded4d2bb..c70c1c1648 100644 --- a/install/index.php +++ b/install/index.php @@ -517,6 +517,17 @@ class InstallRequirements { $onlyRequire ); if ($dbName != 'Drupal' && $dbName != 'Backdrop') { + $this->requireNoExistingData( + $databaseConfig['server'], + $databaseConfig['username'], + $databaseConfig['password'], + $databaseConfig['database'], + array( + ts("MySQL %1 Configuration", array(1 => $dbName)), + ts("Does database has data from previous installation?"), + ts("CiviCRM data from previous installation exists in '%1'.", array(1 => $databaseConfig['database'])), + ) + ); $this->requireMySQLInnoDB($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], @@ -1277,6 +1288,37 @@ class InstallRequirements { } } + /** + * @param $server + * @param $username + * @param $password + * @param $database + * @param $testDetails + */ + public function requireNoExistingData( + $server, + $username, + $password, + $database, + $testDetails + ) { + $this->testing($testDetails); + $conn = $this->connect($server, $username, $password); + + @mysqli_select_db($conn, $database); + $contactRecords = mysqli_query($conn, "SELECT count(*) as contactscount FROM civicrm_contact"); + if ($contactRecords) { + $contactRecords = mysqli_fetch_object($contactRecords); + if ($contactRecords->contactscount > 0) { + $this->error($testDetails); + return; + } + } + + $testDetails[3] = ts('CiviCRM data from previous installation does not exists in %1.', array(1 => $database)); + $this->testing($testDetails); + } + /** * @param $server * @param string $username