Commit 7f1363c5 authored by Dave Reid's avatar Dave Reid
Browse files

by Dave Reid: OMG. Rebuilding, regeneration, and sitemap operations are all working now.

parent 54186f4e
......@@ -22,7 +22,6 @@ function xmlsitemap_sitemap_list_form() {
'#title' => t('Update options'),
'#prefix' => '<div class="container-inline">',
'#suffix' => '</div>',
'#access' => FALSE, // @todo Remove this when operations works.
);
$form['options']['operation'] = array(
'#type' => 'select',
......@@ -154,8 +153,8 @@ function xmlsitemap_sitemap_list_submit($form, &$form_state) {
call_user_func_array($function, $args);
$count = count($form_state['values']['sitemaps']);
watchdog('xmlsitemap', '@action @count XML sitemaps.', array('@action' => $operation['action_past'], '@count' => $count));
drupal_set_message(format_plural(count($rids), '@action @count XML sitemap.', '@action @count XML sitemaps.', array('@action' => $operation['action_past'], '@count' => $count)));
watchdog('xmlsitemap', '@action @count XML sitemaps.', array('@action' => $operation['action past'], '@count' => $count));
drupal_set_message(format_plural(count($sitemaps), '@action @count XML sitemap.', '@action @count XML sitemaps.', array('@action' => $operation['action past'], '@count' => $count)));
//$form_state['redirect'] = 'admin/config/search/xmlsitemap';
}
}
......@@ -262,23 +261,24 @@ function xmlsitemap_sitemap_delete_form_submit($form, $form_state) {
* @see xmlsitemap_settings_form_validate()
*/
function xmlsitemap_settings_form() {
$form['xmlsitemap'] = array(
'#type' => 'fieldset',
'#title' => t('Settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['xmlsitemap']['xmlsitemap_minimum_lifetime'] = array(
$form['xmlsitemap_minimum_lifetime'] = array(
'#type' => 'select',
'#title' => t('Minimum sitemap lifetime'),
'#options' => array(0 => t('No minimum')) + drupal_map_assoc(array(300, 900, 1800, 3600, 10800, 21600, 43200, 86400, 172800, 259200, 604800), 'format_interval'),
'#default_value' => xmlsitemap_var('minimum_lifetime')
'#description' => t('The minimum amount of time that will elapse before the sitemaps are regenerated. The sitemaps will also only be regenerated on cron if any links have been added, updated, or deleted.') . '<br />' . t('Recommended value: %value.', array('%value' => t('1 day'))),
'#default_value' => 0,
);
$form['xmlsitemap']['xmlsitemap_xsl'] = array(
$form['xmlsitemap_xsl'] = array(
'#type' => 'checkbox',
'#title' => t('Include a stylesheet in the sitemaps for humans.'),
'#default_value' => xmlsitemap_var('xsl'),
'#description' => t('Using the stylesheet will add formatting and tables with sorting to make it easier to view the XML sitemap data instead of viewing raw XML output. Search engines will ignore any formatting.')
'#description' => t('When enabled, this will add formatting and tables with sorting to make it easier to view the XML sitemap data instead of viewing raw XML output. Search engines will ignore this.'),
'#default_value' => 1,
);
$form['xmlsitemap_prefetch_aliases'] = array(
'#type' => 'checkbox',
'#title' => t('Prefetch URL aliases during sitemap generation.'),
'#description' => t('When enabled, this will fetch all URL alises at once instead of one at a time during sitemap generation. For medium or large sites, it is recommended to disable this feature as it uses a lot of memory.'),
'#default_value' => 1,
);
$form['advanced'] = array(
......@@ -297,16 +297,10 @@ function xmlsitemap_settings_form() {
$form['advanced']['xmlsitemap_chunk_size'] = array(
'#type' => 'select',
'#title' => t('Number of links in each sitemap page'),
'#options' => array('auto' => t('Automatic (recommended)')) + drupal_map_assoc(array(100, 500, 1000, 2500, 5000, 10000, 25000, 50000)),
'#options' => array('auto' => t('Automatic (recommended)')) + drupal_map_assoc(array(100, 500, 1000, 2500, 5000, 10000, 25000, XMLSITEMAP_MAX_SITEMAP_LINKS)),
'#default_value' => xmlsitemap_var('chunk_size'),
// @todo This description is not clear.
'#description' => t('If there are problems with rebuilding the sitemap, you may want to manually set this value. If you have more than 50,000 links, an index with multiple sitemap pages will be generated. There is a maximum of 1000 sitemap pages.'),
);
$form['advanced']['xmlsitemap_prefetch_aliases'] = array(
'#type' => 'checkbox',
'#title' => t('Prefetch URL aliases during sitemap generation.'),
'#description' => t('This will help increase performance for sitemap generation on sites with a small to medium number of URL alises.'),
'#default_value' => TRUE,
'#description' => t('If there are problems with rebuilding the sitemap, you may want to manually set this value. If you have more than @max links, an index with multiple sitemap pages will be generated. There is a maximum of @max sitemap pages.', array('@max' => XMLSITEMAP_MAX_SITEMAP_LINKS)),
);
$form['advanced']['xmlsitemap_batch_limit'] = array(
'#type' => 'select',
......@@ -341,11 +335,11 @@ function xmlsitemap_settings_form() {
'#type' => 'select',
'#title' => t('Last modification date format'),
'#options' => array(
'Y-m-d' => t('Short'),
'Y-m-d\TH:i\Z' => t('Medium'),
'c' => t('Long'),
XMLSITEMAP_LASTMOD_SHORT => t('Short'),
XMLSITEMAP_LASTMOD_MEDIUM => t('Medium'),
XMLSITEMAP_LASTMOD_LONG => t('Long'),
),
'#default_value' => 'Y-m-d\TH:i\Z',
'#default_value' => XMLSITEMAP_LASTMOD_MEDIUM,
);
foreach ($form['advanced']['xmlsitemap_lastmod_format']['#options'] as $key => &$label) {
$label .= ' (' . gmdate($key, REQUEST_TIME) . ')';
......@@ -440,38 +434,17 @@ function xmlsitemap_rebuild_form() {
}
}
// Build the list of rebuildable entities.
$entities = xmlsitemap_get_link_info();
$callbacks = $options = array();
foreach ($entities as $entity => $info) {
if (empty($info['xmlsitemap']['rebuild callback'])) {
// If the entity is missing a rebuild callback, skip.
continue;
}
if (!empty($info['entity keys']['bundle']) && !xmlsitemap_get_link_type_enabled_bundles($entity)) {
// If the entity has bundles, but no enabled bundles, skip since
// rebuilding wouldn't get any links.
continue;
}
else {
// Build the list of callbacks and options for the form and batch
// processing.
$callbacks[$entity] = $info['xmlsitemap']['rebuild callback'];
$options[$entity] = $info['label'];
}
}
// Build a list of rebuildable link types.
module_load_include('generate.inc', 'xmlsitemap');
$rebuild_types = xmlsitemap_get_rebuildable_link_types();
$form['callbacks'] = array(
'#type' => 'value',
'#value' => $callbacks,
);
$form['entities'] = array(
'#type' => 'select',
'#title' => t("Select which link types you would like to rebuild"),
'#description' => t('If no link types are selected, the sitemap files will just be regenerated.'),
'#multiple' => TRUE,
'#options' => $options,
'#default_value' => variable_get('xmlsitemap_rebuild_needed', FALSE) || !variable_get('xmlsitemap_developer_mode', 0) ? array_keys($options) : array(),
'#options' => drupal_map_assoc($rebuild_types),
'#default_value' => variable_get('xmlsitemap_rebuild_needed', FALSE) || !variable_get('xmlsitemap_developer_mode', 0) ? $rebuild_types : array(),
'#access' => variable_get('xmlsitemap_developer_mode', 0),
);
$form['save_custom'] = array(
......@@ -497,11 +470,8 @@ function xmlsitemap_rebuild_form() {
* @see xmlsitemap_rebuild_batch()
*/
function xmlsitemap_rebuild_form_submit($form, &$form_state) {
// Set the rebuild flag incase something fails during the rebuild.
variable_set('xmlsitemap_rebuild_needed', TRUE);
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.generate');
$batch = xmlsitemap_rebuild_batch($form_state['values']['entities'], $form_state['values']['callbacks'], $form_state['values']['save_custom']);
module_load_include('generate.inc', 'xmlsitemap');
$batch = xmlsitemap_rebuild_batch($form_state['values']['entities'], $form_state['values']['save_custom']);
batch_set($batch);
$form_state['redirect'] = 'admin/config/search/xmlsitemap';
}
......
......@@ -37,8 +37,10 @@ function xmlsitemap_drush_command() {
* Regenerate the sitemap files from existing data.
*/
function drush_xmlsitemap_regenerate() {
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.generate');
xmlsitemap_regenerate();
module_load_include('generate.inc', 'xmlsitemap');
// Run the batch process.
xmlsitemap_run_progressive_batch('xmlsitemap_regenerate_batch');
$vars = array(
'@timer' => timer_read('xmlsitemap_regenerate'),
......@@ -51,44 +53,13 @@ function drush_xmlsitemap_regenerate() {
* Dump and rebuild all the sitemap data, then regenerate the files.
*/
function drush_xmlsitemap_rebuild() {
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.generate');
timer_start('xmlsitemap_rebuild');
// Set the rebuild flag incase something fails during the rebuild.
variable_set('xmlsitemap_rebuild_needed', TRUE);
// Build the list of rebuildable entities.
$entities = xmlsitemap_get_link_info();
$callbacks = $options = array();
foreach ($entities as $entity => $info) {
if (empty($info['xmlsitemap']['rebuild callback'])) {
// If the entity is missing a rebuild callback, skip.
continue;
}
if (!empty($info['entity keys']['bundle']) && !xmlsitemap_get_link_type_enabled_bundles($entity)) {
// If the entity has bundles, but no enabled bundles, skip since
// rebuilding wouldn't get any links.
continue;
}
else {
// Build the list of callbacks and options for the form and batch
// processing.
$callbacks[$entity] = $info['xmlsitemap']['rebuild callback'];
$options[$entity] = $info['label'];
}
}
// Build the batch array.
$batch = xmlsitemap_rebuild_batch(array_keys($options), $callbacks, TRUE);
batch_set($batch);
module_load_include('generate.inc', 'xmlsitemap');
// We need to manually set the progressive variable again.
// @todo Remove when http://drupal.org/node/638712 is fixed.
$batch =& batch_get();
$batch['progressive'] = FALSE;
// Build a list of rebuildable link types.
$rebuild_types = xmlsitemap_get_rebuildable_link_types();
// Run the batch process.
batch_process();
xmlsitemap_run_progressive_batch('xmlsitemap_rebuild_batch', $rebuild_types, TRUE);
$vars = array(
'@timer' => timer_read('xmlsitemap_rebuild'),
......
......@@ -44,56 +44,15 @@ function xmlsitemap_get_path_alias($path, $language) {
}
}
/**
* @todo Move to xmlsitemap.context.inc
*/
function xmlsitemap_get_url_options_from_context(array $context) {
$options = module_invoke_all('xmlsitemap_context_url_options', $context);
drupal_alter('xmlsitemap_context_url_options', $options, $context);
return $options;
}
/**
* @todo Replace with table of sitemap objects.
*/
function xmlsitemap_get_contexts() {
$contexts = array();
if (module_exists('xmlsitemap_i18n')) {
foreach (xmlsitemap_var('languages') as $langcode) {
$contexts[] = array('language' => $langcode);
}
}
else {
// Add an empty, default context.
$contexts[] = array();
}
$hashes = array_map('md5', array_map('serialize', $contexts));
$contexts = array_combine($hashes, $contexts);
return $contexts;
}
/**
* Delete and regenerate the sitemap files.
*/
function xmlsitemap_regenerate() {
_xmlsitemap_regenerate_before();
// Generate the sitemap pages.
$contexts = xmlsitemap_get_contexts();
$chunk_count = xmlsitemap_get_chunk_count(TRUE);
foreach ($contexts as $context) {
// Generate index.
if ($chunk_count > 1) {
xmlsitemap_generate('index', $context);
}
for ($i = 1; $i <= $chunk_count; $i++) {
xmlsitemap_generate($i, $context);
}
}
_xmlsitemap_regenerate_after();
}
/**
* Perform operations before rebuilding the sitemap.
*/
......@@ -179,23 +138,23 @@ function _xmlsitemap_regenerate_after() {
/**
* Fetch the data from {xmlsitemap}, generates the sitemap, then caches it.
*
* @param $sitemap
* An unserialized data array for an XML sitemap.
* @param $chunk
* An integer representing the integer of the sitemap page chunk.
* @param $language
* A language object, defaults to the default language.
* @return
* TRUE on success; otherwise FALSE
*
* @todo Revise/simplify or remove the function.
*/
function xmlsitemap_generate($chunk, array $context) {
if (($chunk == 'index' && xmlsitemap_get_chunk_count() < 2) || ($chunk != 'index' && (!is_numeric($chunk) || $chunk > xmlsitemap_get_chunk_count()))) {
function xmlsitemap_generate(array $sitemap, $chunk) {
if ($chunk != 'index' && !is_numeric($chunk)) {
// Don't bother translating this string.
trigger_error('Improper condition hit in xmlsitemap_generate(). Chunk: ' . $chunk . ', Chunk Count: ' . xmlsitemap_get_chunk_count());
trigger_error('Improper condition hit in xmlsitemap_generate(). Chunk: ' . $chunk);
return FALSE;
}
$file = xmlsitemap_get_file_from_context($context, $chunk);
$file = xmlsitemap_get_file_from_context($sitemap['context'], $chunk);
if (!$handle = fopen($file, 'wb')) {
trigger_error(t('Could not open file @file for writing.', array('@file' => $file)));
......@@ -204,10 +163,13 @@ function xmlsitemap_generate($chunk, array $context) {
$status = TRUE;
if ($chunk == 'index') {
xmlsitemap_generate_index($handle, $status, $context);
xmlsitemap_generate_index($sitemap, $handle, $status);
}
else {
xmlsitemap_generate_chunk($handle, $status, $chunk, $context);
$links = xmlsitemap_generate_chunk($sitemap, $handle, $status, $chunk);
// @todo Fix this up.
fclose($handle);
return $links;
}
fclose($handle);
......@@ -228,21 +190,24 @@ function xmlsitemap_generate($chunk, array $context) {
return $status;
}
/**
* Write the proper XML sitemap header.
*
* @param $sitemap
* An unserialized data array for an XML sitemap.
* @param $type
* @param $handle
* A file system pointer resource that is typically created using fopen().
* @param $status
* @param $language
*/
function xmlsitemap_generate_chunk_header($type, $handle, &$status, array $context) {
function xmlsitemap_generate_chunk_header($type, array $sitemap, $handle, &$status) {
$output = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
$url_options = xmlsitemap_get_url_options_from_context($context);
// Add the stylesheet link.
if (xmlsitemap_var('xsl')) {
if (variable_get('xmlsitemap_xsl', 1)) {
$url_options = xmlsitemap_get_url_options_from_context($sitemap['context']);
$url_options['alias'] = TRUE;
$xsl_url = url('sitemap.xsl', $url_options);
$output .= '<?xml-stylesheet type="text/xsl" href="' . $xsl_url . '"?>' . PHP_EOL;
}
......@@ -263,6 +228,8 @@ function xmlsitemap_generate_chunk_header($type, $handle, &$status, array $conte
/**
* Generate one page (chunk) of the sitemap.
*
* @param $sitemap
* An unserialized data array for an XML sitemap.
* @param $handle
* A file system pointer resource that is typically created using fopen().
* @param $status
......@@ -270,11 +237,11 @@ function xmlsitemap_generate_chunk_header($type, $handle, &$status, array $conte
* writing to $handle.
* @param $chunk
* An integer representing the integer of the sitemap page chunk.
* @param $language
* A language object for the sitemap chunk.
*/
function xmlsitemap_generate_chunk($handle, &$status, $chunk, array $context) {
$url_options = xmlsitemap_get_url_options_from_context($context);
function xmlsitemap_generate_chunk(array $sitemap, $handle, &$status, $chunk) {
$lastmod_format = variable_get('xmlsitemap_lastmod_format', XMLSITEMAP_LASTMOD_MEDIUM);
$url_options = xmlsitemap_get_url_options_from_context($sitemap['context']);
$url_options += array(
'absolute' => TRUE,
'base_url' => xmlsitemap_var('base_url'),
......@@ -283,7 +250,7 @@ function xmlsitemap_generate_chunk($handle, &$status, $chunk, array $context) {
);
$last_url = '';
$lastmod_format = variable_get('xmlsitemap_lastmod_format', 'Y-m-d\TH:i\Z');
$link_count = 0;
$query = db_select('xmlsitemap', 'x');
$query->fields('x', array('loc', 'lastmod', 'changefreq', 'changecount', 'priority', 'language', 'access', 'status'));
......@@ -292,7 +259,7 @@ function xmlsitemap_generate_chunk($handle, &$status, $chunk, array $context) {
$query->orderBy('language', 'DESC');
$query->orderBy('loc');
$query->addTag('xmlsitemap');
$query->addMetaData('context', $context);
$query->addMetaData('context', $sitemap['context']);
$offset = max($chunk - 1, 0) * xmlsitemap_get_chunk_size();
$limit = xmlsitemap_get_chunk_size();
......@@ -300,7 +267,7 @@ function xmlsitemap_generate_chunk($handle, &$status, $chunk, array $context) {
$links = $query->execute();
// Add the XML header and XSL if desired.
xmlsitemap_generate_chunk_header('urlset', $handle, $status, $context);
xmlsitemap_generate_chunk_header('urlset', $sitemap, $handle, $status);
while ($link = $links->fetchAssoc()) {
$link['language'] = $link['language'] != LANGUAGE_NONE ? xmlsitemap_language_load($link['language']) : $url_options['language'];
......@@ -317,6 +284,8 @@ function xmlsitemap_generate_chunk($handle, &$status, $chunk, array $context) {
}
else {
$last_url = $link_url;
// Keep track of the total number of links written.
$link_count++;
}
$link_output = '<url><loc>' . $link_url . '</loc>';
......@@ -339,39 +308,39 @@ function xmlsitemap_generate_chunk($handle, &$status, $chunk, array $context) {
}
$link_output .= '</url>' . PHP_EOL;
$status &= (bool) fwrite($handle, $link_output);
}
// Close the XML file.
$status &= (bool) fwrite($handle, '</urlset>' . PHP_EOL);
return $status;
return $link_count;
}
/**
* Generate the index sitemap.
*
* @param $sitemap
* An unserialized data array for an XML sitemap.
* @param $handle
* A file system pointer resource that is typically created using fopen().
* @param $status
* @param $language
* A language object, defaults to the default language.
*/
function xmlsitemap_generate_index($handle, &$status, array $context) {
$url_options = xmlsitemap_get_url_options_from_context($context);
function xmlsitemap_generate_index(array $sitemap, $handle, &$status) {
$lastmod_format = variable_get('xmlsitemap_lastmod_format', XMLSITEMAP_LASTMOD_MEDIUM);
$url_options = xmlsitemap_get_url_options_from_context($sitemap['context']);
$url_options += array(
'absolute' => TRUE,
'base_url' => xmlsitemap_var('base_url'),
'alias' => TRUE,
'language' => language_default(),
'alias' => TRUE,
);
$chunk_count = xmlsitemap_get_chunk_count(TRUE);
$lastmod_format = variable_get('xmlsitemap_lastmod_format', 'Y-m-d\TH:i\Z');
// Add the XML header and XSL if desired.
xmlsitemap_generate_chunk_header('sitemapindex', $handle, $status, $context);
xmlsitemap_generate_chunk_header('sitemapindex', $sitemap, $handle, $status);
for ($i = 1; $i <= $chunk_count; $i++) {
for ($i = 1; $i <= $sitemap['chunks']; $i++) {
$output = '<sitemap>';
$url_options['query']['page'] = $i;
$output .= '<loc>' . url('sitemap.xml', $url_options) . '</loc>';
......@@ -384,13 +353,102 @@ function xmlsitemap_generate_index($handle, &$status, array $context) {
// Close the XML file.
$status &= (bool) fwrite($handle, '</sitemapindex>' . PHP_EOL);
return $status;
return $sitemap['chunks'];
}
// BATCH OPERATIONS ------------------------------------------------------------
/**
* Batch information callback for regenerating the sitemap files.
*/
function xmlsitemap_regenerate_batch(array $smids = array()) {
if (empty($smids)) {
$smids = db_query("SELECT smid FROM {xmlsitemap_sitemap}")->fetchCol();
}
//$t = get_t();
$batch = array(
'operations' => array(),
//'error_message' => $t('An error has occurred.'),
'finished' => 'xmlsitemap_regenerate_batch_finished',
'title' => t('Regenerating Sitemap'),
'file' => drupal_get_path('module', 'xmlsitemap') . '/xmlsitemap.generate.inc',
);
// Generate all the sitemap pages for each context.
$batch['operations'][] = array('_xmlsitemap_regenerate_before', array());
foreach ($smids as $smid) {
$batch['operations'][] = array('xmlsitemap_regenerate_batch_generate', array($smid));
$batch['operations'][] = array('xmlsitemap_regenerate_batch_generate_index', array($smid));
}
$batch['operations'][] = array('_xmlsitemap_regenerate_after', array());
return $batch;
}
/**
* Batch callback; generate all pages of a sitemap.
*/
function xmlsitemap_regenerate_batch_generate($smid, array &$context) {
if (!isset($context['sandbox']['sitemap'])) {
$context['sandbox']['sitemap'] = xmlsitemap_sitemap_load($smid);
$context['sandbox']['sitemap']['chunks'] = 1;
$context['sandbox']['sitemap']['links'] = 0;
$context['sandbox']['max'] = XMLSITEMAP_MAX_SITEMAP_LINKS;
}
$sitemap = &$context['sandbox']['sitemap'];
$links = xmlsitemap_generate($sitemap, $sitemap['chunks']);
$context['message'] = t('Now generating sitemap page @chunk.', array('@chunk' => $sitemap['chunks']));
if ($links) {
$sitemap['links'] += $links;
$sitemap['chunks']++;
}
else {
// Account for the 'extra' chunk here.
// @todo Delete the extra file?
$sitemap['chunks']--;
// Save the updated chunks and links values.
$context['sandbox']['max'] = $sitemap['chunks'];
$sitemap['updated'] = REQUEST_TIME;
xmlsitemap_sitemap_save($sitemap);
}
if ($sitemap['chunks'] != $context['sandbox']['max']) {
$context['finished'] = $sitemap['chunks'] / $context['sandbox']['max'];
}
}
/**
* Batch callback; generate the index page of a sitemap.
*/
function xmlsitemap_regenerate_batch_generate_index($smid, array &$context) {
$sitemap = xmlsitemap_sitemap_load($smid);
if ($sitemap['chunks'] > 1) {
xmlsitemap_generate($sitemap, 'index');
$context['message'] = t('Now generating sitemap index for @count pages.', array('@count' => $sitemap['chunks']));
}
}
/**
* Batch information callback.
* Batch callback; sitemap regeneration finished.
*/
function xmlsitemap_rebuild_batch(array $entities, array $callbacks, $save_custom = FALSE) {
function xmlsitemap_regenerate_batch_finished($success, $results, $operations) {
if ($success) {
// Reset the rebuild flag since it was successful.
variable_set('xmlsitemap_regenerate_needed', FALSE);
//drupal_set_message(t('The sitemaps were regenerated.'));
}
else {
drupal_set_message(t('The sitemaps was not successfully regenerated.'), 'error');
}
}
/**
* Batch information callback for rebuilding the sitemap data.
*/
function xmlsitemap_rebuild_batch(array $entities, $save_custom = FALSE) {
$batch = array(
'operations' => array(),
'finished' => 'xmlsitemap_rebuild_batch_finished',
......@@ -398,25 +456,34 @@ function xmlsitemap_rebuild_batch(array $entities, array $callbacks, $save_custo
'file' => drupal_get_path('module', 'xmlsitemap') . '/xmlsitemap.generate.inc',
);
$batch['operations'][] = array('xmlsitemap_rebuild_batch_prerebuild', array());
// Purge any links first.
$batch['operations'][] = array('xmlsitemap_rebuild_batch_clear', array($entities, (bool) $save_custom));
// Fetch all the sitemap links and save them to the {xmlsitemap} table.
foreach ($entities as $entity) {
$batch['operations'][] = array($callbacks[$entity], array($entity));
$info = xmlsitemap_get_link_info($entity);
$batch['operations'][] = array($info['xmlsitemap']['rebuild callback'], array($entity));
}
// Generate all the sitemap pages for each context.
$batch['operations'][] = array('_xmlsitemap_regenerate_before', array());
$contexts = xmlsitemap_get_contexts();
foreach ($contexts as $context) {
$batch['operations'][] = array('xmlsitemap_rebuild_batch_generate', array($context));
}
$batch['operations'][] = array('_xmlsitemap_regenerate_after', array());
// Add the regeneration batch.
$regenerate_batch = xmlsitemap_regenerate_batch();
$batch['operations'] = array_merge($batch['operations'], $regenerate_batch['operations']);
return $batch;
}
/**
* Batch callback; perform operations before rebuilding the sitemap data.
*/
function xmlsitemap_rebuild_batch_prerebuild() {
// Set the rebuild flag in case something fails during the rebuild.
variable_set('xmlsitemap_rebuild_needed', TRUE);
timer_start('xmlsitemap_rebuild');
}
/**
* Batch callback; clear sitemap links for entites.
*/
......@@ -471,7 +538,8 @@ function xmlsitemap_rebuild_batch_fetch($entity, &$context) {
// PostgreSQL cannot have the ORDERED BY in the count query.
$query->orderBy($info['entity keys']['id']);
$query->range(0, variable_get('xmlsitemap_batch_limit', 100));
$limit = 20; //variable_get('xmlsitemap_batch_limit', 100)
$query->range(0, $limit);
$ids = $query->execute()->fetchCol();
$info['xmlsitemap']['process callback']($ids);
......@@ -484,29 +552,6 @@ function xmlsitemap_rebuild_batch_fetch($entity, &$context) {
}
}
/**
* Batch callback; generate the sitemap chunks for a context.
*/
function xmlsitemap_rebuild_batch_generate(array $sitemap_context, array &$context) {
if (!isset($context['sandbox']['progress'])) {
$context['sandbox']['progress'] = 1;
$context['sandbox']['max'] = xmlsitemap_get_chunk_count(TRUE);
if ($context['sandbox']['max'] > 1) {
xmlsitemap_generate('index', $sitemap_context);
}