From 7bc4bac5ec5c10784555b25ad8a5340c9d937386 Mon Sep 17 00:00:00 2001 From: Aaron Crosman Date: Thu, 7 Apr 2016 13:54:29 -0400 Subject: [PATCH] Re-roll of patch + a few other fixes. --- src/Form/XmlSitemapEntitiesSettingsForm.php | 15 +++---- src/Form/XmlSitemapLinkBundleSettingsForm.php | 1 + src/Form/XmlSitemapSettingsForm.php | 2 +- src/XmlSitemapGenerator.php | 33 +++++++++------- src/XmlSitemapLinkStorage.php | 8 +++- xmlsitemap.module | 56 ++++++++++----------------- xmlsitemap.services.yml | 7 +++- 7 files changed, 59 insertions(+), 63 deletions(-) diff --git a/src/Form/XmlSitemapEntitiesSettingsForm.php b/src/Form/XmlSitemapEntitiesSettingsForm.php index ced17a0..aa0832d 100644 --- a/src/Form/XmlSitemapEntitiesSettingsForm.php +++ b/src/Form/XmlSitemapEntitiesSettingsForm.php @@ -144,17 +144,17 @@ class XmlSitemapEntitiesSettingsForm extends ConfigFormBase implements Container '#markup' => SafeMarkup::checkPlain($bundle_info['label']), ), 'operations' => [ - '#type' => 'operations', - '#links' => [ - 'configure' => [ - 'title' => $this->t('Configure'), - 'url' => Url::fromRoute('xmlsitemap.admin_settings_bundle', array( + '#type' => 'operations', + '#links' => [ + 'configure' => [ + 'title' => $this->t('Configure'), + 'url' => Url::fromRoute('xmlsitemap.admin_settings_bundle', array( 'entity' => $entity_type_id, 'bundle' => $bundle, 'query' => drupal_get_destination(), )), - ] - ] + ] + ] ], ); $form['settings'][$entity_type_id]['types']['#default_value'][$bundle] = xmlsitemap_link_bundle_check_enabled($entity_type_id, $bundle); @@ -199,6 +199,7 @@ class XmlSitemapEntitiesSettingsForm extends ConfigFormBase implements Container } } } + \Drupal::state()->set('xmlsitemap_regenerate_needed', TRUE); parent::submitForm($form, $form_state); } } diff --git a/src/Form/XmlSitemapLinkBundleSettingsForm.php b/src/Form/XmlSitemapLinkBundleSettingsForm.php index 7622896..2ca103c 100644 --- a/src/Form/XmlSitemapLinkBundleSettingsForm.php +++ b/src/Form/XmlSitemapLinkBundleSettingsForm.php @@ -129,6 +129,7 @@ class XmlSitemapLinkBundleSettingsForm extends ConfigFormBase implements Contain $xmlsitemap = $form_state->getValue('xmlsitemap'); xmlsitemap_link_bundle_settings_save($this->entity_type, $this->bundle_type, $xmlsitemap, TRUE); + \Drupal::state()->set('xmlsitemap_regenerate_needed', TRUE); $entity_info = $form['xmlsitemap']['#entity_info']; if (!empty($form['xmlsitemap']['#show_message'])) { diff --git a/src/Form/XmlSitemapSettingsForm.php b/src/Form/XmlSitemapSettingsForm.php index e6da37f..a8a9ab1 100644 --- a/src/Form/XmlSitemapSettingsForm.php +++ b/src/Form/XmlSitemapSettingsForm.php @@ -252,7 +252,7 @@ class XmlSitemapSettingsForm extends ConfigFormBase { $config->set('frontpage_priority', $frontpage_priority); $config->set('frontpage_changefreq', $frontpage_changefreq); $config->save(); - $this->linkStorage->save(array('type' => 'frontpage', 'id' => 0, 'subtype' => '', 'loc' => '', 'priority' => $frontpage_priority, 'changefreq' => $frontpage_changefreq)); + $this->linkStorage->save(array('type' => 'frontpage', 'id' => 0, 'loc' => '', 'subtype' => '', 'priority' => $frontpage_priority, 'changefreq' => $frontpage_changefreq)); } $this->state->set('xmlsitemap_developer_mode', $values['xmlsitemap_developer_mode']); $this->state->set('xmlsitemap_base_url', $values['xmlsitemap_base_url']); diff --git a/src/XmlSitemapGenerator.php b/src/XmlSitemapGenerator.php index 85b044d..24e27f9 100644 --- a/src/XmlSitemapGenerator.php +++ b/src/XmlSitemapGenerator.php @@ -14,6 +14,7 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\State\StateInterface; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Url; +use \Psr\Log\LoggerInterface; /** * XmlSitemap generator service class. @@ -70,6 +71,13 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface { protected $state; /** + * A logger instance. + * + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + + /** * Constructs a XmlSitemapGenerator object. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory @@ -78,12 +86,15 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface { * The entity manager handler. * @param \Drupal\Core\State\StateInterface $state * The state handler. + * @param \Psr\Log\LoggerInterface $logger + * A logger instance. */ - public function __construct(ConfigFactoryInterface $config_factory, EntityManagerInterface $entity_manager, StateInterface $state, LanguageManagerInterface $language_manager) { + public function __construct(ConfigFactoryInterface $config_factory, EntityManagerInterface $entity_manager, StateInterface $state, LanguageManagerInterface $language_manager, LoggerInterface $logger) { $this->config = $config_factory->getEditable('xmlsitemap.settings'); $this->entityManager = $entity_manager; $this->state = $state; $this->languageManager = $language_manager; + $this->logger = $logger; } /** @@ -123,10 +134,9 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface { $this->setMemoryLimit(); if ($this->state->get('xmlsitemap_developer_mode')) { - $message = t('Starting XML sitemap generation. Memory usage: @memory-peak.', + $this->logger->notice('Starting XML sitemap generation. Memory usage: @memory-peak.', array( array('@memory-peak' => format_size(memory_get_peak_usage(TRUE)), - )); - \Drupal::logger('xmlsitemap')->debug($message); + ))); } } @@ -188,7 +198,7 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface { $writer->endDocument(); } catch (Exception $e) { - watchdog_exception('xmlsitemap', $e); + $this->logger->error($e); throw $e; } @@ -291,7 +301,7 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface { $writer->endDocument(); } catch (Exception $e) { - watchdog_exception('xmlsitemap', $e); + $this->logger->error($e); throw $e; return FALSE; } @@ -362,13 +372,7 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface { drupal_set_message(t('The sitemaps were regenerated.')); // Show a watchdog message that the sitemap was regenerated. - $message = t('Finished XML sitemap generation in @elapsed. Memory usage: @memory-peak.', - array( - '@elapsed' => $elapsed, - '@memory-peak' => format_size(memory_get_peak_usage(TRUE)), - ) - ); - \Drupal::logger('xmlsitemap')->notice($message); + $this->logger->notice('Finished XML sitemap generation in @elapsed. Memory usage: @memory-peak.', ['@elapsed' => $elapsed, '@memory-peak' => format_size(memory_get_peak_usage(TRUE))]); } else { drupal_set_message(t('The sitemaps were not successfully regenerated.'), 'error'); @@ -407,8 +411,7 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface { } $info = $context['sandbox']['info']; - $query = new EntityFieldQuery(); - $query->entityCondition('entity_type', $entity); + $query = \Drupal::entityQuery($entity); $query->entityCondition('entity_id', $context['sandbox']['last_id'], '>'); $query->addTag('xmlsitemap_link_bundle_access'); $query->addTag('xmlsitemap_rebuild'); diff --git a/src/XmlSitemapLinkStorage.php b/src/XmlSitemapLinkStorage.php index 3c6512f..fb88db6 100644 --- a/src/XmlSitemapLinkStorage.php +++ b/src/XmlSitemapLinkStorage.php @@ -77,6 +77,10 @@ class XmlSitemapLinkStorage implements XmlSitemapLinkStorageInterface { 'changefreq' => isset($settings['changefreq']) ? $settings['changefreq'] : 0, ); + if (method_exists($entity, 'getChangedTime')) { + $entity->xmlsitemap['lastmod'] = $entity->getChangedTime(); + } + $url = $entity->url(); // The following values must always be checked because they are volatile. $entity->xmlsitemap['loc'] = $uri; @@ -126,8 +130,8 @@ class XmlSitemapLinkStorage implements XmlSitemapLinkStorageInterface { ->fields(array( 'loc' => $link['loc'], 'subtype' => $link['subtype'], - 'access' => $link['access'], - 'status' => $link['status'], + 'access' => (int) $link['access'], + 'status' => (int) $link['status'], 'status_override' => $link['status_override'], 'lastmod' => $link['lastmod'], 'priority' => $link['priority'], diff --git a/xmlsitemap.module b/xmlsitemap.module index 85c924b..6a452c1 100644 --- a/xmlsitemap.module +++ b/xmlsitemap.module @@ -764,9 +764,8 @@ function xmlsitemap_link_bundle_settings_save($entity, $bundle, array $settings, } foreach ($settings as $key => $value) { - \Drupal::configFactory()->getEditable("xmlsitemap.settings.{$entity}.{$bundle}")->set($key, $value); + \Drupal::configFactory()->getEditable("xmlsitemap.settings.{$entity}.{$bundle}")->set($key, $value)->save(); } - \Drupal::configFactory()->getEditable("xmlsitemap.settings.{$entity}.{$bundle}")->save(); foreach (\Drupal::languageManager()->getLanguages() as $lang) { \Drupal::cache()->delete('xmlsitemap:link_info:' . $lang->getId()); @@ -1129,7 +1128,7 @@ function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) { $form['xmlsitemap'] = array( '#type' => 'details', '#tree' => TRUE, - '#title' => t('XML sitemap'), + '#title' => \Drupal::translation()->translate('XML sitemap'), '#collapsible' => TRUE, '#collapsed' => !$link['status_override'] && !$link['priority_override'], '#access' => $currentUser->hasPermission('administer xmlsitemap') || xmlsitemap_link_bundle_access($bundle_info), @@ -1468,19 +1467,6 @@ function xmlsitemap_get_operation_link($url, $options = array()) { } /** - * Implements hook_entity_info_alter(). - */ -function xmlsitemap_entity_info_alter(&$entity_info) { - if (!\Drupal::config('xmlsitemap.settings.user.user')->isNew()) { - return $entity_info; - } - $entity_info['user']['bundle label'] = t('User'); - $entity_info['user']['xmlsitemap'] = array( - 'process callback' => 'xmlsitemap_user_xmlsitemap_process_user_links', - ); -} - -/** * Returns HTML for an administration settings table. * * @param array $variables @@ -1557,12 +1543,12 @@ function xmlsitemap_xmlsitemap_index_links($limit) { } try { $query = \Drupal::entityManager()->getStorage($entity_type_id)->getQuery(); - $query->range(0, $limit); - if ($entity_type->get('type')) { - $query->condition('type', $entity_bundles, 'IN'); - } + $query->condition('type', $entity_bundles, 'IN'); $ids = $query->execute(); - xmlsitemap_xmlsitemap_process_entity_links($entity_type_id, $ids); + while ($ids) { + $ids_part = array_splice($ids, 0, $limit); + xmlsitemap_xmlsitemap_process_entity_links($entity_type_id, $ids_part); + } } catch (QueryException $e) { @@ -1772,27 +1758,27 @@ function xmlsitemap_query_xmlsitemap_generate_alter(AlterableInterface $query) { switch ($mode) { case 'simple': // Current language and language neutral. - $query->condition('language', array($current, LanguageInterface::LANGCODE_NOT_SPECIFIED)); + $query->condition('language', array($current, LanguageInterface::LANGCODE_NOT_SPECIFIED), 'IN'); break; case 'mixed': // Mixed current language (if available) or default language (if not) and language neutral. - $query->condition('language', array($current, $default, LanguageInterface::LANGCODE_NOT_SPECIFIED)); + $query->condition('language', array($current, $default, LanguageInterface::LANGCODE_NOT_SPECIFIED), 'IN'); break; case 'default': // Only default language and language neutral. - $query->condition('language', array($default, LanguageInterface::LANGCODE_NOT_SPECIFIED)); + $query->condition('language', array($default, LanguageInterface::LANGCODE_NOT_SPECIFIED), 'IN'); break; case 'strict': // Only current language (for nodes), simple for all other types. $node_condition = db_and(); - $node_condition->condition('type', 'node'); - $node_condition->condition('language', $current); + $node_condition->condition('type', 'node', 'IN'); + $node_condition->condition('language', $current, 'IN'); $normal_condition = db_and(); $normal_condition->condition('type', 'node', '<>'); - $normal_condition->condition('language', array($current, LanguageInterface::LANGCODE_NOT_SPECIFIED)); + $normal_condition->condition('language', array($current, LanguageInterface::LANGCODE_NOT_SPECIFIED), 'IN'); $condition = db_or(); $condition->condition($node_condition); $condition->condition($normal_condition); @@ -2034,7 +2020,7 @@ function xmlsitemap_add_link_bundle_settings(array &$form, FormStateInterface $f '#type' => 'select', '#title' => t('Inclusion'), '#options' => xmlsitemap_get_status_options(), - '#default_value' => $bundle_info['status'], + '#default_value' => (int) $bundle_info['status'], ); $form['xmlsitemap']['priority'] = array( '#type' => 'select', @@ -2264,11 +2250,11 @@ function _xmlsitemap_get_blurb($check_version = TRUE) { $blurb = FALSE; if (!$check_version || (($version = _xmlsitemap_get_version()) && preg_match('/dev|unstable|alpha|beta|HEAD/i', $version))) { $sponsors = array( - $this->l('Symantec', Url::fromUri('http://www.symantec.com/')), - $this->l('WebWise Solutions', Url::fromUri('http://www.webwiseone.com/')), - $this->l('Volacci', Url::fromUri('http://www.volacci.com/')), - $this->l('lanetro', Url::fromUri('http://www.lanetro.com/')), - $this->l('Coupons Dealuxe', Url::fromUri('http://couponsdealuxe.com/')), + \Drupal::l('Symantec', Url::fromUri('http://www.symantec.com/')), + \Drupal::l('WebWise Solutions', Url::fromUri('http://www.webwiseone.com/')), + \Drupal::l('Volacci', Url::fromUri('http://www.volacci.com/')), + \Drupal::l('lanetro', Url::fromUri('http://www.lanetro.com/')), + \Drupal::l('Coupons Dealuxe', Url::fromUri('http://couponsdealuxe.com/')), ); // Don't extract the following string for translation. $blurb = '

Thank you for helping test the XML sitemap module rewrite. Please consider helping offset developer free time by donating or if your company is interested in sponsoring the rewrite or a specific feature, please contact the developer. Thank you to the following current sponsors: ' . implode(', ', $sponsors) . ', and all the individuals that have donated. This message will not be seen in the stable versions.

'; @@ -2378,7 +2364,6 @@ function xmlsitemap_regenerate_batch(array $smids = array()) { 'error_message' => $t('An error has occurred.'), 'finished' => 'xmlsitemap_regenerate_batch_finished', 'title' => t('Regenerating Sitemap'), - 'file' => drupal_get_path('module', 'xmlsitemap') . '/xmlsitemap.generate.inc', ); // Set the regenerate flag in case something fails during file generation. @@ -2520,8 +2505,7 @@ function xmlsitemap_rebuild_batch_fetch($entity, &$context) { } $info = $context['sandbox']['info']; - $query = new EntityFieldQuery(); - $query->entityCondition('entity_type', $entity); + $query = \Drupal::entityQuery($entity); $query->entityCondition('entity_id', $context['sandbox']['last_id'], '>'); $query->addTag('xmlsitemap_link_bundle_access'); $query->addTag('xmlsitemap_rebuild'); diff --git a/xmlsitemap.services.yml b/xmlsitemap.services.yml index 7e503bb..e992bac 100644 --- a/xmlsitemap.services.yml +++ b/xmlsitemap.services.yml @@ -1,11 +1,14 @@ services: xmlsitemap_generator: class: Drupal\xmlsitemap\XmlSitemapGenerator - arguments: ['@config.factory', '@entity.manager', '@state', '@language_manager'] + arguments: ['@config.factory', '@entity.manager', '@state', '@language_manager', '@logger.channel.xmlsitemap'] tags: - { name: xmlsitemap_generator } xmlsitemap.link_storage: class: Drupal\xmlsitemap\XmlSitemapLinkStorage arguments: ['@state', '@module_handler'] tags: - - { name: xmlsitemap.link_storage } \ No newline at end of file + - { name: xmlsitemap.link_storage } + logger.channel.xmlsitemap: + parent: logger.channel_base + arguments: ['xmlsitemap'] -- 1.9.5.msysgit.0 From 6c41bc3a5cdfc39c5eecd26bea597c9694c28733 Mon Sep 17 00:00:00 2001 From: davereid Date: Tue, 2 Feb 2016 11:26:54 -0800 Subject: [PATCH] Issue #2661364 by Dave Reid: Fixed String class is now SafeMarkup --- xmlsitemap.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmlsitemap.module b/xmlsitemap.module index c187c50..85c924b 100644 --- a/xmlsitemap.module +++ b/xmlsitemap.module @@ -11,7 +11,7 @@ use Drupal\Component\Utility\Crypt; use Drupal\Core\Language\LanguageInterface; use Drupal\xmlsitemap\XmlSitemapInterface; -use Drupal\Component\Utility\String; +use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Render\Element; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Entity\EntityInterface; @@ -1945,7 +1945,7 @@ function xmlsitemap_add_form_entity_summary(&$form, $entity, array $entity_info) } else { // Bundle labels are assumed to be un-escaped input. - $row[] = String::checkPlain($bundle_info['label']); + $row[] = SafeMarkup::checkPlain($bundle_info['label']); } $row[] = $statuses[$bundle_info['xmlsitemap']['status'] ? 1 : 0]; $row[] = $priorities[number_format($bundle_info['xmlsitemap']['priority'], 1)]; -- 1.9.5.msysgit.0