search_api_sorts.install 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * Implements hook_schema().
  4. */
  5. function search_api_sorts_schema() {
  6. $schema['search_api_sort'] = array(
  7. 'description' => 'Stores all activated or configured sorts of a site.',
  8. 'fields' => array(
  9. 'id' => array(
  10. 'description' => 'The primary identifier for a sort.',
  11. 'type' => 'serial',
  12. 'unsigned' => TRUE,
  13. 'not null' => TRUE,
  14. ),
  15. 'identifier' => array(
  16. 'description' => 'The identifier for this sort.',
  17. 'type' => 'varchar',
  18. 'length' => 255,// This is ugly, but we can't be sure how long a field name might get.
  19. 'not null' => TRUE,
  20. ),
  21. 'index_id' => array(
  22. 'description' => 'The {search_api_index}.machine_name this sort belongs to.',
  23. 'type' => 'varchar',
  24. 'length' => 50,
  25. 'not null' => TRUE,
  26. ),
  27. 'field' => array(
  28. 'description' => 'The index field this sort belongs to.',
  29. 'type' => 'varchar',
  30. 'length' => 255,// This is ugly, but we can't be sure how long a field name might get.
  31. 'not null' => TRUE,
  32. ),
  33. 'name' => array(
  34. 'description' => 'The human-readable name to be displayed for this sort.',
  35. 'type' => 'varchar',
  36. 'length' => 80,
  37. 'not null' => TRUE,
  38. ),
  39. 'enabled' => array(
  40. 'description' => 'A flag indicating whether the sort is enabled.',
  41. 'type' => 'int',
  42. 'size' => 'tiny',
  43. 'not null' => TRUE,
  44. 'default' => 1,
  45. ),
  46. 'default_sort' => array(
  47. 'description' => 'A flag indicating whether the sort is the default sort for the index.',
  48. 'type' => 'int',
  49. 'size' => 'tiny',
  50. 'not null' => TRUE,
  51. 'default' => 0,
  52. ),
  53. 'default_sort_no_terms' => array(
  54. 'description' => 'A flag indicating whether the sort is the default sort for the index when there are no search terms present.',
  55. 'type' => 'int',
  56. 'size' => 'tiny',
  57. 'not null' => TRUE,
  58. 'default' => 0,
  59. ),
  60. 'default_order' => array(
  61. 'description' => 'The default order for this field.',
  62. 'type' => 'varchar',
  63. 'length' => 4,
  64. 'not null' => TRUE,
  65. 'default' => 'desc',
  66. ),
  67. 'weight' => array(
  68. 'description' => 'A weight field determining the sort order of the sorts in the block.',
  69. 'type' => 'int',
  70. 'size' => 'tiny',
  71. 'not null' => TRUE,
  72. 'default' => 0,
  73. ),
  74. ) + entity_exportable_schema_fields(),
  75. 'indexes' => array(
  76. 'field' => array('index_id', array('field', 50)),
  77. 'enabled' => array('enabled'),
  78. ),
  79. 'primary key' => array('id'),
  80. );
  81. return $schema;
  82. }
  83. /**
  84. * Implements hook_uninstall().
  85. */
  86. function search_api_sorts_uninstall() {
  87. variable_del('search_api_sorts_default_sort');
  88. variable_del('search_api_sorts_default_order');
  89. }
  90. /**
  91. * Add default sort and order columns to the sort table. Removed deprecated variables.
  92. */
  93. function search_api_sorts_update_7201() {
  94. variable_del('search_api_sorts_default_sort');
  95. variable_del('search_api_sorts_default_order');
  96. db_add_field('search_api_sort', 'default_sort', array(
  97. 'description' => 'A flag indicating whether the sort is the default sort for the index.',
  98. 'type' => 'int',
  99. 'size' => 'tiny',
  100. 'not null' => TRUE,
  101. 'default' => 0,
  102. ));
  103. db_add_field('search_api_sort', 'default_order', array(
  104. 'description' => 'The default order for this field.',
  105. 'type' => 'varchar',
  106. 'length' => 4,
  107. 'not null' => TRUE,
  108. 'default' => 'desc'
  109. ));
  110. }
  111. /**
  112. * Add an identifier field consisting of the index and field name
  113. */
  114. function search_api_sorts_update_7202() {
  115. db_add_field('search_api_sort', 'identifier', array(
  116. 'description' => 'The identifier for this sort.',
  117. 'type' => 'varchar',
  118. 'length' => 255,// This is ugly, but we can't be sure how long a field name might get.
  119. 'not null' => TRUE,
  120. 'default' => '',
  121. ));
  122. db_update('search_api_sort')
  123. ->expression('identifier', 'CONCAT(index_id, \'__\', field)')
  124. ->execute();
  125. }
  126. /**
  127. * Add weight property.
  128. */
  129. function search_api_sorts_update_7203() {
  130. db_add_field('search_api_sort', 'weight', array(
  131. 'description' => 'A weight field determining the sort order of the sorts in the block.',
  132. 'type' => 'int',
  133. 'size' => 'tiny',
  134. 'not null' => TRUE,
  135. 'default' => 0,
  136. ));
  137. }
  138. /**
  139. * Add default sort no terms to the sort table.
  140. */
  141. function search_api_sorts_update_7204() {
  142. db_add_field('search_api_sort', 'default_sort_no_terms', array(
  143. 'description' => 'A flag indicating whether the sort is the default sort for the index when there are no search terms present.',
  144. 'type' => 'int',
  145. 'size' => 'tiny',
  146. 'not null' => TRUE,
  147. 'default' => 0,
  148. ));
  149. }