function install_check_requirements

install_check_requirements($install_state)

Checks installation requirements and reports any errors.

File

core/includes/install.core.inc, line 1947
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);

  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
        )),
      );
    }
    // Otherwise, if $file does not exist yet, we can try to copy
    // $default_file to create it.
    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;
        }
        // If $file and $default_file have different owners, this probably means
        // the server is set up "securely" (with the webserver running as its
        // own user, distinct from the user who owns all the Drupal PHP files),
        // although with either a group or world writable sites directory.
        // Keeping $file owned by the webserver would therefore introduce a
        // security risk. It would also cause a usability problem, since site
        // owners who do not have root access to the file system would be unable
        // to edit their settings file later on. We therefore must delete the
        // file we just created and force the administrator to log on to the
        // server and create it manually.
        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;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!includes!install.core.inc/function/install_check_requirements/8.1.x