Unverified Commit 736d0e02 authored by Dave Reid's avatar Dave Reid Committed by Dave Reid
Browse files

Issue #2392579 by Dave Reid, davidburns, marvin_B8: Fxied rebuild should skip...

Issue #2392579 by Dave Reid, davidburns, marvin_B8: Fxied rebuild should skip excluded bundles. Fixed xmlsitemap_rebuild_batch_fetch() to not duplicate XmlSitemapGenerator::rebuildBatchFetch().
parent 5ca1c882
......@@ -420,14 +420,23 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface {
public function rebuildBatchFetch($entity_type_id, &$context) {
if (!isset($context['sandbox']['info'])) {
$context['sandbox']['info'] = xmlsitemap_get_link_info($entity_type_id);
$context['sandbox']['bundles'] = xmlsitemap_get_link_type_enabled_bundles($entity_type_id);
$context['sandbox']['progress'] = 0;
$context['sandbox']['last_id'] = 0;
}
if (empty($context['sandbox']['bundles'])) {
return;
}
$info = $context['sandbox']['info'];
$entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
$query = \Drupal::entityQuery($entity_type_id);
$query->condition($entity_type->getKey('id'), $context['sandbox']['last_id'], '>');
if ($entity_type->hasKey('bundle')) {
$query->condition($entity_type->getKey('bundle'), $context['sandbox']['bundles'], 'IN');
}
$query->addTag('xmlsitemap_link_bundle_access');
$query->addTag('xmlsitemap_rebuild');
$query->addMetaData('entity_type_id', $entity_type_id);
......
......@@ -2590,11 +2590,8 @@ function xmlsitemap_batch_variable_set(array $variables) {
* Save custom data.
* @param array $context
* Context to be rebuilt.
*
* @codingStandardsIgnoreStart
*/
function xmlsitemap_rebuild_batch_clear(array $entity_type_ids, $save_custom, &$context = []) {
// @codingStandardsIgnoreEnd
function xmlsitemap_rebuild_batch_clear(array $entity_type_ids, $save_custom, array &$context = []) {
\Drupal::service('xmlsitemap_generator')->rebuildBatchClear($entity_type_ids, $save_custom, $context);
}
......@@ -2605,61 +2602,9 @@ function xmlsitemap_rebuild_batch_clear(array $entity_type_ids, $save_custom, &$
* Entity type ID.
* @param array $context
* Sitemap context.
*
* @codingStandardsIgnoreStart
*/
function xmlsitemap_rebuild_batch_fetch($entity_type_id, &$context) {
// @codingStandardsIgnoreEnd
if (!isset($context['sandbox']['info'])) {
$context['sandbox']['info'] = xmlsitemap_get_link_info($entity_type_id);
$context['sandbox']['progress'] = 0;
$context['sandbox']['last_id'] = 0;
}
$info = $context['sandbox']['info'];
$entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
$query = \Drupal::entityQuery($entity_type_id);
$query->condition($entity_type->getKey('id'), $context['sandbox']['last_id'], '>');
$query->addTag('xmlsitemap_link_bundle_access');
$query->addTag('xmlsitemap_rebuild');
$query->addMetaData('entity_type_id', $entity_type_id);
$query->addMetaData('entity_info', $info);
if (!isset($context['sandbox']['max'])) {
$count_query = clone $query;
$count_query->count();
$context['sandbox']['max'] = $count_query->execute();
if (!$context['sandbox']['max']) {
// If there are no items to process, skip everything else.
return;
}
}
// PostgreSQL cannot have the ORDERED BY in the count query.
$query->sort($entity_type->getKey('id'));
// Get batch limit.
$limit = \Drupal::config('xmlsitemap.settings')->get('batch_limit');
$query->range(0, $limit);
$result = $query->execute();
$info['xmlsitemap']['process callback']($entity_type_id, $result);
$context['sandbox']['last_id'] = end($result);
$context['sandbox']['progress'] += count($result);
$context['message'] = t('Now processing %entity_type_id @last_id (@progress of @count).', [
'%entity_type_id' => $entity_type_id,
'@last_id' => $context['sandbox']['last_id'],
'@progress' => $context['sandbox']['progress'],
'@count' => $context['sandbox']['max'],
]);
if ($context['sandbox']['progress'] >= $context['sandbox']['max']) {
$context['finished'] = 1;
}
else {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
function xmlsitemap_rebuild_batch_fetch($entity_type_id, array &$context) {
\Drupal::service('xmlsitemap_generator')->rebuildBatchFetch($entity_type_id, $context);
}
/**
......@@ -2673,11 +2618,8 @@ function xmlsitemap_rebuild_batch_fetch($entity_type_id, &$context) {
* Operations performed.
* @param int $elapsed
* Time elapsed.
*
* @codingStandardsIgnoreStart
*/
function xmlsitemap_rebuild_batch_finished($success, $results, $operations, $elapsed) {
// @codingStandardsIgnoreEnd
function xmlsitemap_rebuild_batch_finished($success, array $results, array $operations, $elapsed) {
\Drupal::service('xmlsitemap_generator')->rebuildBatchFinished($success, $results, $operations, $elapsed);
}
......
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