qbf.install 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * @file
  4. * QBF module - installer
  5. *
  6. * Copyright 2008 Ouest Systèmes Informatiques SARL
  7. *
  8. * Author FG Marand
  9. *
  10. * License GPL2 or later
  11. */
  12. // $Id: qbf.install,v 1.1.2.5 2008-10-13 15:02:32 marand Exp $
  13. require_once(drupal_get_path('module', 'qbf') .'/qbf.module');
  14. /**
  15. * Implement hook_install().
  16. *
  17. * - Create the QBF tables
  18. * - qbf_queries
  19. * - Assign initial settings
  20. * - none
  21. *
  22. * @todo support PGSQL
  23. * @ingroup hooks
  24. * @return void
  25. */
  26. function qbf_install() {
  27. // Initialize settings
  28. $ar_const = get_defined_constants();
  29. $ar_const = array_keys($ar_const);
  30. $count = 0;
  31. $init_count = 0;
  32. foreach ($ar_const as $name) {
  33. if (strpos($name, 'QBF_VAR_') === 0) {
  34. $count++;
  35. $default = 'QBF_DEF_'. drupal_substr($name, drupal_strlen('QBF_VAR_'));
  36. if (defined($default)) {
  37. variable_set(constant($name), constant($default));
  38. $init_count++;
  39. }
  40. }
  41. }
  42. drupal_set_message(t('Initialized QBF module settings (@initCount/@count parameters). You can <a href="!link">complete setup</a>.',
  43. array
  44. (
  45. '@initCount' => $init_count,
  46. '@count' => $count,
  47. '!link' => url(QBF_PATH_SETTINGS),
  48. )));
  49. switch ($GLOBALS['db_type']) {
  50. case 'mysql':
  51. case 'mysqli':
  52. $sq = 'CREATE TABLE {qbf_queries} '
  53. .' ( '
  54. ." `qid` INT(10) NOT NULL DEFAULT '0' COMMENT 'Query ID', "
  55. ." `uid` INT(10) NOT NULL DEFAULT '0' COMMENT 'User ID', "
  56. ." `name` VARCHAR(40) NOT NULL DEFAULT '' COMMENT 'Query name', "
  57. ." `query` TEXT NOT NULL COMMENT 'Query array', "
  58. ." `created` INT(10) NOT NULL DEFAULT '0' COMMENT 'Creation timestamp', "
  59. ." `updated` INT(10) NOT NULL DEFAULT '0' COMMENT 'Update timestamp', "
  60. .' PRIMARY KEY (`qid`) , '
  61. .' KEY `uid` (`uid`), '
  62. .' KEY `updated`(`updated`) '
  63. .' ) '
  64. .'ENGINE = MyISAM '
  65. .'CHARACTER SET = utf8 '
  66. ."COMMENT = 'QBF Query store' ";
  67. db_query($sq);
  68. break;
  69. case pgsql:
  70. default:
  71. drupal_set_message(t('Unsupported database backend for QBF module: @db',
  72. array('@db' => $GLOBALS['db_type'])), 'error');
  73. break;
  74. }
  75. }
  76. /**
  77. * Implement hook_uninstall().
  78. *
  79. * - Drop all the tables maintained by the module
  80. * - qbf_queries
  81. * - Remove nodes of all the types maintained by the module
  82. * - none
  83. * - Remove module settings
  84. * - none
  85. * - Do NOT remove module schema version from {system}
  86. *
  87. * @ingroup hooks
  88. * @return void
  89. */
  90. function qbf_uninstall() {
  91. // Remove settings
  92. $ar_const = get_defined_constants();
  93. $ar_const = array_keys($ar_const);
  94. foreach ($ar_const as $name) {
  95. if (strpos($name, 'QBF_VAR_') === 0) {
  96. variable_del($name);
  97. }
  98. }
  99. drupal_set_message(t('Removed QBF module settings.'));
  100. switch ($GLOBALS['db_type']) {
  101. case 'mysql':
  102. case 'mysqli':
  103. case 'pgsql':
  104. db_query("DROP TABLE {qbf_queries}");
  105. break;
  106. default:
  107. drupal_set_message(t('Unsupported database backend for QBF module: @db',
  108. array('@db' => $GLOBALS['db_type'])), 'error');
  109. break;
  110. }
  111. }
  112. /**
  113. * Implement hook_update_N().
  114. *
  115. * For now, just define a proper initial schema version.
  116. *
  117. * @ingroup hooks
  118. * @return array
  119. */
  120. function qbf_update_5000() {
  121. return array();
  122. }