You are here

public function AcsfInitCommands::uninstall in Acquia Cloud Site Factory Connector 8.2

Remove Acquia Site Factory components from this repository.

Uninstalls components that allow this Drupal repository to be compatible with Acquia Site Factory.

@command acsf-uninstall

@bootstrap root

File

acsf_init/src/Commands/AcsfInitCommands.php, line 525

Class

AcsfInitCommands
Provides drush commands to set up a codebase for Acquia Cloud Site Factory.

Namespace

Drush\Commands

Code

public function uninstall() {
  $this
    ->output()
    ->writeln('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 ($this
    ->getRequiredFiles($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 = $this
        ->io()
        ->confirm(dt('Delete !file?', [
        '!file' => $dest,
      ]));
      if ($confirm === FALSE) {
        continue;
      }
      if (unlink($dest)) {
        $this
          ->logger()
          ->success(dt('Success'));
      }
      else {
        $this
          ->logger()
          ->error(dt('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(self::ACSF_INIT_CODE_DELIMITER_START, '/') . '.*?' . preg_quote(self::ACSF_INIT_CODE_DELIMITER_END, '/') . '/sm', '', $default_settings_php_contents);
    file_put_contents($repo_root . '/docroot/sites/default/settings.php', $default_settings_php_contents);
  }
}