You are here

function xmlsitemap_xmlsitemap_index_links in XML sitemap 2.x

Same name and namespace in other branches
  1. 8 xmlsitemap.module \xmlsitemap_xmlsitemap_index_links()

Implements hook_xmlsitemap_index_links().

1 call to xmlsitemap_xmlsitemap_index_links()
xmlsitemap_cron in ./xmlsitemap.module
Implements hook_cron().


./xmlsitemap.module, line 1550
xmlsitemap XML sitemap


function xmlsitemap_xmlsitemap_index_links($limit) {
  $entity_type_manager = \Drupal::entityTypeManager();
  $entity_types = $entity_type_manager
  foreach ($entity_types as $entity_type_id => $entity_type) {

    // If an entity type is not supported it will not have link info.
    $info = xmlsitemap_get_link_info($entity_type_id);
    if (empty($info)) {
    $bundles = xmlsitemap_get_link_type_enabled_bundles($entity_type_id);
    if (empty($bundles)) {
    try {
      $query = $entity_type_manager
        ->range(0, $limit);
      if (!empty($info['entity keys']['bundle'])) {
          ->condition($info['entity keys']['bundle'], $bundles, 'IN');

      // Perform a subquery against the xmlsitemap table to ensure that we are
      // only looking for items that we have not already indexed.
      $subquery = \Drupal::database()
        ->select('xmlsitemap', 'x');
        ->addField('x', 'id');
        ->condition('type', $entity_type_id);

      // If the storage for this entity type is against a SQL backend, perform
      // a direct subquery condition to avoid needing to load all the IDs.
      if ($query instanceof \Drupal\Core\Entity\Query\Sql\Query) {
          ->condition($info['entity keys']['id'], $subquery, 'NOT IN');
      else {
          ->condition($info['entity keys']['id'], $subquery
          ->fetchCol(), 'NOT IN');

      // Access for entities is checked individually for the anonymous user
      // when each item is processed. We can skip the access check for the
      // query.
      if ($ids = $query
        ->execute()) {

        // Chunk the array into batch sizes.
        $chunks = array_chunk($ids, \Drupal::config('xmlsitemap.settings')
        foreach ($chunks as $chunk) {
          $info['xmlsitemap']['process callback']($entity_type_id, $chunk);
          ->info('Indexed @count new @type items.', [
          '@count' => count($ids),
          '@type' => $entity_type_id,
    } catch (\Exception $e) {
      watchdog_exception('xmlsitemap', $e);