redirect.drush.inc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @file
  4. * Drush integration for the redirect module.
  5. */
  6. /**
  7. * Implementation of hook_drush_command().
  8. */
  9. function redirect_drush_command() {
  10. $items['generate-redirects'] = array(
  11. 'description' => 'Create redirects.',
  12. 'drupal dependencies' => array('devel_generate'),
  13. 'arguments' => array(
  14. 'count' => 'Number of redirects to generate.',
  15. ),
  16. 'options' => array(
  17. 'delete' => 'Delete all redirects before generating new ones.',
  18. ),
  19. );
  20. return $items;
  21. }
  22. /**
  23. * Command callback. Generate a number of redirects.
  24. */
  25. function drush_redirect_generate_redirects($count = NULL) {
  26. if (drush_generate_is_number($count) == FALSE) {
  27. return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', t('Invalid number of redirects.'));
  28. }
  29. module_load_include('inc', 'redirect', 'redirect.generate');
  30. drush_generate_include_devel();
  31. redirect_run_unprogressive_batch('redirect_generate_redirects_batch_info', $count, drush_get_option('delete'));
  32. }
  33. /**
  34. * Perform an unprogressive batch process for CLI.
  35. */
  36. function redirect_run_unprogressive_batch() {
  37. $batch = batch_get();
  38. if (!empty($batch)) {
  39. // If there is already something in the batch, don't run.
  40. return FALSE;
  41. }
  42. $args = func_get_args();
  43. $batch_callback = array_shift($args);
  44. if (!lock_acquire($batch_callback)) {
  45. return FALSE;
  46. }
  47. // Attempt to increase the execution time.
  48. drupal_set_time_limit(240);
  49. // Build the batch array.
  50. $batch = call_user_func_array($batch_callback, $args);
  51. batch_set($batch);
  52. // We need to manually set the progressive variable again.
  53. // @todo Remove when http://drupal.org/node/638712 is fixed.
  54. $batch =& batch_get();
  55. $batch['progressive'] = FALSE;
  56. // Run the batch process.
  57. batch_process();
  58. lock_release($batch_callback);
  59. return TRUE;
  60. }