function _xmlsitemap_check_cache_files in XML sitemap 6
Check the cache files.
Return value
TRUE if the cache files must be updated / created, FALSE otherwise.
1 call to _xmlsitemap_check_cache_files()
- xmlsitemap_output in ./
xmlsitemap.pages.inc - Menu callback; display the sitemap.
File
- ./
xmlsitemap.pages.inc, line 116 - XML sitemap page callbacks.
Code
function _xmlsitemap_check_cache_files() {
$chunk_size = variable_get('xmlsitemap_chunk_size', 1000);
$link_count = xmlsitemap_link_count();
$id = xmlsitemap_language_id();
$parent_directory = variable_get('xmlsitemap_cache_directory', file_directory_path() . '/xmlsitemap');
// If the directory that should contains the cache files doesn't exist, then
// the cache files must be created.
if (!file_check_directory($parent_directory, FILE_CREATE_DIRECTORY)) {
return TRUE;
}
$update_timestamp = variable_get('xmlsitemap_update_timestamp', REQUEST_TIME);
// If the cache files creation has failed last time, the cache files must be
// created.
if (variable_get("xmlsitemap_create_cache_result_{$id}", -1) !== TRUE) {
return TRUE;
}
// If the main cache file doesn't exist, then the cache files must be
// created.
if (!file_exists($parent_directory . "/xsm-{$id}.xml")) {
return TRUE;
}
// If the main cache file has been created before the sitemap content has
// been updated, then the cache files must be updated.
if (filemtime($parent_directory . "/xsm-{$id}.xml") < $update_timestamp) {
return TRUE;
}
// Check also the other cache files.
if ($link_count > $chunk_size) {
for ($chunk = 0; $chunk < $link_count / $chunk_size; ++$chunk) {
if (!file_exists($parent_directory . "/xsm-{$id}-{$chunk}.xml")) {
return TRUE;
}
if (filemtime($parent_directory . "/xsm-{$id}-{$chunk}.xml") < $update_timestamp) {
return TRUE;
}
}
}
return FALSE;
}