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

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'),
......
This diff is collapsed.
......@@ -27,6 +27,21 @@ define('XMLSITEMAP_FREQUENCY_DAILY', 86400); // 60 * 60 * 24
define('XMLSITEMAP_FREQUENCY_HOURLY', 3600); // 60 * 60
define('XMLSITEMAP_FREQUENCY_ALWAYS', 60);
/**
* Short lastmod timestamp format.
*/
define('XMLSITEMAP_LASTMOD_SHORT', 'Y-m-d');
/**
* Medium lastmod timestamp format.
*/
define('XMLSITEMAP_LASTMOD_MEDIUM', 'Y-m-d\TH:i\Z');
/**
* Long lastmod timestamp format.
*/
define('XMLSITEMAP_LASTMOD_LONG', 'c');
/**
* Implements hook_hook_info().
*/
......@@ -254,8 +269,8 @@ function xmlsitemap_cron() {
}
// Regenerate the sitemap XML files.
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.generate');
xmlsitemap_regenerate();
module_load_include('generate.inc', 'xmlsitemap');
xmlsitemap_run_progressive_batch('xmlsitemap_regenerate_batch');
}
/**
......@@ -639,26 +654,26 @@ function xmlsitemap_variables() {
return array(
'xmlsitemap_rebuild_needed' => FALSE,
'xmlsitemap_regenerate_needed' => FALSE,
'xmlsitemap_generated_last' => 0,
'xmlsitemap_minimum_lifetime' => 0,
'xmlsitemap_xsl' => TRUE,
'xmlsitemap_languages' => array(language_default('language')),
'xmlsitemap_generated_last' => 0,
'xmlsitemap_xsl' => 1,
'xmlsitemap_prefetch_aliases' => 1,
'xmlsitemap_chunk_size' => 'auto',
'xmlsitemap_batch_limit' => 100,
'xmlsitemap_path' => 'xmlsitemap',
'xmlsitemap_base_url' => $GLOBALS['base_url'],
'xmlsitemap_developer_mode' => FALSE,
'xmlsitemap_developer_mode' => 0,
'xmlsitemap_frontpage_priority' => 1.0,
'xmlsitemap_frontpage_changefreq' => XMLSITEMAP_FREQUENCY_DAILY,
'xmlsitemap_max_chunks' => 0,
'xmlsitemap_max_filesize' => 0,
'xmlsitemap_lastmod_format' => 'Y-m-d\TH:i\Z',
'xmlsitemap_prefetch_aliases' => TRUE,
'xmlsitemap_lastmod_format' => XMLSITEMAP_LASTMOD_MEDIUM,
// Removed variables are set to NULL so they can still be deleted.
'xmlsitemap_gz' => FALSE,
'xmlsitemap_regenerate_last' => NULL,
'xmlsitemap_custom_links' => NULL,
'xmlsitemap_priority_default' => NULL,
'xmlsitemap_languages' => NULL,
);
}
......@@ -1112,3 +1127,23 @@ function xmlsitemap_context_check(array $context) {
return array();
}
}
/**
* Run a progressive batch operation.
*/
function xmlsitemap_run_progressive_batch() {
$args = func_get_args();
$batch_callback = array_shift();
// Build the batch array.
$batch = call_user_func_array($batch_callback, $args);
batch_set($batch);
// 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;
// Run the batch process.
batch_process();
}
......@@ -65,11 +65,18 @@ function xmlsitemap_xmlsitemap_links() {
function xmlsitemap_xmlsitemap_sitemap_operations() {
$operations['update'] = array(
'label' => t('Update cached files'),
'action past' => t('Updated'),
'callback' => 'xmlsitemap_sitemap_multiple_update',
);
return $operations;
}
function xmlsitemap_sitemap_multiple_update(array $smids) {
module_load_include('generate.inc', 'xmlsitemap');
$batch = xmlsitemap_regenerate_batch($smids);
batch_set($batch);
}
/**
* Implements hook_xmlsitemap_context_url_options().
*/
......
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