Skip to content

Commit

Permalink
CIVICRM-1140: Added a DB check to prevent deleting exisiting CiviCRM …
Browse files Browse the repository at this point in the history
…data from datbase.
  • Loading branch information
agilewarealok authored and agileware-dev committed Apr 2, 2019
1 parent 560d170 commit dee923c
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions install/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,17 @@ public function checkdatabase($databaseConfig, $dbName) {
$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'],
Expand Down Expand Up @@ -1267,6 +1278,37 @@ public function requireMySQLThreadStack($server, $username, $password, $database
}
}

/**
* @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
Expand Down

0 comments on commit dee923c

Please sign in to comment.