qbf.install 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. // $Id: qbf.install,v 1.1.4.2 2009-03-17 11:43:04 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_queries'] = 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. 'name' => array
  45. (
  46. 'description' => t('Query name'),
  47. 'type' => 'varchar',
  48. 'length' => 40,
  49. 'not null' => TRUE,
  50. 'default' => '',
  51. ),
  52. 'query' => array
  53. (
  54. 'description' => t('Query array'),
  55. 'type' => 'text',
  56. 'not null' => TRUE,
  57. ),
  58. 'created' => array
  59. (
  60. 'description' => 'Query creation timestamp.',
  61. 'type' => 'int',
  62. 'not null' => TRUE,
  63. 'default' => 0,
  64. ),
  65. 'updated' => array
  66. (
  67. 'description' => 'Query update timestamp',
  68. 'type' => 'int',
  69. 'not null' => TRUE,
  70. 'default' => 0,
  71. ),
  72. ),
  73. 'primary key' => array('qid'),
  74. 'indexes' => array
  75. (
  76. 'query_updated' => array('updated'),
  77. 'query_created' => array('created'),
  78. ),
  79. 'unique keys' => array(),
  80. );
  81. return $schema;
  82. }
  83. /**
  84. * Implement hook_install().
  85. *
  86. * - Install schema
  87. * - Assign initial settings
  88. *
  89. * @ingroup hooks
  90. * @return void
  91. */
  92. function qbf_install()
  93. {
  94. drupal_install_schema('qbf');
  95. // Initialize settings
  96. $ar_const = get_defined_constants();
  97. $ar_const = array_keys($ar_const);
  98. $count = 0;
  99. $init_count = 0;
  100. foreach ($ar_const as $name)
  101. {
  102. if (strpos($name, 'QBF_VAR_') === 0)
  103. {
  104. $count++;
  105. $default = 'QBF_DEF_'. drupal_substr($name, drupal_strlen('QBF_VAR_'));
  106. if (defined($default))
  107. {
  108. variable_set(constant($name), constant($default));
  109. $init_count++;
  110. }
  111. }
  112. }
  113. drupal_set_message(t('Initialized QBF module settings (@initCount/@count parameters). You can <a href="!link">complete setup</a>.',
  114. array
  115. (
  116. '@initCount' => $init_count,
  117. '@count' => $count,
  118. '!link' => url(QBF_PATH_SETTINGS),
  119. )
  120. ));
  121. }
  122. /**
  123. * Implement hook_uninstall().
  124. *
  125. * - Uninstall schema
  126. * - Remove nodes of all the types maintained by the module
  127. * - none
  128. * - Remove module settings
  129. * - none
  130. * - Do NOT remove module schema version from {system}
  131. *
  132. * @ingroup hooks
  133. * @return void
  134. */
  135. function qbf_uninstall()
  136. {
  137. drupal_uninstall_schema('qbf');
  138. // Remove settings
  139. $ar_const = get_defined_constants();
  140. $ar_const = array_keys($ar_const);
  141. foreach ($ar_const as $name)
  142. {
  143. if (strpos($name, 'QBF_VAR_') === 0)
  144. {
  145. variable_del($name);
  146. }
  147. }
  148. drupal_set_message(t('Removed QBF module settings.'));
  149. }
  150. /**
  151. * Implement hook_update_N().
  152. *
  153. * For 5.x, just define a proper initial schema version.
  154. *
  155. * @ingroup hooks
  156. * @return array
  157. */
  158. function qbf_update_5000()
  159. {
  160. return array();
  161. }
  162. /**
  163. * Implement hook_update_N().
  164. *
  165. * No data structure change from 5000 to 6000, but we need a 6xxx schema version.
  166. *
  167. * @ingroup hooks
  168. * @return array
  169. */
  170. function qbf_update_6000()
  171. {
  172. return array();
  173. }