smartqueue.install 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the smartqueue module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function smartqueue_schema() {
  10. $schema['smartqueue'] = array(
  11. 'description' => 'Table for smartqueues, storing global information for each queue.',
  12. 'fields' => array(
  13. 'qid' => array(
  14. 'description' => 'The primary identifier for a queue.',
  15. 'type' => 'serial',
  16. 'unsigned' => TRUE,
  17. 'not null' => TRUE
  18. ),
  19. 'use_parents' => array(
  20. 'description' => "Whether a queue is to use the terms' parents when displaying the queue selection.",
  21. 'type' => 'int',
  22. 'size' => 'tiny',
  23. 'default' => 0,
  24. ),
  25. ),
  26. 'primary key' => array('qid'),
  27. );
  28. return $schema;
  29. }
  30. /**
  31. * Implements hook_update_N().
  32. *
  33. * Adds the smartqueue table.
  34. */
  35. function smartqueue_update_6003() {
  36. // Don't use hook_schema for database updates per http://drupal.org/node/150220.
  37. // It's possible that users who installed the 2.7 or 2.8 versions of
  38. // smartqueue will already have this table.
  39. if (!db_table_exists('smartqueue')) {
  40. $schema = array(
  41. 'description' => 'Table for smartqueues, storing global information for each queue.',
  42. 'fields' => array(
  43. 'qid' => array(
  44. 'description' => 'The primary identifier for a queue.',
  45. 'type' => 'serial',
  46. 'unsigned' => TRUE,
  47. 'not null' => TRUE
  48. ),
  49. 'use_parents' => array(
  50. 'description' => "Whether a queue is to use the terms' parents when displaying the queue selection.",
  51. 'type' => 'int',
  52. 'size' => 'tiny',
  53. 'default' => 0,
  54. ),
  55. ),
  56. 'primary key' => array('qid'),
  57. );
  58. db_create_table('smartqueue', $schema);
  59. }
  60. $result = db_query('SELECT q.qid FROM {nodequeue_queue} q LEFT JOIN {smartqueue} s ON q.qid = s.qid WHERE s.qid IS NULL');
  61. foreach ($result as $queue) {
  62. db_insert('smartqueue')
  63. ->fields(array('qid' => $queue->qid))
  64. ->execute();
  65. }
  66. }
  67. /**
  68. * Change reference field to rely on field names intead of field-ids.
  69. */
  70. function smartqueue_update_7001() {
  71. $results = db_select('nodequeue_queue', 'nq')
  72. ->fields('nq', array('qid','reference'))
  73. ->condition('owner', 'smartqueue_taxonomy', '=')
  74. ->execute();
  75. foreach ($results as $result) {
  76. $field_names = array();
  77. $field_ids = explode('-', $result->reference);
  78. foreach ($field_ids as $field_id) {
  79. $field = field_info_field_by_id($field_id);
  80. $field_names[] = $field['field_name'];
  81. }
  82. db_update('nodequeue_queue')
  83. ->fields(array('reference' => implode('-', $field_names)))
  84. ->condition('qid', $result->qid)
  85. ->execute();
  86. }
  87. }