xmlsitemap.drush.inc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. // $Id: xmlsitemap.drush.inc,v 1.8 2010/01/24 05:54:40 davereid Exp $
  3. /**
  4. * @file
  5. * Drush integration functions for the xmlsitemap module.
  6. *
  7. * @ingroup xmlsitemap
  8. */
  9. /**
  10. * Implements hook_drush_command().
  11. */
  12. function xmlsitemap_drush_command() {
  13. $items['xmlsitemap-regenerate'] = array(
  14. 'description' => 'Regenerate the XML sitemap files.',
  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. 'drupal dependencies' => array('xmlsitemap'),
  20. );
  21. $items['xmlsitemap-index'] = array(
  22. 'description' => 'Process un-indexed XML sitemap links.',
  23. 'drupal dependencies' => array('xmlsitemap'),
  24. 'options' => array(
  25. '--limit' => 'The limit of links of each type to process. Default value: ' . variable_get('xmlsitemap_batch_limit', 100),
  26. ),
  27. );
  28. return $items;
  29. }
  30. /**
  31. * Regenerate the sitemap files from existing data.
  32. */
  33. function drush_xmlsitemap_regenerate() {
  34. module_load_include('inc', 'xmlsitemap');
  35. xmlsitemap_regenerate();
  36. $vars = array(
  37. '@timer' => timer_read('xmlsitemap_regenerate'),
  38. '@memory-peak' => format_size(memory_get_peak_usage(TRUE)),
  39. );
  40. drush_print(dt('XML sitemap files regenerated in @timer ms. Peak memory usage: @memory-peak.', $vars));
  41. }
  42. /**
  43. * Dump and rebuild all the sitemap data, then regenerate the files.
  44. */
  45. function drush_xmlsitemap_rebuild() {
  46. module_load_include('inc', 'xmlsitemap');
  47. timer_start('xmlsitemap_rebuild');
  48. // Set the rebuild flag incase something fails during the rebuild.
  49. variable_set('xmlsitemap_rebuild_needed', TRUE);
  50. // Build the batch array.
  51. $modules = module_implements('xmlsitemap_link_info');
  52. $batch = xmlsitemap_rebuild_batch($modules, TRUE);
  53. $batch['progressive'] = FALSE;
  54. batch_set($batch);
  55. // We need to manually set the progressive variable again.
  56. // @todo Remove when http://drupal.org/node/638712 is fixed.
  57. $batch =& batch_get();
  58. $batch['progressive'] = FALSE;
  59. // Run the batch process.
  60. batch_process();
  61. $vars = array(
  62. '@timer' => timer_read('xmlsitemap_rebuild'),
  63. '@memory-peak' => format_size(memory_get_peak_usage(TRUE)),
  64. );
  65. drush_print(dt('XML sitemap files rebuilt in @timer ms. Peak memory usage: @memory-peak.', $vars));
  66. }
  67. /**
  68. * Process un-indexed XML sitemap links.
  69. */
  70. function drush_xmlsitemap_index() {
  71. $limit = (int) drush_get_option('limit', variable_get('xmlsitemap_batch_limit', 100));
  72. module_invoke_all('xmlsitemap_index_links', $limit);
  73. }