You are here

function install_check_requirements in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/includes/install.core.inc \install_check_requirements()

Checks installation requirements and reports any errors.

1 call to install_check_requirements()
install_verify_requirements in core/includes/install.core.inc
Verifies the requirements for installing Drupal.

File

core/includes/install.core.inc, line 1954
API functions for installing Drupal.

Code

function install_check_requirements($install_state) {
  $profile = $install_state['parameters']['profile'];

  // Check the profile requirements.
  $requirements = drupal_check_profile($profile, $install_state);
  if ($install_state['settings_verified']) {
    return $requirements;
  }

  // If Drupal is not set up already, we need to try to create the default
  // settings and services files.
  $default_files = array();
  $default_files['settings.php'] = array(
    'file' => 'settings.php',
    'file_default' => 'default.settings.php',
    'title_default' => t('Default settings file'),
    'description_default' => t('The default settings file does not exist.'),
    'title' => t('Settings file'),
  );
  foreach ($default_files as $default_file_info) {
    $readable = FALSE;
    $writable = FALSE;
    $site_path = './' . \Drupal::service('site.path');
    $file = $site_path . "/{$default_file_info['file']}";
    $default_file = "./sites/default/{$default_file_info['file_default']}";
    $exists = FALSE;

    // Verify that the directory exists.
    if (drupal_verify_install_file($site_path, FILE_EXIST, 'dir')) {
      if (drupal_verify_install_file($file, FILE_EXIST)) {

        // If it does, make sure it is writable.
        $readable = drupal_verify_install_file($file, FILE_READABLE);
        $writable = drupal_verify_install_file($file, FILE_WRITABLE);
        $exists = TRUE;
      }
    }

    // If the default $default_file does not exist, or is not readable,
    // report an error.
    if (!drupal_verify_install_file($default_file, FILE_EXIST | FILE_READABLE)) {
      $requirements["default {$file} file exists"] = array(
        'title' => $default_file_info['title_default'],
        'value' => $default_file_info['description_default'],
        'severity' => REQUIREMENT_ERROR,
        'description' => t('The @drupal installer requires that the %default-file file not be modified in any way from the original download.', array(
          '@drupal' => drupal_install_profile_distribution_name(),
          '%default-file' => $default_file,
        )),
      );
    }
    elseif (!$exists) {
      $copied = drupal_verify_install_file($site_path, FILE_EXIST | FILE_WRITABLE, 'dir') && @copy($default_file, $file);
      if ($copied) {

        // If the new $file file has the same owner as $default_file this means
        // $default_file is owned by the webserver user. This is an inherent
        // security weakness because it allows a malicious webserver process to
        // append arbitrary PHP code and then execute it. However, it is also a
        // common configuration on shared hosting, and there is nothing Drupal
        // can do to prevent it. In this situation, having $file also owned by
        // the webserver does not introduce any additional security risk, so we
        // keep the file in place. Additionally, this situation also occurs when
        // the test runner is being run be different user than the webserver.
        if (fileowner($default_file) === fileowner($file) || DRUPAL_TEST_IN_CHILD_SITE) {
          $readable = drupal_verify_install_file($file, FILE_READABLE);
          $writable = drupal_verify_install_file($file, FILE_WRITABLE);
          $exists = TRUE;
        }
        else {
          $deleted = @drupal_unlink($file);

          // We expect deleting the file to be successful (since we just
          // created it ourselves above), but if it fails somehow, we set a
          // variable so we can display a one-time error message to the
          // administrator at the bottom of the requirements list. We also try
          // to make the file writable, to eliminate any conflicting error
          // messages in the requirements list.
          $exists = !$deleted;
          if ($exists) {
            $settings_file_ownership_error = TRUE;
            $readable = drupal_verify_install_file($file, FILE_READABLE);
            $writable = drupal_verify_install_file($file, FILE_WRITABLE);
          }
        }
      }
    }

    // If the $file does not exist, throw an error.
    if (!$exists) {
      $requirements["{$file} file exists"] = array(
        'title' => $default_file_info['title'],
        'value' => t('The %file does not exist.', array(
          '%file' => $default_file_info['title'],
        )),
        'severity' => REQUIREMENT_ERROR,
        'description' => t('The @drupal installer requires that you create a %file as part of the installation process. Copy the %default_file file to %file. More details about installing Drupal are available in <a href=":install_txt">INSTALL.txt</a>.', array(
          '@drupal' => drupal_install_profile_distribution_name(),
          '%file' => $file,
          '%default_file' => $default_file,
          ':install_txt' => base_path() . 'core/INSTALL.txt',
        )),
      );
    }
    else {
      $requirements["{$file} file exists"] = array(
        'title' => $default_file_info['title'],
        'value' => t('The %file exists.', array(
          '%file' => $file,
        )),
      );

      // If the $file is not readable, throw an error.
      if (!$readable) {
        $requirements["{$file} file readable"] = array(
          'title' => $default_file_info['title'],
          'value' => t('The %file is not readable.', array(
            '%file' => $default_file_info['title'],
          )),
          'severity' => REQUIREMENT_ERROR,
          'description' => t('@drupal requires read permissions to %file at all times. The <a href=":handbook_url">webhosting issues</a> documentation section offers help on this and other topics.', array(
            '@drupal' => drupal_install_profile_distribution_name(),
            '%file' => $file,
            ':handbook_url' => 'https://www.drupal.org/server-permissions',
          )),
        );
      }

      // If the $file is not writable, throw an error.
      if (!$writable) {
        $requirements["{$file} file writeable"] = array(
          'title' => $default_file_info['title'],
          'value' => t('The %file is not writable.', array(
            '%file' => $default_file_info['title'],
          )),
          'severity' => REQUIREMENT_ERROR,
          'description' => t('The @drupal installer requires write permissions to %file during the installation process. The <a href=":handbook_url">webhosting issues</a> documentation section offers help on this and other topics.', array(
            '@drupal' => drupal_install_profile_distribution_name(),
            '%file' => $file,
            ':handbook_url' => 'https://www.drupal.org/server-permissions',
          )),
        );
      }
      else {
        $requirements["{$file} file"] = array(
          'title' => $default_file_info['title'],
          'value' => t('The @file is writable.', array(
            '@file' => $default_file_info['title'],
          )),
        );
      }
      if (!empty($settings_file_ownership_error)) {
        $requirements["{$file} file ownership"] = array(
          'title' => $default_file_info['title'],
          'value' => t('The @file is owned by the web server.', array(
            '@file' => $default_file_info['title'],
          )),
          'severity' => REQUIREMENT_ERROR,
          'description' => t('The @drupal installer failed to create a %file file with proper file ownership. Log on to your web server, remove the existing %file file, and create a new one by copying the %default_file file to %file. More details about installing Drupal are available in <a href=":install_txt">INSTALL.txt</a>. The <a href=":handbook_url">webhosting issues</a> documentation section offers help on this and other topics.', array(
            '@drupal' => drupal_install_profile_distribution_name(),
            '%file' => $file,
            '%default_file' => $default_file,
            ':install_txt' => base_path() . 'core/INSTALL.txt',
            ':handbook_url' => 'https://www.drupal.org/server-permissions',
          )),
        );
      }
    }
  }
  return $requirements;
}