You are here

function xmlsitemap_regenerate_batch in XML sitemap 8

Same name and namespace in other branches
  1. 6.2 xmlsitemap.generate.inc \xmlsitemap_regenerate_batch()
  2. 7.2 xmlsitemap.generate.inc \xmlsitemap_regenerate_batch()
  3. 2.x xmlsitemap.module \xmlsitemap_regenerate_batch()

Batch information callback for regenerating the sitemap files.

Parameters

array $smids: An optional array of XML sitemap IDs. If not provided, it will load all existing XML sitemaps.

4 calls to xmlsitemap_regenerate_batch()
drush_xmlsitemap_regenerate in ./xmlsitemap.drush.inc
Regenerate the sitemap files from existing data.
XmlSitemapCommands::regenerate in src/Commands/XmlSitemapCommands.php
Regenerate the XML sitemap files.
xmlsitemap_rebuild_batch in ./xmlsitemap.module
Batch information callback for rebuilding the sitemap data.
xmlsitemap_sitemap_multiple_update in ./xmlsitemap.module
XML sitemap operation callback; regenerate sitemap files using the batch API.
1 string reference to 'xmlsitemap_regenerate_batch'
xmlsitemap_cron in ./xmlsitemap.module
Implements hook_cron().

File

./xmlsitemap.module, line 2438
xmlsitemap XML sitemap

Code

function xmlsitemap_regenerate_batch(array $smids = []) {
  if (empty($smids)) {
    $sitemaps = \Drupal::entityTypeManager()
      ->getStorage('xmlsitemap')
      ->loadMultiple();
    foreach ($sitemaps as $sitemap) {
      $smids[] = $sitemap
        ->id();
    }
  }
  $t = 't';
  $batch = [
    'operations' => [],
    'error_message' => $t('An error has occurred.'),
    'finished' => 'xmlsitemap_regenerate_batch_finished',
    'title' => t('Regenerating Sitemap'),
  ];

  // Set the regenerate flag in case something fails during file generation.
  $batch['operations'][] = [
    'xmlsitemap_batch_variable_set',
    [
      [
        'xmlsitemap_regenerate_needed' => TRUE,
      ],
    ],
  ];

  // @todo Get rid of this batch operation.
  $batch['operations'][] = [
    '_xmlsitemap_regenerate_before',
    [],
  ];

  // Generate all the sitemap pages for each context.
  foreach ($smids as $smid) {
    $batch['operations'][] = [
      'xmlsitemap_regenerate_batch_generate',
      [
        $smid,
      ],
    ];
    $batch['operations'][] = [
      'xmlsitemap_regenerate_batch_generate_index',
      [
        $smid,
      ],
    ];
  }

  // Clear the regeneration flag.
  $batch['operations'][] = [
    'xmlsitemap_batch_variable_set',
    [
      [
        'xmlsitemap_regenerate_needed' => FALSE,
      ],
    ],
  ];
  return $batch;
}