Commit 84d59083 authored by andrei.dincu's avatar andrei.dincu
Browse files

Issue #2249723 by andrei.dincu: Make generated_last state() variable instead of config() variable

parent 0ebddb9b
minimum_lifetime: 0
generated_last: 0
xsl: 1
prefetch_aliases: 1
chunk_size: 'auto'
......
......@@ -7,9 +7,6 @@ xmlsitemap.settings:
minimum_lifetime:
type: integer
label: 'Minumum lifetime of an xmlsitemap xml file'
generated_last:
type: integer
label: 'Last generated sitemap'
xsl:
type: integer
label: 'Check XSL functionality'
......
......@@ -76,8 +76,7 @@ class XmlSitemapFunctionalTest extends XmlSitemapTestBase {
public function testStatusReport() {
// Test the rebuild flag.
$this->drupalLogin($this->admin_user);
\Drupal::config('xmlsitemap.settings')->set('generated_last', REQUEST_TIME);
\Drupal::config('xmlsitemap.settings')->save();
\Drupal::state()->set('generated_last', REQUEST_TIME);
\Drupal::state()->set('rebuild_needed', TRUE);
$this->assertXMLSitemapProblems(t('The XML sitemap data is out of sync and needs to be completely rebuilt.'));
$this->clickLink(t('completely rebuilt'));
......@@ -86,8 +85,7 @@ class XmlSitemapFunctionalTest extends XmlSitemapTestBase {
$this->assertNoXMLSitemapProblems();
//Test the regenerate flag (and cron hasn't run in a while).
\Drupal::state()->set('regenerate_needed', TRUE);
\Drupal::config('xmlsitemap.settings')->set('generated_last', REQUEST_TIME - \Drupal::config('xmlsitemap.settings')->get('cron_threshold_warning') - 100);
\Drupal::config('xmlsitemap.settings')->save();
\Drupal::state()->set('generated_last', REQUEST_TIME - \Drupal::config('xmlsitemap.settings')->get('cron_threshold_warning') - 100);
$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);
......
......@@ -85,10 +85,9 @@ abstract class XmlSitemapTestBase extends WebTestBase {
*/
protected function regenerateSitemap() {
\Drupal::state()->set('regenerate_needed', TRUE);
\Drupal::config('xmlsitemap.settings')->set('generated_last', 0);
\Drupal::config('xmlsitemap.settings')->save();
\Drupal::state()->set('generated_last', 0);
$this->cronRun();
$this->assertTrue(\Drupal::config('xmlsitemap.settings')->get('generated_last') && !\Drupal::state()->get('regenerate_needed'), t('XML sitemaps regenerated and flag cleared.'));
$this->assertTrue(\Drupal::state()->get('generated_last') && !\Drupal::state()->get('regenerate_needed'), t('XML sitemaps regenerated and flag cleared.'));
}
protected function assertSitemapLink($entity_type, $entity_id = NULL) {
......
......@@ -296,7 +296,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
$this->assertResponse(200);
$this->assertNoRaw('lifetime-test');
\Drupal::config('xmlsitemap.settings')->set('generated_last', REQUEST_TIME - 400)->save();
\Drupal::state()->set('generated_last', REQUEST_TIME - 400);
$this->cronRun();
$this->drupalGetSitemap();
$this->assertRaw('lifetime-test');
......
......@@ -325,7 +325,7 @@ class XmlSitemapGeneratorService implements XmlSitemapGeneratorInterface {
*/
public function regenerateBatchFinished($success, $results, $operations, $elapsed) {
if ($success && !\Drupal::state()->get('regenerate_needed', FALSE)) {
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_generated_last', REQUEST_TIME);
\Drupal::state()->set('generated_last', REQUEST_TIME);
//drupal_set_message(t('The sitemaps were regenerated.'));
// Show a watchdog message that the sitemap was regenerated.
watchdog('xmlsitemap', 'Finished XML sitemap generation in @elapsed. Memory usage: @memory-peak.', array(
......
......@@ -349,7 +349,7 @@ function xmlsitemap_regenerate_batch_generate_index($smid, array &$context) {
*/
function xmlsitemap_regenerate_batch_finished($success, $results, $operations, $elapsed) {
if ($success && \Drupal::state()->get('regenerate_needed') == FALSE) {
\Drupal::config('xmlsitemap.settings')->set('generated_last', REQUEST_TIME)->save();
\Drupal::state()->set('generated_last', REQUEST_TIME);
drupal_set_message(t('The sitemaps were regenerated.'));
// Show a watchdog message that the sitemap was regenerated.
watchdog('xmlsitemap', 'Finished XML sitemap generation in @elapsed. Memory usage: @memory-peak.', array(
......
......@@ -116,7 +116,7 @@ function xmlsitemap_requirements($phase) {
}
// Check when the cached files were last generated.
$generated_last = \Drupal::config('xmlsitemap.settings')->get('generated_last');
$generated_last = \Drupal::state()->get('generated_last', 0);
$generated_ago = REQUEST_TIME - $generated_last;
$requirements['xmlsitemap_generated'] = array(
'title' => $t('XML sitemap'),
......
......@@ -176,7 +176,7 @@ function xmlsitemap_cron() {
}
// If the minimum sitemap lifetime hasn't been passed, skip.
$lifetime = REQUEST_TIME - \Drupal::config('xmlsitemap.settings')->get('generated_last');
$lifetime = REQUEST_TIME - \Drupal::state()->get('generated_last');
if ($lifetime < \Drupal::config('xmlsitemap.settings')->get('minimum_lifetime')) {
return;
}
......@@ -217,7 +217,6 @@ function xmlsitemap_robotstxt() {
function xmlsitemap_config_variables() {
return array(
'minimum_lifetime' => 0,
'generated_last' => 0,
'xsl' => 1,
'prefetch_aliases' => 1,
'chunk_size' => 'auto',
......@@ -247,6 +246,7 @@ function xmlsitemap_state_variables() {
'rebuild_needed' => FALSE,
'regenerate_needed' => TRUE,
'base_url' => '',
'generated_last' => 0,
'developer_mode' => 0
);
}
......
......@@ -51,8 +51,7 @@ class XmlSitemapEnginesFunctionalTest extends XmlSitemapTestBase {
'xmlsitemap_engines_submit_last' => REQUEST_TIME - 10000,
'xmlsitemap_engines_minimum_lifetime' => 0
));
\Drupal::config('xmlsitemap.settings')->set('generated_last', REQUEST_TIME - 100);
\Drupal::config('xmlsitemap.settings')->save();
\Drupal::state()->set('generated_last', REQUEST_TIME - 100);
xmlsitemap_engines_cron();
$this->assertTrue(\Drupal::state()->get('xmlsitemap_engines_submit_last') > (REQUEST_TIME - 100), 'Submitted the sitemaps to search engines. {}');
}
......
......@@ -68,7 +68,7 @@ function xmlsitemap_engines_submit_access() {
$minimum_lifetime = \Drupal::state()->get('xmlsitemap_engines_minimum_lifetime');
// Skip if sitemap data has not been updated since last submission.
if ($submit_updated && \Drupal::config('xmlsitemap.settings')->get('generated_last') <= $submitted_last) {
if ($submit_updated && \Drupal::state()->get('generated_last') <= $submitted_last) {
return FALSE;
}
......
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