You are here

function boost_requirements in Boost 6

Same name and namespace in other branches
  1. 7 boost.install \boost_requirements()

Implementation of hook_requirements().

File

./boost.install, line 73
Handles Boost module installation and upgrade tasks.

Code

function boost_requirements($phase) {
  global $base_root;
  global $base_path;
  $requirements = array();
  $t = get_t();
  switch ($phase) {
    case 'runtime':
      if (!BOOST_IGNORE_SUBDIR_LIMIT) {
        boost_tree_directory(BOOST_ROOT_CACHE_DIR);
      }
      $cache_directories = array();
      $cache_directories[] = BOOST_ROOT_CACHE_DIR;
      $cache_directories[] = BOOST_FILE_PATH;
      $cache_directories[] = BOOST_PERM_FILE_PATH;
      foreach (_boost_copy_file_get_domains(BOOST_PERM_FILE_PATH) as $dir) {
        _boost_mkdir_p($dir);
        file_put_contents($dir . '/' . variable_get('boost_root_file', '.boost'), $dir);
      }
      if (BOOST_GZIP) {
        $cache_directories[] = BOOST_GZIP_FILE_PATH;
        $cache_directories[] = BOOST_PERM_GZIP_FILE_PATH;
        foreach (_boost_copy_file_get_domains(BOOST_PERM_GZIP_FILE_PATH) as $dir) {
          _boost_mkdir_p($dir);
          file_put_contents($dir . '/' . variable_get('boost_root_file', '.boost'), $dir);
        }
      }
      $cache_directories = array_unique($cache_directories);
      $htaccess = stristr($_SERVER["SERVER_SOFTWARE"], 'apache') && file_exists(dirname($_SERVER["SCRIPT_FILENAME"]) . '/.htaccess') ? file_get_contents(dirname($_SERVER["SCRIPT_FILENAME"]) . '/.htaccess') : FALSE;
      if (BOOST_CRAWL_ON_CRON) {
        $crawler_response = drupal_http_request(BOOST_CRAWLER_SELF . '&test=1', array(), 'GET', NULL, 10);
        $crawler_code = $crawler_response->code;
        $crawler_error = $crawler_response->error;
      }
      $robots = drupal_http_request('http://' . check_plain($_SERVER['HTTP_HOST']) . '/robots.txt');
      if ($robots->code == 200) {
        $robots = $robots->data;
      }
      else {
        $robots = FALSE;
      }
      boost_htaccess_cache_dir_put();
      foreach ($cache_directories as $cache_directory) {
        if (_boost_mkdir_p($cache_directory)) {
          $root_file = file_put_contents($cache_directory . '/' . variable_get('boost_root_file', '.boost'), $cache_directory);
        }
        if (!is_dir($cache_directory)) {
          $requirements['boost_default'] = array(
            'title' => $t('Boost'),
            'description' => $t('!cache_dir: does not exist.', array(
              '!cache_dir' => $cache_directory,
            )),
            'severity' => REQUIREMENT_ERROR,
            'value' => $t('Cache path'),
          );
        }
        if (is_dir($cache_directory) && (!$root_file || !is_writable($cache_directory))) {
          $requirements['boost_permissions'] = array(
            'title' => $t('Boost'),
            'description' => $t('Directory %dir credentials - Permissions: %fp. Owner %fo. Group %fg.<br /> Your credentials - Group ID: %gid. User ID: %uid. Current script owner: %user.', array(
              '%dir' => getcwd() . '/' . $cache_directory,
              '%gid' => getmygid(),
              '%uid' => getmyuid(),
              '%user' => get_current_user(),
              '%fp' => substr(sprintf('%o', fileperms($cache_directory)), -4),
              '%fo' => fileowner($cache_directory),
              '%fg' => filegroup($cache_directory),
            )),
            'severity' => REQUIREMENT_ERROR,
            'value' => $t('Can not write to file-system'),
          );
        }
      }
      if (BOOST_FILE_PATH != boost_cache_directory(NULL, FALSE)) {
        $requirements['boost_dir_exists'] = array(
          'title' => $t('Boost'),
          'description' => $t('<a href="@url">Cache file path</a>: is not set to the default(!default). ', array(
            '@url' => url('admin/settings/performance/boost#edit-boost-file-path'),
            '!default' => boost_cache_directory(NULL, FALSE),
          )),
          'severity' => REQUIREMENT_WARNING,
          'value' => $t('Cache path'),
        );
      }
      if ($htaccess && !BOOST_IGNORE_HTACCESS_WARNING && !boost_chk_htaccess_doc($htaccess)) {
        $requirements['boost_htaccess'] = array(
          'title' => $t('Boost'),
          'description' => $t('.htaccess file does not contain or match the boost specific rewrite rules, or the rewrite rules have changed, due to new settings, and they need to be updated. Get the rules: <a href="@url">Boost Apache .htaccess settings generation</a>.', array(
            '@url' => url('admin/settings/performance/boost-rules'),
          )),
          'severity' => REQUIREMENT_ERROR,
          'value' => $t('.htaccess file'),
        );
      }
      if ($htaccess && !boost_chk_htaccess_doc_subdir($htaccess)) {
        $requirements['boost_htaccess_subdir'] = array(
          'title' => $t('Boost'),
          'description' => $t('Drupal is installed in a subdirectory but the htaccess rules are not set for a subdirectory install. Get rules specific to your setup here: <a href="@url">Boost Apache .htaccess settings generation</a>.', array(
            '@url' => url('admin/settings/performance/boost-rules'),
          )),
          'severity' => REQUIREMENT_ERROR,
          'value' => $t('.htaccess file'),
        );
      }
      if (!boost_chk_module_versions()) {
        $requirements['boost_other_modules'] = array(
          'title' => $t('Boost'),
          'description' => $t('You need to get a newer version of <a href="@url">poormanscron</a>, 1.1 and above, or the 2.0 branch.', array(
            '@url' => "http://drupal.org/project/poormanscron",
          )),
          'severity' => REQUIREMENT_ERROR,
          'value' => $t('poormanscron is the wrong version'),
        );
      }
      if (variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE) == LANGUAGE_NEGOTIATION_PATH) {
        $requirements['boost_language'] = array(
          'title' => $t('Boost'),
          'description' => $t('Boost is not compatible with <a href="!url">language negotiation</a> set to "language fallback".  An anonymous user with their browser set to a language other than the site\'s default language will navigate to a non-cached page.  The page will be displayed in the user\'s browser language.  Boost will cache the non-default-language page. ', array(
            '!url' => url('admin/settings/language/configure'),
          )),
          'severity' => REQUIREMENT_ERROR,
          'value' => $t('Cannot use "language fallback" language negotiation'),
        );
      }
      if (!variable_get('boost_crawler_key', FALSE)) {
        $requirements['boost_crawler'] = array(
          'title' => $t('Boost'),
          'description' => $t('Please Run the database update, as the crawler key is not generated yet.'),
          'severity' => REQUIREMENT_ERROR,
          'value' => $t('Boost Crawler Key Not Found.'),
        );
      }
      elseif (isset($crawler_code) && $crawler_code != 200) {
        switch ($crawler_code) {
          case 503:
            $description = $t('Your site is in maintenance mode, crawler will not work with your site in this state. Take site out of maintenance mode if you wish to use the crawler. Running cron if your site is not in maintenance mode might make this error eventually clear.');
            $severity = REQUIREMENT_WARNING;
            break;
          case 403:
            $description = $t('Menu item for crawler is not there. You need to "Clear cached data" at the bottom of the <a href="!url">performance page</a>', array(
              '!url' => url('admin/settings/performance'),
            ));
            $severity = REQUIREMENT_ERROR;
            break;
          default:
            $description = $t('<a href="!url">Clear cached data</a> & run cron; if error priests <a href="@link">open an issue</a> on the Boost issue queue. Got a %num response from the URL.', array(
              '!url' => url('admin/settings/performance'),
              '@link' => 'http://drupal.org/node/add/project-issue/boost',
              '%num' => $crawler_code,
            ));
            $severity = REQUIREMENT_ERROR;
            break;
        }
        $requirements['boost_crawler'] = array(
          'title' => $t('Boost'),
          'description' => $description,
          'severity' => $severity,
          'value' => $t('Boost crawler did not get a 200 response; @number returned instead. @error', array(
            '@number' => $crawler_code,
            '@error' => $crawler_error,
          )),
        );
      }
      if (!variable_get('boost_enabled', CACHE_NORMAL)) {
        $requirements['boost_is_enabled'] = array(
          'title' => $t('Boost'),
          'description' => $t('Boost is disabled. <a href="@performance">Enable</a> it.', array(
            '@performance' => url('admin/settings/performance/boost'),
          )),
          'severity' => REQUIREMENT_WARNING,
          'value' => $t('Boost Disabled'),
        );
      }
      if (ini_get('safe_mode') && !BOOST_IGNORE_SAFE_WARNING) {
        $requirements['boost_safemode'] = array(
          'title' => $t('Boost'),
          'description' => $t('Boost does not work very well if PHP is in safe mode. Some functionality may not work correctly.'),
          'severity' => REQUIREMENT_WARNING,
          'value' => $t('Boost & PHP running in Safe Mode is not a good idea.'),
        );
      }

      //       if (BOOST_CRAWL_URL_ALIAS && BOOST_LOOPBACK_BYPASS) {
      //         $requirements['boost_crawler'] = array(
      //           'title'       => $t('Boost'),
      //           'description' => $t('Crawler settings are inefficient. You probably want to disable the "Crawl All URL\'s in the url_alias table" <a href="@performance">setting</a>.', array('@performance' => url('admin/settings/performance/boost#edit-boost-crawl-on-cron-wrapper'))),
      //           'severity'    => REQUIREMENT_WARNING,
      //           'value'       => $t('Boost crawler does not have efficient settings.'),
      //         );
      //       }
      if (!BOOST_IGNORE_SUBDIR_LIMIT && isset($GLOBALS['_boost_dir_limit_warning'])) {
        $requirements['boost_dir_limit'] = array(
          'title' => $t('Boost'),
          'description' => $t('Sub directory limit about to be hit in these directories: <br /> !list <br /><br /> Change your url structure or open a new thread on the Boost issue tracker; there is a solution but it will cost you $100, since it can not be generalized & must be customized for your configuration', array(
            '!list' => implode(" <br />\n ", $GLOBALS['_boost_dir_limit_warning']),
          )),
          'severity' => REQUIREMENT_WARNING,
          'value' => $t('File system sub directory limit.'),
        );
      }
      if (!BOOST_IGNORE_SUBDIR_LIMIT && isset($GLOBALS['_boost_dir_limit_hit'])) {
        $requirements['boost_dir_limit'] = array(
          'title' => $t('Boost'),
          'description' => $t('Sub directory has been hit in these directories: <br /> !list <br /><br /> Change your url structure or open a new thread on the Boost issue tracker; there is a solution but it will cost you $100, since it can not be generalized & must be customized for your configuration.', array(
            '!list' => implode(" <br />\n ", $GLOBALS['_boost_dir_limit_hit']),
          )),
          'severity' => REQUIREMENT_WARNING,
          'value' => $t('File system sub directory limit.'),
        );
      }
      if ($robots && !stristr($robots, 'Disallow: ' . $base_path . 'boost_stats.php')) {
        $requirements['boost_robots'] = array(
          'title' => $t('Boost'),
          'description' => $t('Your root robots.txt file does not contain "Disallow: !stats". This is needed in order to prevent the output of this from accidentally getting indexed by search engines.', array(
            '!stats' => $base_path . 'boost_stats.php',
          )),
          'severity' => REQUIREMENT_WARNING,
          'value' => $t('"Disallow: !stats" entry missing in robots.txt', array(
            '!stats' => $base_path . 'boost_stats.php',
          )),
        );
      }
      if (variable_get('boost_crawl_on_cron', FALSE) && module_exists('securepages')) {
        $ignore = variable_get('securepages_ignore', '');
        if (!preg_match('/boost-crawler/', $ignore)) {
          $requirements['boost_securepages'] = array(
            'title' => $t('Boost'),
            'description' => $t('You are using the securepages module and the Boost crawler. You must add "boost-crawler" to the <a href="@url">list of ignored pages</a> of securepages.', array(
              '@url' => url('admin/build/securepages'),
            )),
            'severity' => REQUIREMENT_ERROR,
            'value' => $t('Add boost-crawler to the list of ignored pages from securepages.'),
          );
        }
      }

      // if the apache_get_modules function doesn't exist, skip this entirely
      if (function_exists('apache_get_modules')) {

        // Get all available Apache modules.
        $modules = apache_get_modules();
        if (!in_array('mod_headers', $modules)) {
          $requirements['boost_apache_headers'] = array(
            'title' => $t('Boost'),
            'description' => $t('The Apache module "mod_headers" is not available. Enable <a href="!link">mod_headers</a> for Apache if at all possible.', array(
              '!link' => 'http://httpd.apache.org/docs/trunk/mod/mod_headers.html',
            )),
            'severity' => REQUIREMENT_WARNING,
            'value' => $t('Apache module "mod_headers" is not installed.'),
          );
        }
        if (!in_array('mod_rewrite', $modules)) {
          $requirements['boost_apache_rewrite'] = array(
            'title' => $t('Boost'),
            'description' => $t('The Apache module "mod_rewrite" is not available.  You must enable <a href="!link">mod_rewrite</a> for Apache.', array(
              '!link' => 'http://httpd.apache.org/docs/trunk/mod/mod_rewrite.html',
            )),
            'severity' => REQUIREMENT_ERROR,
            'value' => $t('Apache module "mod_rewrite" is not installed.'),
          );
        }
        if (!in_array('mod_mime', $modules)) {
          $requirements['boost_apache_mime'] = array(
            'title' => $t('Boost'),
            'description' => $t('The Apache module "mod_mime" is not available.  You must enable <a href="!link">mod_mime</a> for Apache.', array(
              '!link' => 'http://httpd.apache.org/docs/trunk/mod/mod_mime.html',
            )),
            'severity' => REQUIREMENT_WARNING,
            'value' => $t('Apache module "mod_mime" is not installed.'),
          );
        }
      }
      if (empty($requirements)) {
        $requirements['boost'] = array(
          'title' => $t('Boost'),
          'severity' => REQUIREMENT_OK,
          'value' => $t('Boost installed correctly, should be working if properly <a href="@settings">configured</a>.', array(
            '@settings' => url('admin/settings/performance/boost'),
          )),
        );
      }
      break;
  }
  return $requirements;
}