qbf.install 3.5 KB

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