tripal_core.install 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /**
  3. * @file
  4. * Contains functions used to install/uninstall tripal_core.
  5. */
  6. /**
  7. * Implementation of hook_install().
  8. *
  9. * @ingroup tripal_legacy_core
  10. */
  11. function tripal_core_install() {
  12. }
  13. /**
  14. * Implementation of hook_schema().
  15. *
  16. * @ingroup tripal_legacy_core
  17. */
  18. function tripal_core_schema() {
  19. // Get the schemas defined by this install file.
  20. $schema = tripal_core_get_schemas();
  21. // if this module is already installed and enabled, then we want to provide
  22. // the schemas for all of the custom tables. This will allow Views to
  23. // see the schemas. We check if the module is installed because during
  24. // installation we don't want to make these custom tables available as we
  25. // don't want them created in the Drupal database. The custom tables go in
  26. // the Chado database.
  27. if (db_table_exists('tripal_custom_tables')) {
  28. $sql = 'SELECT * FROM {tripal_custom_tables}';
  29. $results = db_query($sql);
  30. foreach ($results as $custom) {
  31. $schema[$custom->table_name] = unserialize($custom->schema);
  32. }
  33. }
  34. return $schema;
  35. }
  36. /**
  37. * Implementation of hook_uninstall().
  38. *
  39. * @ingroup tripal_legacy_core
  40. */
  41. function tripal_core_uninstall() {
  42. // drop the foreign key between tripal_custom_tables and tripal_mviews
  43. // so that Drupal can then drop the tables
  44. // db_query('
  45. // ALTER TABLE {tripal_custom_tables}
  46. // DROP CONSTRAINT tripal_custom_tables_fk1 CASCADE
  47. // ');
  48. }
  49. /**
  50. * This function simply defines all tables needed for the module to work
  51. * correctly. By putting the table definitions in a separate function we
  52. * can easily provide the entire list for hook_install or individual
  53. * tables for an update.
  54. *
  55. * @ingroup tripal_legacy_core
  56. */
  57. function tripal_core_get_schemas() {
  58. $schema = array();
  59. // Get all the various schema parts and join them together
  60. $temp = tripal_core_get_tripal_toc_schema();
  61. foreach ($temp as $table => $arr) {
  62. $schema[$table] = $arr;
  63. }
  64. $temp = tripal_core_get_tripal_vars_schema();
  65. foreach ($temp as $table => $arr) {
  66. $schema[$table] = $arr;
  67. }
  68. return $schema;
  69. }
  70. /**
  71. *
  72. */
  73. function tripal_core_get_tripal_toc_schema() {
  74. $schema = array();
  75. $schema['tripal_toc'] = array(
  76. 'fields' => array(
  77. 'toc_item_id' => array(
  78. 'type' => 'serial',
  79. 'unsigned' => TRUE,
  80. 'not null' => TRUE
  81. ),
  82. 'node_type' => array(
  83. 'type' => 'varchar',
  84. 'length' => 32,
  85. 'not null' => TRUE
  86. ),
  87. 'key' => array(
  88. 'type' => 'varchar',
  89. 'length' => 255,
  90. 'not null' => TRUE,
  91. ),
  92. 'title' => array(
  93. 'type' => 'varchar',
  94. 'length' => 255,
  95. 'not null' => FALSE
  96. ),
  97. 'weight' => array(
  98. 'type' => 'int',
  99. 'not null' => FALSE
  100. ),
  101. 'hide' => array(
  102. 'type' => 'int',
  103. 'size' => 'tiny',
  104. 'not null' => FALSE,
  105. 'default' => 0,
  106. ),
  107. 'nid' => array(
  108. 'type' => 'int',
  109. 'not null' => FALSE,
  110. )
  111. ),
  112. 'indexes' => array(
  113. 'tripal_toc_idx1' => array('node_type', 'key'),
  114. 'tripal_toc_idx2' => array('node_type', 'key', 'nid'),
  115. ),
  116. 'unique keys' => array(
  117. 'tripal_toc_uq1' => array('node_type', 'key', 'nid'),
  118. ),
  119. 'primary key' => array('toc_item_id'),
  120. );
  121. return $schema;
  122. }
  123. /**
  124. *
  125. */
  126. function tripal_core_get_tripal_vars_schema() {
  127. $schema = array();
  128. $schema['tripal_node_variables'] = array(
  129. 'description' => 'This table is used for storing any type of variable such as ' .
  130. 'a property or setting that should be associated with a Tripal managed Drupal node. This table is '.
  131. 'meant to store non-biological information only. All biological data should be housed ' .
  132. 'in the Chado tables. Be aware that any data stored here will not be made visible ' .
  133. 'through services such as Tripal Web Services and therefore can be a good place to ' .
  134. 'hide application specific settings.',
  135. 'fields' => array (
  136. 'node_variable_id' => array (
  137. 'type' => 'serial',
  138. 'not null' => TRUE,
  139. ),
  140. 'nid' => array (
  141. 'type' => 'int',
  142. 'not null' => TRUE,
  143. ),
  144. 'variable_id' => array (
  145. 'type' => 'int',
  146. 'not null' => TRUE,
  147. ),
  148. 'value' => array (
  149. 'type' => 'text',
  150. 'not null' => FALSE,
  151. ),
  152. 'rank' => array (
  153. 'type' => 'int',
  154. 'not null' => TRUE,
  155. 'default' => 0,
  156. ),
  157. ),
  158. 'primary key' => array (
  159. 0 => 'node_variable_id',
  160. ),
  161. 'unique keys' => array (
  162. 'tripal_node_variables_c1' => array (
  163. 0 => 'nid',
  164. 1 => 'variable_id',
  165. 2 => 'rank',
  166. ),
  167. ),
  168. 'indexes' => array (
  169. 'tripal_node_variables_idx1' => array (
  170. 0 => 'variable_id',
  171. ),
  172. ),
  173. 'foreign keys' => array (
  174. 'tripal_variables' => array (
  175. 'table' => 'tripal_variables',
  176. 'columns' => array (
  177. 'variable_id' => 'variable_id',
  178. ),
  179. ),
  180. ),
  181. );
  182. return $schema;
  183. }