Commit 43187667 authored by andrei.dincu's avatar andrei.dincu

Issue #2249723 by andrei.dincu: Add xmlsitemap_ prefix to all state() keys

parent 84d59083
......@@ -22,7 +22,7 @@ class XmlSitemapController extends ControllerBase {
$file = xmlsitemap_sitemap_get_file($sitemap, $chunk);
// Provide debugging information if enabled.
if (\Drupal::state()->get('developer_mode')) {
if (\Drupal::state()->get('xmlsitemap_developer_mode')) {
$output = array();
$context = xmlsitemap_get_current_context();
$output[] = "Current context: " . print_r($context, TRUE);
......
......@@ -28,8 +28,8 @@ class XmlSitemapRebuildForm extends ConfigFormBase {
*/
public function buildForm(array $form, array &$form_state) {
$request = $this->getRequest();
if (!$request->request && !\Drupal::state()->get('rebuild_needed')) {
if (!\Drupal::state()->get('regenerate_needed')) {
if (!$request->request && !\Drupal::state()->get('xmlsitemap_rebuild_needed')) {
if (!\Drupal::state()->get('xmlsitemap_regenerate_needed')) {
drupal_set_message(t('Your sitemap is up to date and does not need to be rebuilt.'), 'error');
}
else {
......@@ -49,8 +49,8 @@ class XmlSitemapRebuildForm extends ConfigFormBase {
'#description' => t('If no link types are selected, the sitemap files will just be regenerated.'),
'#multiple' => TRUE,
'#options' => $rebuild_types,
'#default_value' => \Drupal::state()->get('rebuild_needed') || !\Drupal::state()->get('developer_mode') ? $rebuild_types : array(),
'#access' => \Drupal::state()->get('developer_mode'),
'#default_value' => \Drupal::state()->get('xmlsitemap_rebuild_needed') || !\Drupal::state()->get('xmlsitemap_developer_mode') ? $rebuild_types : array(),
'#access' => \Drupal::state()->get('xmlsitemap_developer_mode'),
);
$form['save_custom'] = array(
'#type' => 'checkbox',
......
......@@ -28,7 +28,6 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
\Drupal::moduleHandler()->loadInclude('xmlsitemap', 'inc', 'xmlsitemap.admin');
$intervals = array(300, 900, 1800, 3600, 10800, 21600, 43200, 86400, 172800, 259200, 604800);
$form['minimum_lifetime'] = array(
'#type' => 'select',
......@@ -54,7 +53,7 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
'#type' => 'details',
'#title' => t('Advanced settings'),
'#collapsible' => TRUE,
'#collapsed' => !\Drupal::state()->get('developer_mode'),
'#collapsed' => !\Drupal::state()->get('xmlsitemap_developer_mode'),
'#weight' => 10,
);
$form['advanced']['gz'] = array(
......@@ -93,10 +92,10 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
'#field_prefix' => file_build_uri(''),
'#required' => TRUE,
);
$form['advanced']['base_url'] = array(
$form['advanced']['xmlsitemap_base_url'] = array(
'#type' => 'textfield',
'#title' => t('Default base URL'),
'#default_value' => \Drupal::state()->get('base_url'),
'#default_value' => \Drupal::state()->get('xmlsitemap_base_url'),
'#size' => 30,
'#description' => t('This is the default base URL used for sitemaps and sitemap links.'),
'#required' => TRUE,
......@@ -114,10 +113,10 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
foreach ($form['advanced']['lastmod_format']['#options'] as $key => &$label) {
$label .= ' (' . gmdate($key, REQUEST_TIME) . ')';
}
$form['advanced']['developer_mode'] = array(
$form['advanced']['xmlsitemap_developer_mode'] = array(
'#type' => 'checkbox',
'#title' => t('Enable developer mode to expose additional settings.'),
'#default_value' => \Drupal::state()->get('developer_mode'),
'#default_value' => \Drupal::state()->get('xmlsitemap_developer_mode'),
);
$form['xmlsitemap_settings'] = array(
......@@ -167,10 +166,10 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
form_set_error('chunk_size', t('The sitemap page link count of @size will create more than 1,000 sitemap pages. Please increase the link count.', array('@size' => $chunk_size)));
}
$base_url = &$form_state['values']['base_url'];
$base_url = &$form_state['values']['xmlsitemap_base_url'];
$base_url = rtrim($base_url, '/');
if ($base_url != '' && !UrlHelper::isValid($base_url, TRUE)) {
\Drupal::formBuilder()->setErrorByName('base_url', $form_state, t('Invalid base URL.'));
\Drupal::formBuilder()->setErrorByName('xmlsitemap_base_url', $form_state, t('Invalid base URL.'));
}
parent::validateForm($form, $form_state);
......@@ -183,10 +182,10 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
// Save any changes to the frontpage link.
$values = $form_state['values'];
xmlsitemap_link_save(array('type' => 'frontpage', 'id' => 0, 'loc' => ''));
\Drupal::state()->set('developer_mode', $values['developer_mode']);
\Drupal::state()->set('base_url', $values['base_url']);
unset($values['developer_mode']);
unset($values['base_url']);
\Drupal::state()->set('xmlsitemap_developer_mode', $values['xmlsitemap_developer_mode']);
\Drupal::state()->set('xmlsitemap_base_url', $values['xmlsitemap_base_url']);
unset($values['xmlsitemap_developer_mode']);
unset($values['xmlsitemap_base_url']);
foreach ($values as $key => $value) {
\Drupal::config('xmlsitemap.settings')->set($key, $value);
}
......
......@@ -50,18 +50,18 @@ class XmlSitemapFunctionalTest extends XmlSitemapTestBase {
*/
public function testBaseURL() {
$this->drupalLogin($this->admin_user);
$edit = array('base_url' => '');
$edit = array('xmlsitemap_base_url' => '');
$this->drupalPostForm('admin/config/search/xmlsitemap/settings', $edit, t('Save configuration'));
$edit = array('base_url' => 'invalid');
$edit = array('xmlsitemap_base_url' => 'invalid');
$this->drupalPostForm('admin/config/search/xmlsitemap/settings', $edit, t('Save configuration'));
$this->assertText(t('Invalid base URL.'));
$edit = array('base_url' => 'http://example.com/ ');
$edit = array('xmlsitemap_base_url' => 'http://example.com/ ');
$this->drupalPostForm('admin/config/search/xmlsitemap/settings', $edit, t('Save configuration'));
$this->assertText(t('Invalid base URL.'));
$edit = array('base_url' => 'http://example.com/');
$edit = array('xmlsitemap_base_url' => 'http://example.com/');
$this->drupalPostForm('admin/config/search/xmlsitemap/settings', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
......@@ -76,16 +76,16 @@ class XmlSitemapFunctionalTest extends XmlSitemapTestBase {
public function testStatusReport() {
// Test the rebuild flag.
$this->drupalLogin($this->admin_user);
\Drupal::state()->set('generated_last', REQUEST_TIME);
\Drupal::state()->set('rebuild_needed', TRUE);
\Drupal::state()->set('xmlsitemap_generated_last', REQUEST_TIME);
\Drupal::state()->set('xmlsitemap_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'));
$this->assertResponse(200);
\Drupal::state()->set('rebuild_needed', FALSE);
\Drupal::state()->set('xmlsitemap_rebuild_needed', FALSE);
$this->assertNoXMLSitemapProblems();
//Test the regenerate flag (and cron hasn't run in a while).
\Drupal::state()->set('regenerate_needed', TRUE);
\Drupal::state()->set('generated_last', REQUEST_TIME - \Drupal::config('xmlsitemap.settings')->get('cron_threshold_warning') - 100);
\Drupal::state()->set('xmlsitemap_regenerate_needed', TRUE);
\Drupal::state()->set('xmlsitemap_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);
......
......@@ -84,10 +84,10 @@ abstract class XmlSitemapTestBase extends WebTestBase {
* Regenerate the sitemap by setting the regenerate flag and running cron.
*/
protected function regenerateSitemap() {
\Drupal::state()->set('regenerate_needed', TRUE);
\Drupal::state()->set('generated_last', 0);
\Drupal::state()->set('xmlsitemap_regenerate_needed', TRUE);
\Drupal::state()->set('xmlsitemap_generated_last', 0);
$this->cronRun();
$this->assertTrue(\Drupal::state()->get('generated_last') && !\Drupal::state()->get('regenerate_needed'), t('XML sitemaps regenerated and flag cleared.'));
$this->assertTrue(\Drupal::state()->get('xmlsitemap_generated_last') && !\Drupal::state()->get('xmlsitemap_regenerate_needed'), t('XML sitemaps regenerated and flag cleared.'));
}
protected function assertSitemapLink($entity_type, $entity_id = NULL) {
......
......@@ -29,14 +29,14 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
}
public function testAssertFlag() {
\Drupal::state()->set('rebuild_needed', TRUE);
$this->assertTrue(xmlsitemap_var('rebuild_needed'));
$this->assertTrue($this->assertFlag('rebuild_needed', TRUE, FALSE));
$this->assertTrue(xmlsitemap_var('rebuild_needed'));
$this->assertTrue($this->assertFlag('rebuild_needed', TRUE, TRUE));
$this->assertFalse(xmlsitemap_var('rebuild_needed'));
$this->assertTrue($this->assertFlag('rebuild_needed', FALSE, FALSE));
$this->assertFalse(xmlsitemap_var('rebuild_needed'));
\Drupal::state()->set('xmlsitemap_rebuild_needed', TRUE);
$this->assertTrue(xmlsitemap_var('xmlsitemap_rebuild_needed'));
$this->assertTrue($this->assertFlag('xmlsitemap_rebuild_needed', TRUE, FALSE));
$this->assertTrue(xmlsitemap_var('xmlsitemap_rebuild_needed'));
$this->assertTrue($this->assertFlag('xmlsitemap_rebuild_needed', TRUE, TRUE));
$this->assertFalse(xmlsitemap_var('xmlsitemap_rebuild_needed'));
$this->assertTrue($this->assertFlag('xmlsitemap_rebuild_needed', FALSE, FALSE));
$this->assertFalse(xmlsitemap_var('xmlsitemap_rebuild_needed'));
}
/**
......@@ -154,47 +154,47 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
public function testSaveLink() {
$link = array('type' => 'testing', 'id' => 1, 'loc' => 'testing', 'status' => 1);
xmlsitemap_link_save($link);
$this->assertFlag('regenerate_needed', TRUE);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$link['status'] = 0;
xmlsitemap_link_save($link);
$this->assertFlag('regenerate_needed', TRUE);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$link['priority'] = 0.5;
$link['loc'] = 'new_location';
$link['status'] = 1;
xmlsitemap_link_save($link);
$this->assertFlag('regenerate_needed', TRUE);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$link['priority'] = 0.0;
xmlsitemap_link_save($link);
$this->assertFlag('regenerate_needed', TRUE);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$link['priority'] = 0.1;
xmlsitemap_link_save($link);
$this->assertFlag('regenerate_needed', TRUE);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$link['priority'] = 1.0;
xmlsitemap_link_save($link);
$this->assertFlag('regenerate_needed', TRUE);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$link['priority'] = 1;
xmlsitemap_link_save($link);
$this->assertFlag('regenerate_needed', FALSE);
$this->assertFlag('xmlsitemap_regenerate_needed', FALSE);
$link['priority'] = 0;
xmlsitemap_link_save($link);
$this->assertFlag('regenerate_needed', TRUE);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$link['priority'] = 0.5;
xmlsitemap_link_save($link);
$this->assertFlag('regenerate_needed', TRUE);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$link['priority'] = 0.5;
$link['priority_override'] = 0;
$link['status'] = 1;
xmlsitemap_link_save($link);
$this->assertFlag('regenerate_needed', FALSE);
$this->assertFlag('xmlsitemap_regenerate_needed', FALSE);
}
/**
......@@ -205,7 +205,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
$link1 = $this->addSitemapLink(array('loc' => 'testing1', 'status' => 0));
$link2 = $this->addSitemapLink(array('loc' => 'testing1', 'status' => 1));
$link3 = $this->addSitemapLink(array('status' => 0));
\Drupal::state()->set('regenerate_needed', FALSE);
\Drupal::state()->set('xmlsitemap_regenerate_needed', FALSE);
// Test delete multiple links.
// Test that the regenerate flag is set when visible links are deleted.
......@@ -214,12 +214,12 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
$this->assertFalse(xmlsitemap_link_load($link1['type'], $link1['id']));
$this->assertFalse(xmlsitemap_link_load($link2['type'], $link2['id']));
$this->assertTrue(xmlsitemap_link_load($link3['type'], $link3['id']));
$this->assertFlag('regenerate_needed', TRUE);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$deleted = xmlsitemap_link_delete($link3['type'], $link3['id']);
$this->assertEqual($deleted, 1);
$this->assertFalse(xmlsitemap_link_load($link3['type'], $link3['id']));
$this->assertFlag('regenerate_needed', FALSE);
$this->assertFlag('xmlsitemap_regenerate_needed', FALSE);
}
/**
......@@ -231,7 +231,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
$links[1] = $this->addSitemapLink(array('subtype' => 'group1'));
$links[2] = $this->addSitemapLink(array('subtype' => 'group1'));
$links[3] = $this->addSitemapLink(array('subtype' => 'group2'));
\Drupal::state()->set('regenerate_needed', FALSE);
\Drupal::state()->set('xmlsitemap_regenerate_needed', FALSE);
// id | type | subtype | language | access | status | priority
// 1 | testing | group1 | '' | 1 | 1 | 0.5
// 2 | testing | group1 | '' | 1 | 1 | 0.5
......@@ -239,7 +239,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
$updated = xmlsitemap_link_update_multiple(array('status' => 0), array('type' => 'testing', 'subtype' => 'group1', 'status_override' => 0));
$this->assertEqual($updated, 2);
$this->assertFlag('regenerate_needed', TRUE);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
// id | type | subtype | language | status | priority
// 1 | testing | group1 | '' | 0 | 0.5
// 2 | testing | group1 | '' | 0 | 0.5
......@@ -247,7 +247,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
$updated = xmlsitemap_link_update_multiple(array('priority' => 0.0), array('type' => 'testing', 'subtype' => 'group1', 'priority_override' => 0));
$this->assertEqual($updated, 2);
$this->assertFlag('regenerate_needed', FALSE);
$this->assertFlag('xmlsitemap_regenerate_needed', FALSE);
// id | type | subtype | language | status | priority
// 1 | testing | group1 | '' | 0 | 0.0
// 2 | testing | group1 | '' | 0 | 0.0
......@@ -255,7 +255,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
$updated = xmlsitemap_link_update_multiple(array('subtype' => 'group2'), array('type' => 'testing', 'subtype' => 'group1'));
$this->assertEqual($updated, 2);
$this->assertFlag('regenerate_needed', FALSE);
$this->assertFlag('xmlsitemap_regenerate_needed', FALSE);
// id | type | subtype | language | status | priority
// 1 | testing | group2 | '' | 0 | 0.0
// 2 | testing | group2 | '' | 0 | 0.0
......@@ -263,7 +263,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
$updated = xmlsitemap_link_update_multiple(array('status' => 1), array('type' => 'testing', 'subtype' => 'group2', 'status_override' => 0, 'status' => 0));
$this->assertEqual($updated, 2);
$this->assertFlag('regenerate_needed', TRUE);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
// id | type | subtype | language | status | priority
// 1 | testing | group2 | '' | 1 | 0.0
// 2 | testing | group2 | '' | 1 | 0.0
......@@ -296,7 +296,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
$this->assertResponse(200);
$this->assertNoRaw('lifetime-test');
\Drupal::state()->set('generated_last', REQUEST_TIME - 400);
\Drupal::state()->set('xmlsitemap_generated_last', REQUEST_TIME - 400);
$this->cronRun();
$this->drupalGetSitemap();
$this->assertRaw('lifetime-test');
......
......@@ -54,7 +54,7 @@ class XmlSitemapGeneratorService implements XmlSitemapGeneratorInterface {
// Attempt to increase the memory limit.
_xmlsitemap_set_memory_limit();
if (\Drupal::state()->get('developer_mode')) {
if (\Drupal::state()->get('xmlsitemap_developer_mode')) {
watchdog('xmlsitemap', 'Starting XML sitemap generation. Memory usage: @memory-peak.', array(
'@memory-peak' => format_size(memory_get_peak_usage(TRUE)),
), WATCHDOG_DEBUG
......@@ -137,7 +137,7 @@ class XmlSitemapGeneratorService implements XmlSitemapGeneratorInterface {
$url_options = $sitemap->uri['options'];
$url_options += array(
'absolute' => TRUE,
'base_url' => \Drupal::state()->get('base_url'),
'xmlsitemap_base_url' => \Drupal::state()->get('xmlsitemap_base_url'),
'language' => language_default(),
'alias' => \Drupal::config('xmlsitemap.settings')->get('prefetch_aliases'),
);
......@@ -249,7 +249,7 @@ class XmlSitemapGeneratorService implements XmlSitemapGeneratorInterface {
);
// Set the regenerate flag in case something fails during file generation.
$batch['operations'][] = array('xmlsitemap_batch_variable_set', array(array('regenerate_needed' => TRUE)));
$batch['operations'][] = array('xmlsitemap_batch_variable_set', array(array('xmlsitemap_regenerate_needed' => TRUE)));
// @todo Get rid of this batch operation.
$batch['operations'][] = array('_xmlsitemap_regenerate_before', array());
......@@ -261,7 +261,7 @@ class XmlSitemapGeneratorService implements XmlSitemapGeneratorInterface {
}
// Clear the regeneration flag.
$batch['operations'][] = array('xmlsitemap_batch_variable_set', array(array('regenerate_needed' => FALSE)));
$batch['operations'][] = array('xmlsitemap_batch_variable_set', array(array('xmlsitemap_regenerate_needed' => FALSE)));
return $batch;
}
......@@ -324,8 +324,8 @@ class XmlSitemapGeneratorService implements XmlSitemapGeneratorInterface {
* {@inheritdoc}
*/
public function regenerateBatchFinished($success, $results, $operations, $elapsed) {
if ($success && !\Drupal::state()->get('regenerate_needed', FALSE)) {
\Drupal::state()->set('generated_last', REQUEST_TIME);
if ($success && !\Drupal::state()->get('xmlsitemap_regenerate_needed', FALSE)) {
\Drupal::state()->set('xmlsitemap_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(
......
......@@ -20,7 +20,7 @@ class XmlSitemapIndexWriter extends XmlSitemapWriter {
public function getRootAttributes() {
$attributes['xmlns'] = 'http://www.sitemaps.org/schemas/sitemap/0.9';
if (\Drupal::state()->get('developer_mode')) {
if (\Drupal::state()->get('xmlsitemap_developer_mode')) {
$attributes['xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance';
$attributes['xsi:schemaLocation'] = 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd';
}
......@@ -33,8 +33,8 @@ class XmlSitemapIndexWriter extends XmlSitemapWriter {
$url_options = $this->sitemap->uri['options'];
$url_options += array(
'absolute' => TRUE,
'base_url' => variable_get('xmlsitemap_base_url', $GLOBALS['base_url']),
'language' => language_default(),
'xmlsitemap_base_url' => \Drupal::state()->get('xmlsitemap_base_url'),
'language' => \Drupal::languageManager()->getDefaultLanguage(),
'alias' => TRUE,
);
......
......@@ -49,7 +49,7 @@ class XmlSitemapLinkStorage {
$existing = db_query_range("SELECT loc, access, status, lastmod, priority, changefreq, changecount, language FROM {xmlsitemap} WHERE type = :type AND id = :id", 0, 1, array(':type' => $link['type'], ':id' => $link['id']))->fetchAssoc();
// Check if this is a changed link and set the regenerate flag if necessary.
if (!\Drupal::state()->get('regenerate_needed')) {
if (!\Drupal::state()->get('xmlsitemap_regenerate_needed')) {
self::checkChangedLink($link, $existing, TRUE);
}
......@@ -107,7 +107,7 @@ class XmlSitemapLinkStorage {
}
if ($changed && $flag) {
\Drupal::state()->set('regenerate_needed', TRUE);
\Drupal::state()->set('xmlsitemap_regenerate_needed', TRUE);
}
return $changed;
......@@ -138,7 +138,7 @@ class XmlSitemapLinkStorage {
$changed = $query->execute()->fetchField();
if ($changed && $flag) {
\Drupal::state()->set('regenerate_needed', TRUE);
\Drupal::state()->set('xmlsitemap_regenerate_needed', TRUE);
}
return $changed;
......@@ -183,7 +183,7 @@ class XmlSitemapLinkStorage {
return FALSE;
}
if (!\Drupal::state()->get('regenerate_needed')) {
if (!\Drupal::state()->get('xmlsitemap_regenerate_needed')) {
self::checkChangedLinks($conditions, array(), TRUE);
}
......@@ -213,7 +213,7 @@ class XmlSitemapLinkStorage {
public static function linkUpdateMultiple($updates = array(), $conditions = array(), $check_flag = TRUE) {
// If we are going to modify a visible sitemap link, we will need to set
// the regenerate needed flag.
if ($check_flag && !\Drupal::state()->get('regenerate_needed')) {
if ($check_flag && !\Drupal::state()->get('xmlsitemap_regenerate_needed')) {
self::checkChangedLinks($conditions, $updates, TRUE);
}
......
......@@ -68,7 +68,7 @@ class XmlSitemapWriter extends \XMLWriter {
*/
public function getRootAttributes() {
$attributes['xmlns'] = 'http://www.sitemaps.org/schemas/sitemap/0.9';
if (\Drupal::state()->get('developer_mode')) {
if (\Drupal::state()->get('xmlsitemap_developer_mode')) {
$attributes['xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance';
$attributes['xsi:schemaLocation'] = 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd';
}
......
......@@ -61,7 +61,7 @@ function _xmlsitemap_regenerate_before() {
// Attempt to increase the memory limit.
_xmlsitemap_set_memory_limit();
if (\Drupal::state()->get('developer_mode')) {
if (\Drupal::state()->get('xmlsitemap_developer_mode')) {
watchdog('xmlsitemap', 'Starting XML sitemap generation. Memory usage: @memory-peak.', array(
'@memory-peak' => format_size(memory_get_peak_usage(TRUE)),
), WATCHDOG_DEBUG
......@@ -151,7 +151,7 @@ function xmlsitemap_generate_chunk(XmlSitemapInterface $sitemap, XmlSitemapWrite
$url_options = $sitemap->uri['options'];
$url_options += array(
'absolute' => TRUE,
'base_url' => \Drupal::state()->get('base_url'),
'base_url' => \Drupal::state()->get('xmlsitemap_base_url', ''),
'language' => language_default(),
'alias' => \Drupal::config('xmlsitemap.settings')->get('prefetch_aliases'),
);
......@@ -272,7 +272,7 @@ function xmlsitemap_regenerate_batch(array $smids = array()) {
);
// Set the regenerate flag in case something fails during file generation.
$batch['operations'][] = array('xmlsitemap_batch_variable_set', array(array('regenerate_needed' => TRUE)));
$batch['operations'][] = array('xmlsitemap_batch_variable_set', array(array('xmlsitemap_regenerate_needed' => TRUE)));
// @todo Get rid of this batch operation.
$batch['operations'][] = array('_xmlsitemap_regenerate_before', array());
......@@ -284,7 +284,7 @@ function xmlsitemap_regenerate_batch(array $smids = array()) {
}
// Clear the regeneration flag.
$batch['operations'][] = array('xmlsitemap_batch_variable_set', array(array('regenerate_needed' => FALSE)));
$batch['operations'][] = array('xmlsitemap_batch_variable_set', array(array('xmlsitemap_regenerate_needed' => FALSE)));
return $batch;
}
......@@ -348,8 +348,8 @@ function xmlsitemap_regenerate_batch_generate_index($smid, array &$context) {
* Batch callback; sitemap regeneration finished.
*/
function xmlsitemap_regenerate_batch_finished($success, $results, $operations, $elapsed) {
if ($success && \Drupal::state()->get('regenerate_needed') == FALSE) {
\Drupal::state()->set('generated_last', REQUEST_TIME);
if ($success && \Drupal::state()->get('xmlsitemap_regenerate_needed') == FALSE) {
\Drupal::state()->set('xmlsitemap_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(
......@@ -375,7 +375,7 @@ function xmlsitemap_rebuild_batch(array $entities, $save_custom = FALSE) {
);
// Set the rebuild flag in case something fails during the rebuild.
$batch['operations'][] = array('xmlsitemap_batch_variable_set', array(array('rebuild_needed' => TRUE)));
$batch['operations'][] = array('xmlsitemap_batch_variable_set', array(array('xmlsitemap_rebuild_needed' => TRUE)));
// Purge any links first.
$batch['operations'][] = array('xmlsitemap_rebuild_batch_clear', array($entities, (bool) $save_custom));
......@@ -387,7 +387,7 @@ function xmlsitemap_rebuild_batch(array $entities, $save_custom = FALSE) {
}
// Clear the rebuild flag.
$batch['operations'][] = array('xmlsitemap_batch_variable_set', array(array('rebuild_needed' => FALSE)));
$batch['operations'][] = array('xmlsitemap_batch_variable_set', array(array('xmlsitemap_rebuild_needed' => FALSE)));
// Add the regeneration batch.
$regenerate_batch = xmlsitemap_regenerate_batch();
......@@ -490,7 +490,7 @@ function xmlsitemap_rebuild_batch_fetch($entity, &$context) {
* Batch callback; sitemap rebuild finished.
*/
function xmlsitemap_rebuild_batch_finished($success, $results, $operations, $elapsed) {
if ($success && !\Drupal::state()->get('rebuild_needed')) {
if ($success && !\Drupal::state()->get('xmlsitemap_rebuild_needed')) {
drupal_set_message(t('The sitemap links were rebuilt.'));
}
else {
......
......@@ -111,23 +111,23 @@ function xmlsitemap_requirements($phase) {
$requirements['xmlsitemap_file_size']['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)));
$requirements['xmlsitemap_file_size']['severity'] = REQUIREMENT_ERROR;
}
elseif (!\Drupal::state()->get('developer_mode')) {
elseif (!\Drupal::state()->get('xmlsitemap_developer_mode')) {
unset($requirements['xmlsitemap_file_size']);
}
// Check when the cached files were last generated.
$generated_last = \Drupal::state()->get('generated_last', 0);
$generated_last = \Drupal::state()->get('xmlsitemap_generated_last', 0);
$generated_ago = REQUEST_TIME - $generated_last;
$requirements['xmlsitemap_generated'] = array(
'title' => $t('XML sitemap'),
'value' => $generated_last ? $t('Last attempted generation on !date (!interval ago).', array('!date' => format_date($generated_last, 'small'), '!interval' => format_interval($generated_ago))) : $t('Cached files have not been generated yet.'),
'severity' => REQUIREMENT_OK,
);
if (\Drupal::state()->get('rebuild_needed')) {
if (\Drupal::state()->get('xmlsitemap_rebuild_needed')) {
$requirements['xmlsitemap_generated']['severity'] = REQUIREMENT_ERROR;
$requirements['xmlsitemap_generated']['description'] = $t('The XML sitemap data is out of sync and needs to be <a href="@link-rebuild">completely rebuilt<a>.', array('@link-rebuild' => url('admin/config/search/xmlsitemap/rebuild')));
}
elseif (\Drupal::state()->get('regenerate_needed')) {
elseif (\Drupal::state()->get('xmlsitemap_regenerate_needed')) {
if ($max_filesize == 0) {
// A maximum sitemap file size of 0 indicates an error in generation.
$requirements['xmlsitemap_generated']['severity'] = REQUIREMENT_ERROR;
......@@ -295,13 +295,13 @@ function xmlsitemap_install() {
$state_variables = xmlsitemap_state_variables();
\Drupal::state()->setMultiple($state_variables);
\Drupal::state()->set('base_url', url(NULL, array('absolute' => TRUE)));
\Drupal::state()->set('xmlsitemap_base_url', url(NULL, array('absolute' => TRUE)));
$context = xmlsitemap_get_current_context();
$sitemap = \Drupal::entityManager()->getStorage('xmlsitemap')->create(array(
'id' => xmlsitemap_sitemap_get_context_hash($context),
));
$sitemap->context = xmlsitemap_get_current_context();
$sitemap = $sitemap->setLabel(\Drupal::state()->get('base_url'));
$sitemap = $sitemap->setLabel(\Drupal::state()->get('xmlsitemap_base_url'));
$sitemap->save();
}
......@@ -312,7 +312,7 @@ function xmlsitemap_enable() {
// Ensure the file cache directory is available and ready.
xmlsitemap_check_directory();
\Drupal::state()->set('regenerate_needed', TRUE);
\Drupal::state()->set('xmlsitemap_regenerate_needed', TRUE);
}
/**
......
......@@ -171,12 +171,12 @@ function _xmlsitemap_rebuild_form_access() {
*/
function xmlsitemap_cron() {
// If there were no new or changed links, skip.
if (!\Drupal::state()->get('regenerate_needed')) {
if (!\Drupal::state()->get('xmlsitemap_regenerate_needed')) {
return;
}
// If the minimum sitemap lifetime hasn't been passed, skip.
$lifetime = REQUEST_TIME - \Drupal::state()->get('generated_last');
$lifetime = REQUEST_TIME - \Drupal::state()->get('xmlsitemap_generated_last');
if ($lifetime < \Drupal::config('xmlsitemap.settings')->get('minimum_lifetime')) {
return;
}
......@@ -222,8 +222,6 @@ function xmlsitemap_config_variables() {
'chunk_size' => 'auto',
'batch_limit' => 100,
'path' => 'xmlsitemap',
'base_url' => $GLOBALS['base_url'],
'developer_mode' => 0,
'frontpage_priority' => 1.0,
'frontpage_changefreq' => XMLSITEMAP_FREQUENCY_DAILY,
'lastmod_format' => XMLSITEMAP_LASTMOD_MEDIUM,
......@@ -243,11 +241,11 @@ function xmlsitemap_config_variables() {
*/
function xmlsitemap_state_variables() {
return array(
'rebuild_needed' => FALSE,
'regenerate_needed' => TRUE,
'base_url' => '',
'generated_last' => 0,
'developer_mode' => 0
'xmlsitemap_rebuild_needed' => FALSE,
'xmlsitemap_regenerate_needed' => TRUE,
'xmlsitemap_base_url' => '',
'xmlsitemap_generated_last' => 0,
'xmlsitemap_developer_mode' => 0
);
}
......@@ -376,7 +374,7 @@ function xmlsitemap_sitemap_save(XmlSitemapInterface $sitemap) {
xmlsitemap_directory_move($old_dir, $new_dir);
// Mark the sitemaps as needing regeneration.
\Drupal::state()->set('regenerate_needed', TRUE);
\Drupal::state()->set('xmlsitemap_regenerate_needed', TRUE);
}
$sitemap->save();
......@@ -458,7 +456,7 @@ function xmlsitemap_sitemap_uri(XmlSitemapInterface $sitemap) {
\Drupal::moduleHandler()->alter('xmlsitemap_context_url_options', $uri['options'], $context);
$uri['options'] += array(
'absolute' => TRUE,
'base_url' => \Drupal::state()->get('base_url')