nodequeue_generate.drush.inc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * @file
  4. * Nodequeue generate drush integration.
  5. */
  6. /**
  7. * Implementation of hook_drush_command().
  8. *
  9. * @See drush_parse_command() for a list of recognized keys.
  10. *
  11. * @return
  12. * An associative array describing your command(s).
  13. */
  14. function nodequeue_generate_drush_command() {
  15. $items = array();
  16. $items['nodequeue-generate'] = array(
  17. 'description' => "Re-populates specified nodequeues with random nodes.",
  18. 'drupal dependencies' => array('nodequeue_generate'),
  19. 'arguments' => array(
  20. 'queue' => 'Machine name of queue to be re-populated.',
  21. ),
  22. 'aliases' => array('nqg'),
  23. );
  24. $items['nodequeue-generate-all'] = array(
  25. 'description' => "Re-populates nodequeues with random nodes.",
  26. 'drupal dependencies' => array('nodequeue_generate'),
  27. 'aliases' => array('nqga'),
  28. );
  29. $items['nodequeue-generate-rehash'] = array(
  30. 'description' => "Rehashes smartqueue subqueues for taxonomy smartqueue.",
  31. 'drupal dependencies' => array('nodequeue_generate', 'smartqueue'),
  32. 'aliases' => array('nqgr'),
  33. );
  34. return $items;
  35. }
  36. /**
  37. * Implementation of hook_drush_help().
  38. */
  39. function nodequeue_generate_drush_help($section) {
  40. switch ($section) {
  41. case 'drush:nodequeue-generate':
  42. return dt("Re-populates specified nodequeues with random nodes.");
  43. case 'drush:nodequeue-generate-all':
  44. return dt("Re-populates all nodequeues with random nodes.");
  45. case 'drush:nodequeue-generate-rehash':
  46. return dt("Rehashes smartqueue subqueues for taxonomy smartqueue.");
  47. }
  48. }
  49. /**
  50. * Re-populates specified nodequeues with random nodes.
  51. */
  52. function drush_nodequeue_generate() {
  53. $args = func_get_args();
  54. // At least one queue must be specified.
  55. if (count($args) < 1) {
  56. drush_set_error('error', dt('At least one queue must be specified.'));
  57. }
  58. // Get qids from machine names.
  59. $qids = array();
  60. foreach ($args as $queue) {
  61. $qid = db_select('nodequeue_queue', 'nq')
  62. ->fields('nq', array('qid'))
  63. ->condition('name', $queue)
  64. ->execute()
  65. ->fetchField();
  66. if ($qid) {
  67. $qids[] = $qid;
  68. }
  69. else {
  70. drush_set_error('error', dt('Queue @queue was not found.', array('@queue' => $queue)));
  71. }
  72. }
  73. nodequeue_generate_rehash();
  74. nodequeue_generate_repopulate_queues($qids);
  75. }
  76. /**
  77. * Re-populates all nodequeues with random nodes.
  78. */
  79. function drush_nodequeue_generate_all() {
  80. $qids = db_select('nodequeue_queue', 'nq')
  81. ->fields('nq', array('qid'))
  82. ->execute()
  83. ->fetchAll(PDO::FETCH_COLUMN, 'qid');
  84. nodequeue_generate_rehash();
  85. nodequeue_generate_repopulate_queues($qids);
  86. }
  87. /**
  88. * Rehashes smartqueue subqueues for taxonomy smartqueue.
  89. */
  90. function drush_nodequeue_generate_rehash() {
  91. nodequeue_generate_rehash();
  92. }