Unverified Commit c952b919 authored by Dave Reid's avatar Dave Reid Committed by Dave Reid

Issue #2461505 by Dave Reid, AdamPS: Fixed false alarms on status report if...

Issue #2461505 by Dave Reid, AdamPS: Fixed false alarms on status report if sitemap was flagged for regeneration after cron was last run.
parent 0d808920
......@@ -9,7 +9,5 @@ frontpage_changefreq: 86400
lastmod_format: 'Y-m-d\TH:i\Z'
gz: false
clean_url: 0
cron_threshold_error: 1209600
cron_threshold_warning: 172800
disable_cron_regeneration: false
i18n_selection_mode: 'simple'
......@@ -37,12 +37,6 @@ xmlsitemap.settings:
clean_url:
type: integer
label: 'Insert clean urls into sitemap'
cron_threshold_error:
type: integer
label: 'Threshold error for cron job'
cron_threshold_warning:
type: integer
label: 'Threshold warning for cron job'
disable_cron_regeneration:
type: boolean
label: 'Disable cron generation of sitemap files'
......
......@@ -77,6 +77,8 @@ class XmlSitemapFunctionalTest extends XmlSitemapTestBase {
* report.
*/
public function testStatusReport() {
$cron_warning_threshold = $this->config('system.cron')->get('threshold.requirements_warning');
// Test the rebuild flag.
$this->drupalLogin($this->admin_user);
$this->state->set('xmlsitemap_generated_last', REQUEST_TIME);
......@@ -86,9 +88,18 @@ class XmlSitemapFunctionalTest extends XmlSitemapTestBase {
$this->assertResponse(200);
$this->state->set('xmlsitemap_rebuild_needed', FALSE);
$this->assertNoXMLSitemapProblems();
// Test the regenerate flag (and cron has run recently).
$this->state->set('xmlsitemap_regenerate_needed', TRUE);
$this->state->set('xmlsitemap_generated_last', REQUEST_TIME - $cron_warning_threshold - 600);
$this->state->set('system.cron_last', REQUEST_TIME - $cron_warning_threshold + 600);
$this->assertNoXMLSitemapProblems();
// Test the regenerate flag (and cron hasn't run in a while).
$this->state->set('xmlsitemap_regenerate_needed', TRUE);
$this->state->set('xmlsitemap_generated_last', REQUEST_TIME - $this->config->get('cron_threshold_warning') - 100);
$this->state->set('system.cron_last', 0);
$this->state->set('install_time', 0);
$this->state->set('xmlsitemap_generated_last', REQUEST_TIME - $cron_warning_threshold - 600);
$this->assertXMLSitemapProblems(t('The XML cached files are out of date and need to be regenerated. You can run cron manually to regenerate the sitemap files.'));
$this->clickLink(t('run cron manually'));
$this->assertResponse(200);
......
......@@ -73,7 +73,7 @@ function xmlsitemap_requirements($phase) {
$requirements['xmlsitemap_directory']['description'] = $t('The following directories were not found or are not writable by the server. See <a href="@docpage">@docpage</a> for more information. @directories', ['@directories' => \Drupal::service('renderer')->renderPlain($items), '@docpage' => 'https://www.drupal.org/node/244924']);
}
}
$sitemaps = xmlsitemap_sitemap_load_multiple();
$sitemaps = \Drupal::entityTypeManager()->getStorage('xmlsitemap')->loadMultiple();
$max_links = -1;
$max_chunks = -1;
$max_filesize = -1;
......@@ -135,22 +135,38 @@ function xmlsitemap_requirements($phase) {
$requirements['xmlsitemap_generated']['description'] = $t('The XML sitemap data is out of sync and needs to be <a href="@link-rebuild">completely rebuilt<a>.', ['@link-rebuild' => Url::fromRoute('xmlsitemap.admin_rebuild')->toString()]);
}
elseif (\Drupal::state()->get('xmlsitemap_regenerate_needed')) {
$last_run = $generated_last;
// If cron regeneration is enabled, factor in the last time cron was run
// because the regenerate flag might have been set between the last cron
// run and now.
if (!\Drupal::config('xmlsitemap.settings')->get('disable_cron_regeneration')) {
$last_run = max($generated_last, \Drupal::state()->get('system.cron_last', 0), \Drupal::state()->get('install_time', 0));
}
$last_run_ago = REQUEST_TIME - $last_run;
$cron_warning_threshold = \Drupal::config('system.cron')->get('threshold.requirements_warning');
$cron_error_threshold = \Drupal::config('system.cron')->get('threshold.requirements_error');
if ($max_filesize == 0) {
// A maximum sitemap file size of 0 indicates an error in generation.
$requirements['xmlsitemap_generated']['severity'] = REQUIREMENT_ERROR;
}
elseif ($generated_ago >= \Drupal::config('xmlsitemap.settings')->get('cron_threshold_error')) {
elseif ($last_run_ago >= $cron_error_threshold) {
$requirements['xmlsitemap_generated']['severity'] = REQUIREMENT_ERROR;
}
elseif ($generated_ago >= \Drupal::config('xmlsitemap.settings')->get('cron_threshold_warning')) {
elseif ($last_run_ago >= $cron_warning_threshold) {
$requirements['xmlsitemap_generated']['severity'] = REQUIREMENT_WARNING;
}
if ($requirements['xmlsitemap_generated']['severity']) {
if (\Drupal::config('xmlsitemap.settings')->get('disable_cron_regeneration')) {
// Don't show the link to run cron if cron regeneration is disabled.
$requirements['xmlsitemap_generated']['description'] = $t('The XML cached files are out of date and need to be regenerated.');
}
else {
$requirements['xmlsitemap_generated']['description'] = $t('The XML cached files are out of date and need to be regenerated. You can <a href="@link-cron">run cron manually</a> to regenerate the sitemap files.', [
'@link-cron' => Url::fromRoute('system.run_cron', [], ['query' => drupal_get_destination()])->toString(),
]);
}
}
}
$anonymous_accout = new AnonymousUserSession();
if (!$anonymous_accout->hasPermission('access user profiles') && xmlsitemap_link_bundle_check_enabled('user', 'user')) {
......
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