Commit d06ee8c2 authored by Dave Reid's avatar Dave Reid

by Dave Reid: Added tracking and requirements check for the maximum file size.

parent 2b492a8a
......@@ -83,6 +83,10 @@ function _xmlsitemap_regenerate_before() {
// Clear all cached sitemap files.
xmlsitemap_clear_directory();
xmlsitemap_check_directory();
// Clear the maximum chunk and file size variables.
variable_set('xmlsitemap_maximum_chunks', 0);
variable_set('xmlsitemap_maximum_filesize', 0);
}
function _xmlsitemap_get_memory_usage($start = FALSE) {
......@@ -186,6 +190,12 @@ function xmlsitemap_generate($chunk = 0, $language = NULL) {
}
fclose($handle);
// Track the maximum filesize.
$filesize = filesize($file);
if ($filesize > variable_get('xmlsitemap_max_filesize', 0)) {
variable_set('xmlsitemap_max_filesize', $filesize);
}
if (!$status) {
trigger_error(t('Unknown error occurred while writing to file @file.', array('@file' => $file)));
}
......
......@@ -54,13 +54,22 @@ function xmlsitemap_requirements($phase) {
$requirements['xmlsitemap_chunk_count'] = array(
'title' => $t('XML sitemap page count'),
'value' => xmlsitemap_get_chunk_count(),
'description' => $t('You have exceeded the number of sitemap pages (1,000).'),
'description' => $t('You have exceeded the number of sitemap pages (@number).', array('@number' => number_format(XMLSITEMAP_MAX_SITEMAP_CHUNKS))),
'severity' => REQUIREMENT_ERROR,
);
if (!in_array(xmlsitemap_get_chunk_size(), array(50000, 'auto'))) {
$requirements['xmlsitemap_chunk_count']['description'] .= ' ' . t('Please increase the number of links per page.');
}
}
$max_filesize = variable_get('xmlsitemap_max_filesize', 0);
if ($max_filesize > XMLSITEMAP_MAX_SITEMAP_FILESIZE) {
$requirements['xmlsitemap_file_size'] = array(
'title' => $t('XML sitemap file_size'),
'value' => format_size($max_filesize),
'description' => $t('You have exceeded the maximum sitemap file size of @size. If possible, decrease the number of links per sitemap page.', array('@size' => format_size(XMLSITEMAP_MAX_SITEMAP_FILESIZE))),
'severity' => REQUIREMENT_ERROR,
);
}
// Check when the cached files were last generated.
$generated_last = xmlsitemap_var('generated_last');
......
......@@ -650,6 +650,8 @@ function xmlsitemap_variables() {
'xmlsitemap_developer_mode' => FALSE,
'xmlsitemap_frontpage_priority' => '1.0',
'xmlsitemap_frontpage_changefreq' => XMLSITEMAP_FREQUENCY_DAILY,
'xmlsitemap_max_chunks' => 0,
'xmlsitemap_max_filesize' => 0,
// Removed variables are set to NULL so they can still be deleted.
'xmlsitemap_gz' => FALSE,
'xmlsitemap_regenerate_last' => NULL,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment