qbf.install 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. // $Id: qbf.install,v 1.1.4.6 2009-03-22 15:15:19 marand Exp $
  3. /**
  4. * @file
  5. * QBF module - installer
  6. *
  7. * Copyright 2008-2009 Ouest Systèmes Informatiques SARL
  8. *
  9. * Author FG Marand
  10. *
  11. * Licensed under the CeCILL 2.0 and the General Public Licence version 2 or later
  12. */
  13. // We need to import the module to access its named constants
  14. require_once(drupal_get_path('module', 'qbf') .'/qbf.module');
  15. /**
  16. * Implement hook_schema().
  17. *
  18. * @ingroup hooks
  19. *
  20. * @return array
  21. */
  22. function qbf_schema()
  23. {
  24. $schema[QBF_TABLE_NAME] = array
  25. (
  26. 'description' => t('Saved QBF queries.'),
  27. 'fields' => array
  28. (
  29. 'qid' => array
  30. (
  31. 'description' => t('Query ID'),
  32. 'type' => 'serial',
  33. 'unsigned' => TRUE,
  34. 'not null' => TRUE,
  35. ),
  36. 'uid' => array
  37. (
  38. 'description' => t('User ID'),
  39. 'type' => 'int',
  40. 'unsigned' => TRUE,
  41. 'not null' => TRUE,
  42. 'default' => 0,
  43. ),
  44. 'type' => array
  45. (
  46. 'description' => t('Query type'),
  47. 'type' => 'varchar',
  48. 'length' => 20,
  49. 'not null' => TRUE,
  50. 'default' => '',
  51. ),
  52. 'name' => array
  53. (
  54. 'description' => t('Query name'),
  55. 'type' => 'varchar',
  56. 'length' => 60,
  57. 'not null' => TRUE,
  58. 'default' => '',
  59. ),
  60. 'query' => array
  61. (
  62. 'description' => t('Query array'),
  63. 'type' => 'text',
  64. 'not null' => TRUE,
  65. ),
  66. 'created' => array
  67. (
  68. 'description' => 'Query creation timestamp.',
  69. 'type' => 'int',
  70. 'not null' => TRUE,
  71. 'default' => 0,
  72. ),
  73. 'updated' => array
  74. (
  75. 'description' => 'Query update timestamp',
  76. 'type' => 'int',
  77. 'not null' => TRUE,
  78. 'default' => 0,
  79. ),
  80. ),
  81. 'primary key' => array('qid'),
  82. 'indexes' => array
  83. (
  84. 'query_updated' => array('updated'),
  85. 'query_created' => array('created'),
  86. 'query_per_user' => array('uid', 'type'),
  87. ),
  88. 'unique keys' => array(),
  89. );
  90. return $schema;
  91. }
  92. /**
  93. * Implement hook_install().
  94. *
  95. * - Install schema
  96. * - Assign initial settings
  97. *
  98. * @ingroup hooks
  99. * @return void
  100. */
  101. function qbf_install()
  102. {
  103. drupal_install_schema('qbf');
  104. // Initialize settings
  105. $ar_const = get_defined_constants();
  106. $ar_const = array_keys($ar_const);
  107. $count = 0;
  108. $init_count = 0;
  109. foreach ($ar_const as $name)
  110. {
  111. if (strpos($name, 'QBF_VAR_') === 0)
  112. {
  113. $count++;
  114. $default = 'QBF_DEF_'. drupal_substr($name, drupal_strlen('QBF_VAR_'));
  115. if (defined($default))
  116. {
  117. variable_set(constant($name), constant($default));
  118. $init_count++;
  119. }
  120. }
  121. }
  122. drupal_set_message(t('Initialized QBF module settings (@initCount/@count parameters). You can <a href="!link">complete setup</a>.',
  123. array
  124. (
  125. '@initCount' => $init_count,
  126. '@count' => $count,
  127. '!link' => url(QBF_PATH_SETTINGS),
  128. )
  129. ));
  130. }
  131. /**
  132. * Implement hook_uninstall().
  133. *
  134. * - Uninstall schema
  135. * - Remove nodes of all the types maintained by the module
  136. * - none
  137. * - Remove module settings
  138. * - none
  139. * - Do NOT remove module schema version from {system}
  140. *
  141. * @ingroup hooks
  142. * @return void
  143. */
  144. function qbf_uninstall()
  145. {
  146. drupal_uninstall_schema('qbf');
  147. // Remove settings
  148. $ar_const = get_defined_constants();
  149. $ar_const = array_keys($ar_const);
  150. foreach ($ar_const as $name)
  151. {
  152. if (strpos($name, 'QBF_VAR_') === 0)
  153. {
  154. variable_del($name);
  155. }
  156. }
  157. drupal_set_message(t('Removed QBF module settings.'));
  158. }
  159. /**
  160. * Implement hook_update_N().
  161. *
  162. * For 5.x, just define a proper initial schema version.
  163. *
  164. * @ingroup hooks
  165. * @return array
  166. */
  167. function qbf_update_5000()
  168. {
  169. return array();
  170. }
  171. /**
  172. * Implement hook_update_N().
  173. *
  174. * 5000 to 6000
  175. * - new "type" column
  176. * - "name" varchar(40)->varchar(60)
  177. * - "qid" int->serial
  178. *
  179. * @ingroup hooks
  180. * @return array
  181. */
  182. function qbf_update_6000()
  183. {
  184. $ret = array();
  185. variable_set(QBF_VAR_MAX_QUERIES, variable_get('job_max_queries', QBF_DEF_MAX_QUERIES));
  186. variable_set(QBF_VAR_PROFILE_CATEGORY, variable_get('job_profile_category', QBF_DEF_PROFILE_CATEGORY));
  187. variable_set(QBF_VAR_QUERY_MODE, variable_get('job_query_mode', Qbf_Query_Mode::CONTAINS));
  188. drupal_set_message('Migrated QBF-related settings from Job 5.x to QBF 6.x settings');
  189. db_drop_primary_key($ret, QBF_TABLE_NAME);
  190. db_drop_index($ret, QBF_TABLE_NAME, 'query_updated');
  191. db_drop_index($ret, QBF_TABLE_NAME, 'query_created');
  192. db_drop_index($ret, QBF_TABLE_NAME, 'query_per_user');
  193. db_add_field($ret, QBF_TABLE_NAME, 'type', array
  194. (
  195. 'description' => t('Query type'),
  196. 'type' => 'varchar',
  197. 'length' => 20,
  198. 'not null' => TRUE,
  199. 'default' => '',
  200. 'initial' => 'job_form', // Version 5 was bound to the OSInet job search
  201. ));
  202. db_change_field($ret, QBF_TABLE_NAME, 'name', 'name',
  203. array
  204. (
  205. 'type' => 'varchar',
  206. 'length' => 60, // was 40
  207. )
  208. );
  209. db_change_field($ret, QBF_TABLE_NAME, 'qid', 'qid',
  210. array
  211. (
  212. 'type' => 'serial',
  213. ),
  214. array
  215. (
  216. 'primary key' => array('qid'),
  217. 'indexes' => array
  218. (
  219. 'query_updated' => array('updated'),
  220. 'query_created' => array('created'),
  221. 'query_per_user' => array('uid', 'type'),
  222. ),
  223. 'unique keys' => array(),
  224. )
  225. );
  226. return $ret;
  227. }