View source
<?php
module_load_include('inc', 'filecache', 'filecache');
function filecache_cron() {
$filecache_enabled = FALSE;
global $conf;
foreach ($conf as $setting => $value) {
if ($setting == 'cache_default_class' || substr($setting, 0, strlen('cache_class_')) === 'cache_class_') {
if ($value === 'DrupalFileCache') {
$filecache_enabled = TRUE;
break;
}
}
}
$filecache_registry_pathname = filecache_registry_pathname();
if (!$filecache_enabled) {
@unlink($filecache_registry_pathname);
return;
}
$registry = @unserialize(@file_get_contents($filecache_registry_pathname));
if (!is_array($registry)) {
@unlink($filecache_registry_pathname);
return;
}
$cache_size = 0;
foreach ($registry as $bin => $value) {
$cache = new DrupalFileCache($bin);
$cache_size += $cache
->delete_expired();
}
cache_set('filecache_space', array(
'cache_size' => $cache_size,
));
}
function filecache_requirements($phase) {
$t = get_t();
$requirements = array(
'title' => $t('File Cache'),
);
$requirements['severity'] = REQUIREMENT_ERROR;
$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,
);
}
$requirements['severity'] = REQUIREMENT_OK;
$requirements['value'] = $t('File Cache serves %bins cache bins.', array(
'%bins' => count($filecache_bins),
));
$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,
);
}