function drush_xmlsitemap_queue_rebuild in XML sitemap 7.2
Dump and queue all the sitemap links to be rebuilt in a queue process.
File
- ./
xmlsitemap.drush.inc, line 119 - Drush integration functions for the xmlsitemap module.
Code
function drush_xmlsitemap_queue_rebuild() {
module_load_include('generate.inc', 'xmlsitemap');
$types = xmlsitemap_get_rebuildable_link_types();
if ($option_types = drush_get_option('types', '')) {
$option_types = explode(',', $option_types);
if ($invalid_types = array_diff($option_types, $types)) {
drush_set_error(dt('The following link types are invalid: @types', array(
'@types' => implode(', ', $invalid_types),
)));
}
$types = array_intersect($types, $option_types);
}
if (empty($types)) {
return drush_log(dt('No link types are rebuildable.'), 'warning');
}
xmlsitemap_rebuild_clear($types, TRUE);
$link_count = 0;
$chunk_count = 0;
$chunk_size = (int) drush_get_option('limit', variable_get('xmlsitemap_batch_limit', XMLSITEMAP_BATCH_LIMIT));
// @todo Figure out how to re-use this code with xmlsitemap_rebuild_batch_fetch()
foreach ($types as $type) {
$info = xmlsitemap_get_link_info($type);
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', $type);
$query
->entityCondition('entity_id', 0, '>');
$query
->addTag('xmlsitemap_link_bundle_access');
$query
->addTag('xmlsitemap_rebuild');
$query
->addMetaData('entity', $type);
$query
->addMetaData('entity_info', $info);
if ($bundles = xmlsitemap_get_link_type_enabled_bundles($type)) {
$query
->entityCondition('bundle', $bundles, 'IN');
}
else {
// If no enabled bundle types, skip everything else.
continue;
}
$results = $query
->execute();
if (!empty($results[$type])) {
$ids = array_keys($results[$type]);
$link_count += count($ids);
$chunks = array_chunk($ids, $chunk_size);
$chunk_count += count($chunks);
foreach ($chunks as $chunk) {
xmlsitemap_link_enqueue($type, $chunk);
}
}
}
if ($link_count) {
drush_log(dt('Queued @link_count links for rebuild processing in the xmlsitemap_link_process (in @chunk_count chunks of up to @chunk_size links each).', array(
'@link_count' => $link_count,
'@chunk_count' => $chunk_count,
'@chunk_size' => $chunk_size,
)), 'success');
}
else {
drush_log(dt('No links to queue for rebuild processing.'), 'ok');
}
variable_set('xmlsitemap_rebuild_needed', FALSE);
}