You are here

function filecache_requirements in File Cache 7

Same name and namespace in other branches
  1. 8 filecache.install \filecache_requirements()

Implements hook_requirements().

Parameters

$phase: Phase.

See also

hook_requirements()

File

./filecache.module, line 54

Code

function filecache_requirements($phase) {
  $t = get_t();
  $requirements = array(
    'title' => $t('File Cache'),
  );
  $requirements['severity'] = REQUIREMENT_ERROR;

  // Assume error first
  $readme_hint = $t('Please follow the instructions in <a href="!readmetxt">README.txt</a>.', array(
    '!readmetxt' => base_path() . drupal_get_path('module', 'filecache') . '/README.txt',
  ));
  $filecache_directory = filecache_directory();
  $registry_pathname = filecache_registry_pathname();
  $registry = @unserialize(@file_get_contents($registry_pathname));
  if (!isset($registry) || !is_array($registry)) {
    $registry = array();
  }
  $filecache_bins = array_keys($registry);
  sort($filecache_bins);
  if (empty($filecache_bins)) {
    $requirements['severity'] = REQUIREMENT_WARNING;
    $requirements['value'] = $t('No cache bins are served by File Cache.');
    $requirements['description'] = $readme_hint;
    return array(
      'filecache' => $requirements,
    );
  }
  $not_ok_bins = array();
  foreach ($filecache_bins as $bin) {
    $cache = new DrupalFileCache($bin);
    if (!$cache->ok) {
      array_push($not_ok_bins, $bin);
    }
  }
  if (!empty($not_ok_bins)) {
    $requirements['severity'] = REQUIREMENT_WARNING;
    $requirements['value'] = $t('The following File Cache cache bins has problems: %bins. Look at <em>Recent log messages</em> for details.', array(
      '%bins' => implode(', ', $not_ok_bins),
    ));
    $requirements['description'] = $readme_hint;
    return array(
      'filecache' => $requirements,
    );
  }

  // Show what cache bins we serve (in $requirements['value'])
  $requirements['severity'] = REQUIREMENT_OK;
  $requirements['value'] = $t('File Cache serves %bins cache bins.', array(
    '%bins' => count($filecache_bins),
  ));

  // Show filecache_directory and its size (in $requirements['description'])
  $space = cache_get('filecache_space');
  $cron_last = variable_get('cron_last');
  if ($space) {
    $requirements['description'] = $t('Cache files use !size (calculated !time ago)', array(
      '!size' => format_size($space->data['cache_size']),
      '!time' => format_interval(REQUEST_TIME - $cron_last),
    ));
  }
  else {
    $requirements['description'] = $t('Cache files use unknown disk space. Run cron to update.');
  }
  if ($filecache_directory == filecache_default_directory()) {
    $url = substr($filecache_directory, strlen(DRUPAL_ROOT)) . '/' . FILECACHE_CACHE_BIN_REGISTRY;
    $requirements['severity'] = REQUIREMENT_WARNING;
    $requirements['description'] .= $t('<br>You use default directory location %default_dir. ' . 'Make sure your webserver denies access to files and directories starting with ".ht" like in the following link: ' . '<a href="!link">link</a>. If you deny access to directories starting with ".ht" and you want to remove this message, ' . 'add the following line to your <code>settings.php</code> and then remove the <code>!quickstart</code> directory:<br>' . '<code>$conf[\'filecache_directory\'] = \'!new_dir\';</code>', array(
      '%default_dir' => $filecache_directory,
      '!link' => $url,
      '!quickstart' => FILECACHE_QUICKSTART_DIRECTORY,
      '!new_dir' => filecache_default_directory(FALSE),
    ));
  }
  return array(
    'filecache' => $requirements,
  );
}