Commit 7be8556f authored by amateescu's avatar amateescu

Issue #2479629 followup by amateescu: Generating sitemap of entities doesn't work

parent 599033c3
......@@ -89,6 +89,12 @@ abstract class XmlSitemapTestBase extends WebTestBase {
$this->entityManager = \Drupal::entityTypeManager();
$this->languageManager = \Drupal::languageManager();
$this->linkStorage = \Drupal::service('xmlsitemap.link_storage');
// Create the Article and Page content types.
if ($this->profile != 'standard') {
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Page']);
}
}
/**
......
......@@ -440,11 +440,10 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface {
$query->range(0, $limit);
$result = $query->execute();
$ids = array_keys($result[$entity_type_id]);
$info['xmlsitemap']['process callback']($ids);
$context['sandbox']['last_id'] = end($ids);
$context['sandbox']['progress'] += count($ids);
$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).', array('%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']) {
......
......@@ -653,9 +653,11 @@ function xmlsitemap_get_link_info($type = NULL, $reset = FALSE) {
'type' => $key,
'base table' => FALSE,
'bundles' => array(),
'xmlsitemap' => array(),
'xmlsitemap' => [
'process callback' => 'xmlsitemap_xmlsitemap_process_entity_links',
],
);
if (!isset($info['xmlsitemap']['rebuild callback']) && !empty($info['base table']) && !empty($info['entity keys']['id']) && !empty($info['xmlsitemap']['process callback'])) {
if (!isset($info['xmlsitemap']['rebuild callback']) && !empty($info['base table']) && $entity_types[$key]->getKey('id')) {
$info['xmlsitemap']['rebuild callback'] = 'xmlsitemap_rebuild_batch_fetch';
}
foreach ($info['bundles'] as $bundle => &$bundle_info) {
......@@ -703,7 +705,7 @@ function xmlsitemap_get_link_type_enabled_bundles($entity_type) {
/**
* Returns statistics about specific entity links.
*
* @param string $entity_type
* @param string $entity_type_id
* Entity type id.
* @param string $bundle
* Bundle id.
......@@ -711,24 +713,30 @@ function xmlsitemap_get_link_type_enabled_bundles($entity_type) {
* @return array
* Array with statistics.
*/
function xmlsitemap_get_link_type_indexed_status($entity_type, $bundle = '') {
$info = xmlsitemap_get_link_info($entity_type);
function xmlsitemap_get_link_type_indexed_status($entity_type_id, $bundle = '') {
$info = xmlsitemap_get_link_info($entity_type_id);
$entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
$status['indexed'] = db_query("SELECT COUNT(id) FROM {xmlsitemap} WHERE type = :entity AND subtype = :bundle", array(':entity' => $entity_type, ':bundle' => $bundle))->fetchField();
$status['visible'] = db_query("SELECT COUNT(id) FROM {xmlsitemap} WHERE type = :entity AND subtype = :bundle AND status = 1 AND access = 1", array(':entity' => $entity_type, ':bundle' => $bundle))->fetchField();
$status['indexed'] = db_query("SELECT COUNT(id) FROM {xmlsitemap} WHERE type = :entity AND subtype = :bundle", array(':entity' => $entity_type_id, ':bundle' => $bundle))->fetchField();
$status['visible'] = db_query("SELECT COUNT(id) FROM {xmlsitemap} WHERE type = :entity AND subtype = :bundle AND status = 1 AND access = 1", array(':entity' => $entity_type_id, ':bundle' => $bundle))->fetchField();
try {
$entity_query_object = \Drupal::entityQuery($entity_type);
$entity_query_object->addTag('xmlsitemap_link_bundle_access');
$entity_query_object->addTag('xmlsitemap_link_indexed_status');
$entity_query_object->addMetaData('entity', $entity_type);
$entity_query_object->addMetaData('type', $bundle);
$entity_query_object->addMetaData('entity_info', $info);
$entity_query_object->count();
$status['total'] = $entity_query_object->execute();
$query = \Drupal::entityQuery($entity_type_id);
if ($bundle) {
$query->condition($entity_type->getKey('bundle'), $bundle, '=');
}
$query->addTag('xmlsitemap_link_bundle_access');
$query->addTag('xmlsitemap_link_indexed_status');
$query->addMetaData('entity_type_id', $entity_type_id);
$query->addMetaData('bundle', $bundle);
$query->addMetaData('entity_info', $info);
$query->count();
$status['total'] = $query->execute();
return $status;
}
catch (Exception $e) {
catch (\Exception $e) {
$status['total'] = 0;
}
return $status;
......@@ -2543,11 +2551,10 @@ function xmlsitemap_rebuild_batch_fetch($entity_type_id, &$context) {
$query->range(0, $limit);
$result = $query->execute();
$ids = array_keys($result[$entity_type_id]);
$info['xmlsitemap']['process callback']($ids);
$context['sandbox']['last_id'] = end($ids);
$context['sandbox']['progress'] += count($ids);
$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).', array('%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']) {
......
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