qbf.install 3.4 KB

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