faq.install 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <?php
  2. /**
  3. * @file
  4. * FAQ module install file.
  5. */
  6. /**
  7. * Define the 'faq_weights' and 'faq_questions' table structures.
  8. *
  9. * @return
  10. * The schema which contains the structure for the faq module's tables.
  11. */
  12. function faq_schema() {
  13. $schema['faq_weights'] = array(
  14. 'description' => 'A table containing the weight of each faq node by category.',
  15. 'fields' => array(
  16. 'tid' => array(
  17. 'type' => 'int',
  18. 'unsigned' => TRUE,
  19. 'not null' => TRUE,
  20. 'default' => 0,
  21. 'description' => 'The primary identifier for a term or category. This will be 0 for non-categorized nodes.',
  22. ),
  23. 'nid' => array(
  24. 'type' => 'int',
  25. 'unsigned' => TRUE,
  26. 'not null' => TRUE,
  27. 'default' => 0,
  28. 'description' => 'The primary identifier for a node.',
  29. ),
  30. 'weight' => array(
  31. 'type' => 'int',
  32. 'size' => 'tiny',
  33. 'not null' => TRUE,
  34. 'default' => 0,
  35. 'description' => 'A number representing the weight of a node. Nodes with lower weight values will appear above those with higher weight values.',
  36. ),
  37. ),
  38. 'primary key' => array('nid', 'tid'),
  39. );
  40. $schema['faq_questions'] = array(
  41. 'description' => 'A table containing the long question text of each faq node revision.',
  42. 'fields' => array(
  43. 'nid' => array(
  44. 'type' => 'int',
  45. 'unsigned' => TRUE,
  46. 'not null' => TRUE,
  47. 'default' => 0,
  48. 'description' => 'The primary identifier for a node.',
  49. ),
  50. 'vid' => array(
  51. 'type' => 'int',
  52. 'unsigned' => TRUE,
  53. 'not null' => TRUE,
  54. 'default' => 0,
  55. 'description' => 'The primary identifier for a node revision.',
  56. ),
  57. 'question' => array(
  58. 'type' => 'text',
  59. 'size' => 'normal',
  60. 'not null' => TRUE,
  61. 'description' => 'The faq short question text.',
  62. ),
  63. 'detailed_question' => array(
  64. 'type' => 'text',
  65. 'size' => 'normal',
  66. 'not null' => FALSE,
  67. 'description' => 'The faq long question text.',
  68. ),
  69. ),
  70. 'primary key' => array('nid', 'vid'),
  71. );
  72. return $schema;
  73. }
  74. /**
  75. * Implements hook_install().
  76. *
  77. * Inserts the FAQ module's schema in the SQL database.
  78. */
  79. function faq_install() {
  80. variable_set('node_type_faq', array('status'));
  81. $t = get_t();
  82. // Ensure the FAQ node type is available.
  83. node_types_rebuild();
  84. $types = node_type_get_types();
  85. node_add_body_field($types['faq']);
  86. // Change the default label on the body field.
  87. $body_instance = field_info_instance('node', 'body', 'faq');
  88. $body_instance['label'] = $t('Answer');
  89. field_update_instance($body_instance);
  90. }
  91. /**
  92. * Implements hook_uninstall().
  93. *
  94. * Remove the variables, nodes and schema corresponding to the FAQ module.
  95. */
  96. function faq_uninstall() {
  97. // Delete the variables we created.
  98. // General settings.
  99. variable_del('faq_title');
  100. variable_del('faq_description');
  101. variable_del('faq_description_format');
  102. // Questions page.
  103. variable_del('faq_display');
  104. variable_del('faq_question_listing');
  105. variable_del('faq_qa_mark');
  106. variable_del('faq_question_label');
  107. variable_del('faq_answer_label');
  108. variable_del('faq_question_length');
  109. variable_del('faq_hide_qa_accordion');
  110. variable_del('faq_show_expand_all');
  111. variable_del('faq_use_teaser');
  112. variable_del('faq_show_node_links');
  113. variable_del('faq_back_to_top');
  114. variable_del('faq_disable_node_links');
  115. variable_del('faq_default_sorting');
  116. // Categories page.
  117. variable_del('faq_use_categories');
  118. variable_del('faq_category_display');
  119. variable_del('faq_category_listing');
  120. variable_del('faq_category_hide_qa_accordion');
  121. variable_del('faq_count');
  122. variable_del('faq_answer_category_name');
  123. variable_del('faq_group_questions_top');
  124. variable_del('faq_hide_child_terms');
  125. variable_del('faq_show_term_page_children');
  126. variable_del('faq_omit_vocabulary');
  127. variable_del('faq_enable_term_links');
  128. // Block settings.
  129. variable_del('faq_block_recent_faq_count');
  130. variable_del('faq_block_random_faq_count');
  131. // Custom breadcrumbs control
  132. variable_del('faq_custom_breadcrumbs');
  133. // Deprecated.
  134. variable_del('faq_more_link');
  135. // Clear the cache tables.
  136. cache_clear_all('*', 'cache', TRUE);
  137. cache_clear_all('*', 'cache_filter', TRUE);
  138. cache_clear_all('*', 'cache_menu', TRUE);
  139. cache_clear_all('*', 'cache_page', TRUE);
  140. }
  141. /**
  142. * Create 'faq_weights' table in order to upgrade from older installations.
  143. */
  144. function faq_update_1() {
  145. $schema['faq_weights'] = array(
  146. 'description' => 'A table containing the weight of each faq node by category.',
  147. 'fields' => array(
  148. 'tid' => array(
  149. 'type' => 'int',
  150. 'unsigned' => TRUE,
  151. 'not null' => TRUE,
  152. 'default' => 0,
  153. ),
  154. 'nid' => array(
  155. 'type' => 'int',
  156. 'unsigned' => TRUE,
  157. 'not null' => TRUE,
  158. 'default' => 0,
  159. ),
  160. 'weight' => array(
  161. 'type' => 'int',
  162. 'size' => 'tiny',
  163. 'not null' => TRUE,
  164. 'default' => 0,
  165. ),
  166. ),
  167. 'primary key' => array('nid', 'tid'),
  168. );
  169. $ret = array();
  170. db_create_table('faq_weights', $schema['faq_weights']);
  171. return t('FAQ weighting table created.');
  172. }
  173. /**
  174. * Create 'faq_questions' table in order to upgrade from older installations.
  175. */
  176. function faq_update_2() {
  177. $schema['faq_questions'] = array(
  178. 'description' => 'A table containing the long question text of each faq node revision.',
  179. 'fields' => array(
  180. 'nid' => array(
  181. 'type' => 'int',
  182. 'unsigned' => TRUE,
  183. 'not null' => TRUE,
  184. 'default' => 0,
  185. 'description' => 'The primary identifier for a node.',
  186. ),
  187. 'vid' => array(
  188. 'type' => 'int',
  189. 'unsigned' => TRUE,
  190. 'not null' => TRUE,
  191. 'default' => 0,
  192. 'description' => 'The primary identifier for a node revision.',
  193. ),
  194. 'question' => array(
  195. 'type' => 'text',
  196. 'size' => 'normal',
  197. 'not null' => TRUE,
  198. 'description' => 'The faq long question text.',
  199. ),
  200. ),
  201. 'primary key' => array('nid', 'vid'),
  202. );
  203. db_create_table('faq_questions', $schema['faq_questions']);
  204. // Pre-populate the questions table from the existing nodes.
  205. $select = db_select('node', 'n');
  206. $select->innerJoin('node_revisions', 'r', 'n.nid = %alias.nid');
  207. $select
  208. ->fields('r', array('nid', 'vid', 'title'))
  209. ->condition('n.type', 'faq');
  210. db_insert('faq_questions')
  211. ->fields(array('nid', 'vid', 'question'))
  212. ->from($select)
  213. ->execute();
  214. return t('FAQ Questions table created.');
  215. }
  216. /**
  217. * Add the 'detailed_question' column to the 'faq_questions' table.
  218. */
  219. function faq_update_6003() {
  220. $ret = array();
  221. db_add_field('faq_questions', 'detailed_question', array('type' => 'text', 'size' => 'normal', 'not null' => TRUE));
  222. db_update('faq_questions')
  223. ->expression('detailed_question', 'question')
  224. ->execute();
  225. return t('Detailed question column added. Existing nodes have been given the same detailed question as current question.');
  226. }
  227. /**
  228. * Make'detailed_question' column nullable.
  229. */
  230. function faq_update_7000() {
  231. db_change_field('faq_questions', 'detailed_question', 'detailed_question', array('type' => 'text', 'size' => 'normal', 'not null' => FALSE));
  232. return t('Detailed question field can now be null.');
  233. }
  234. /**
  235. * Delete obsolete variables.
  236. */
  237. function faq_update_7001() {
  238. variable_del('faq_block_recent_faq_count');
  239. variable_del('faq_block_random_faq_count');
  240. variable_del('faq_enable_term_links');
  241. return t('Deleted obsolete variables.');
  242. }