You are here

function drush_acsf_uninstall in Acquia Cloud Site Factory Connector 8

Command callback: Uninstalls ACSF files from the code base.

1 string reference to 'drush_acsf_uninstall'
acsf_init_drush_command in acsf_init/acsf_init.drush.inc
Implements hook_drush_command().

File

acsf_init/acsf_init.drush.inc, line 582
Provides drush commands to set up a site for Acquia Site Factory.

Code

function drush_acsf_uninstall() {
  drush_print('Removing ACSF requirements.');
  $drupal_root = realpath(DRUPAL_ROOT);
  $repo_root = dirname($drupal_root);
  if (basename($drupal_root) !== 'docroot') {

    // We're not failing if Drupal is not installed in 'docroot' (as in
    // acsf-init), so that files can still be removed from strange installs.
    // hooks/ will be checked inside the docroot.
    $repo_root = $drupal_root;
  }
  foreach (acsf_init_get_required_files($repo_root) as $location) {
    $file = $location['filename'];
    $dest = sprintf('%s/%s', $location['dest'], $file);

    // Some files only contain a destination as they are already in place.
    if (isset($location['source']) && file_exists($dest)) {
      $confirm = drush_confirm(dt('Delete !file?', [
        '!file' => $dest,
      ]));
      if ($confirm === FALSE) {
        continue;
      }
      if (unlink($dest)) {
        drush_log(dt('Success'), 'success');
      }
      else {
        drush_log(dt('Error'), 'error');
      }
    }
  }

  // Remove the ACSF specific business logic from the default setting.php.
  if (file_exists($repo_root . '/docroot/sites/default/settings.php')) {
    $default_settings_php_contents = file_get_contents($repo_root . '/docroot/sites/default/settings.php');
    $default_settings_php_contents = preg_replace('/' . preg_quote(ACSF_INIT_CODE_DELIMITER_START, '/') . '.*?' . preg_quote(ACSF_INIT_CODE_DELIMITER_END, '/') . '/sm', '', $default_settings_php_contents);
    file_put_contents($repo_root . '/docroot/sites/default/settings.php', $default_settings_php_contents);
  }
}