xmlsitemap.drush.inc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * @file
  4. * Drush integration functions for the xmlsitemap module.
  5. *
  6. * @ingroup xmlsitemap
  7. */
  8. /**
  9. * Implements hook_drush_command().
  10. */
  11. function xmlsitemap_drush_command() {
  12. $items['xmlsitemap-regenerate'] = array(
  13. 'description' => 'Regenerate the XML sitemap files.',
  14. 'callback' => 'drush_xmlsitemap_regenerate',
  15. 'drupal dependencies' => array('xmlsitemap'),
  16. );
  17. $items['xmlsitemap-rebuild'] = array(
  18. 'description' => 'Dump and re-process all possible XML sitemap data, and then regenerate the files.',
  19. 'callback' => 'drush_xmlsitemap_rebuild',
  20. 'drupal dependencies' => array('xmlsitemap'),
  21. );
  22. $items['xmlsitemap-index'] = array(
  23. 'description' => 'Process un-indexed XML sitemap links.',
  24. 'callback' => 'drush_xmlsitemap_index',
  25. 'drupal dependencies' => array('xmlsitemap'),
  26. 'options' => array(
  27. '--limit' => 'The limit of links of each type to process. Default value: ' . variable_get('xmlsitemap_batch_limit', 100),
  28. ),
  29. );
  30. return $items;
  31. }
  32. /**
  33. * Regenerate the sitemap files from existing data.
  34. */
  35. function drush_xmlsitemap_regenerate() {
  36. module_load_include('generate.inc', 'xmlsitemap');
  37. // Run the batch process.
  38. xmlsitemap_run_unprogressive_batch('xmlsitemap_regenerate_batch');
  39. $vars = array(
  40. '@timer' => timer_read('xmlsitemap_regenerate'),
  41. '@memory-peak' => format_size(memory_get_peak_usage(TRUE)),
  42. );
  43. drush_print(dt('XML sitemap files regenerated in @timer ms. Peak memory usage: @memory-peak.', $vars));
  44. }
  45. /**
  46. * Dump and rebuild all the sitemap data, then regenerate the files.
  47. */
  48. function drush_xmlsitemap_rebuild() {
  49. module_load_include('generate.inc', 'xmlsitemap');
  50. // Build a list of rebuildable link types.
  51. $rebuild_types = xmlsitemap_get_rebuildable_link_types();
  52. // Run the batch process.
  53. xmlsitemap_run_unprogressive_batch('xmlsitemap_rebuild_batch', $rebuild_types, TRUE);
  54. $vars = array(
  55. '@timer' => timer_read('xmlsitemap_rebuild'),
  56. '@memory-peak' => format_size(memory_get_peak_usage(TRUE)),
  57. );
  58. drush_print(dt('XML sitemap files rebuilt in @timer ms. Peak memory usage: @memory-peak.', $vars));
  59. }
  60. /**
  61. * Process un-indexed XML sitemap links.
  62. */
  63. function drush_xmlsitemap_index() {
  64. $limit = (int) drush_get_option('limit', variable_get('xmlsitemap_batch_limit', 100));
  65. $count_before = db_query("SELECT COUNT(id) FROM {xmlsitemap}")->fetchField();
  66. module_invoke_all('xmlsitemap_index_links', $limit);
  67. $count_after = db_query("SELECT COUNT(id) FROM {xmlsitemap}")->fetchField();
  68. if ($count_after == $count_before) {
  69. drush_print(dt('No new XML sitemap links to index.'));
  70. }
  71. else {
  72. drush_print(dt('Indexed @count new XML sitemap links.', array('@count' => $count_after - $count_before)));
  73. }
  74. }