You are here

function drush_acsf_init_verify in Acquia Cloud Site Factory Connector 8

Command callback: Verify that acsf-init was run against the current version.

1 call to drush_acsf_init_verify()
drush_acsf_init in acsf_init/acsf_init.drush.inc
Command callback: executes the required changes to this repository.
1 string reference to 'drush_acsf_init_verify'
acsf_init_drush_command in acsf_init/acsf_init.drush.inc
Implements hook_drush_command().

File

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

Code

function drush_acsf_init_verify() {
  $drupal_root = realpath(DRUPAL_ROOT);
  if (basename($drupal_root) !== 'docroot') {

    // Don't check the rest, since drush acsf-init cannot reliably determine
    // file locations to begin with.
    return drush_set_error('INCORRECT DIRECTORY STRUCTURE', dt("Drupal must be installed in a subdirectory of your code repository, named 'docroot'."));
  }
  $repo_root = dirname($drupal_root);
  $skip_default_settings = drush_get_option('skip-default-settings');
  $lib_path = sprintf('%s/lib', dirname(__FILE__));
  $error = FALSE;
  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']) && isset($location['dest'])) {
      $source = sprintf('%s/%s/%s', $lib_path, $location['source'], $file);
      if (!file_exists($dest)) {
        $error = TRUE;
        drush_set_error('FILE MISSING', dt('The file !file is missing.', [
          '!file' => $file,
        ]));
      }
      elseif (md5_file($source) != md5_file($dest)) {
        $error = TRUE;
        drush_set_error('FILE OUT OF DATE', dt('The file !file is out of date.', [
          '!file' => $file,
        ]));
      }
    }

    // Verify the file is executable.
    // Note: The approach here is to not check for the exact file perms (in
    // other words to not test against the 'mod' element), since git - by
    // design - does not respect anything beyond a simple executable bit, the
    // other perms may be filesystem/OS-dependent, and can't be guaranteed to be
    // consistent.
    if (file_exists($dest) && !empty($location['test_executable'])) {
      $dest_permissions = fileperms($dest);

      // We do want to test the owner executable bit, and the group executable
      // bit as well.
      // e.g. to test whether the owner has execute permission, it is the case
      // of testing with: 00000000 01000000 (which is 0100 in octal, 64 in
      // decimal).
      if (($dest_permissions & (0100 | 010)) != (0100 | 010)) {
        $error = TRUE;
        drush_set_error('INCORRECT FILE MODE', dt('The file !file is not executable. Make this file executable for the owner and group, then commit it again.', [
          '!file' => $file,
        ]));
      }
    }
  }
  if (!drush_acsf_init_test_htaccess_is_patched()) {
    $error = TRUE;
    drush_set_error('HTACCESS UNPATCHED', dt('The .htaccess file has not been patched to allow access to apc_rebuild.php.'));
  }

  // Skip the default settings.php file if --skip-default-settings is set.
  if (!$skip_default_settings) {

    // Check that the default settings.php contains the necessary ACSF business
    // logic.
    $acsf_business_logic = acsf_init_default_settings_php_include_get();

    // Break up the business logic by lines.
    $acsf_business_logic_fragments = explode("\n", $acsf_business_logic);

    // Examine each line in the business logic to make sure it appears in the
    // file. This way minor indentation changes will not cause failure.
    $missing_piece = FALSE;
    $default_settings_php_contents = file_get_contents($repo_root . '/docroot/sites/default/settings.php');
    foreach ($acsf_business_logic_fragments as $line) {
      if (strpos($default_settings_php_contents, $line) === FALSE) {
        $missing_piece = TRUE;
        break;
      }
    }
    if ($missing_piece) {
      $error = TRUE;
      drush_set_error('FILE OUT OF DATE', dt('The default settings.php file is out of date.'));
    }
  }
  if ($error) {
    drush_print(dt('Please run drush acsf-init to correct these problems and commit the resulting code changes.'));
    return FALSE;
  }
  else {

    // The Site Factory code deployment uses this string to determine if the
    // acsf-init has been properly run. If this is changed, also ensure that
    // the check in VcsVerifyAcsf matches.
    drush_log(dt('acsf-init required files ok'), 'success');
    return TRUE;
  }
}