Commit 1b4a049e authored by agilewarealok's avatar agilewarealok

CIVICRM-1140: Added a DB check to prevent deleting exisiting CiviCRM data from datbase.

parent 46e0ade7
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment