tripal_organism.install 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /**
  3. * @file
  4. * Functions pertaining to the install/uninstall of this module
  5. */
  6. /**
  7. * Implements hook_disable().
  8. * Disable default views when module is disabled
  9. *
  10. * @ingroup tripal_organism
  11. */
  12. function tripal_organism_disable() {
  13. // Disable all default views provided by this module
  14. require_once("tripal_organism.views_default.inc");
  15. $views = tripal_organism_views_default_views();
  16. foreach (array_keys($views) as $view_name) {
  17. tripal_disable_view($view_name,FALSE,array('suppress_error' => TRUE));
  18. }
  19. }
  20. /**
  21. * Implementation of hook_install().
  22. *
  23. * @ingroup tripal_organism
  24. */
  25. function tripal_organism_install() {
  26. // cvs & cvterms
  27. tripal_organism_add_cvs();
  28. tripal_organism_add_cvterms();
  29. // set the default vocabularies
  30. tripal_set_default_cv('organismprop', 'type_id', 'organism_property');
  31. }
  32. /**
  33. * Implementation of hook_schema().
  34. *
  35. * @ingroup tripal_organism
  36. */
  37. function tripal_organism_schema() {
  38. $schema['chado_organism'] = array(
  39. 'fields' => array(
  40. 'vid' => array(
  41. 'type' => 'int',
  42. 'unsigned' => TRUE,
  43. 'not null' => TRUE,
  44. 'default' => 0
  45. ),
  46. 'nid' => array(
  47. 'type' => 'int',
  48. 'unsigned' => TRUE,
  49. 'not null' => TRUE,
  50. 'default' => 0
  51. ),
  52. 'organism_id' => array(
  53. 'type' => 'int',
  54. 'not null' => TRUE,
  55. 'default' => 0
  56. )
  57. ),
  58. 'indexes' => array(
  59. 'organism_id' => array('organism_id')
  60. ),
  61. 'unique keys' => array(
  62. 'nid_vid' => array('nid', 'vid'),
  63. 'vid' => array('vid')
  64. ),
  65. 'primary key' => array('nid'),
  66. );
  67. return $schema;
  68. }
  69. /**
  70. * Implementation of hook_uninstall().
  71. *
  72. * @ingroup tripal_organism
  73. */
  74. function tripal_organism_uninstall() {
  75. }
  76. /**
  77. * Implementation of hook_requirements().
  78. *
  79. * @ingroup tripal_organism
  80. */
  81. function tripal_organism_requirements($phase) {
  82. $requirements = array();
  83. if ($phase == 'install') {
  84. // make sure chado is installed
  85. if (!$GLOBALS["chado_is_installed"]) {
  86. $requirements ['tripal_organism'] = array(
  87. 'title' => "tripal_organism",
  88. 'value' => "ERROR: Chado must be installed before this module can be enabled",
  89. 'severity' => REQUIREMENT_ERROR,
  90. );
  91. }
  92. }
  93. return $requirements;
  94. }
  95. /**
  96. * Add cvterms related to organisms
  97. *
  98. * @ingroup tripal_organism
  99. */
  100. function tripal_organism_add_cvs() {
  101. tripal_insert_cv(
  102. 'organism_property',
  103. 'Contains properties for organisms'
  104. );
  105. }
  106. /**
  107. * Add cvterms pertaining to organisms
  108. *
  109. * @ingroup tripal_organism
  110. */
  111. function tripal_organism_add_cvterms() {
  112. }
  113. /**
  114. * This is the required update for tripal_organism when upgrading from Drupal core API 6.x.
  115. *
  116. */
  117. function tripal_organism_update_7200() {
  118. // add the new organism_property vocabulary
  119. // We cannot use the Tripal API calls in the 7000 update
  120. // because during upgrade the tripal_core should also be disabled
  121. try {
  122. $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'organism_property'")->fetchField();
  123. if (!$cv_id) {
  124. $sql = "INSERT INTO chado.cv (name, definition) VALUES (
  125. 'organism_property',
  126. 'Contains properties for organisms.')
  127. ";
  128. db_query($sql);
  129. }
  130. // add in the default vocabulary
  131. db_insert('tripal_cv_defaults')
  132. ->fields(array(
  133. 'table_name' => 'organismprop',
  134. 'field_name' => 'type_id',
  135. 'cv_id' => $cv_id
  136. ))
  137. ->execute();
  138. }
  139. catch (\PDOException $e) {
  140. $error = $e->getMessage();
  141. throw new DrupalUpdateException('Failed to add organism_property vocabulary: '. $error);
  142. }
  143. // During the upgrade from D6 to D7 the vocabulary terms assigned to organisms were
  144. // copied to the field_data_taxonomyextra table rather than to the correct
  145. // field_data_taxonomy_vocabulary_[vid] table. We'll move them.
  146. $vid = db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE name = 'Organism'")->fetchField();
  147. if ($vid) {
  148. try {
  149. // first move from the field_data_taxonomyextra table
  150. $sql = "
  151. INSERT INTO {field_data_taxonomy_vocabulary_$vid}
  152. (entity_type, bundle, deleted, entity_id, revision_id, language, delta, taxonomy_vocabulary_" . $vid. "_tid)
  153. (SELECT entity_type, bundle, deleted, entity_id, revision_id, language, delta, taxonomyextra_tid
  154. FROM field_data_taxonomyextra
  155. WHERE bundle = 'chado_feature')
  156. ";
  157. db_query($sql);
  158. $sql = "DELETE FROM field_data_taxonomyextra WHERE bundle = 'chado_organism'";
  159. db_query($sql);
  160. // next move from the field_revision_taxonomyextra table
  161. $sql = "
  162. INSERT INTO {field_revision_taxonomy_vocabulary_$vid}
  163. (entity_type, bundle, deleted, entity_id, revision_id, language, delta, taxonomy_vocabulary_" . $vid. "_tid)
  164. (SELECT entity_type, bundle, deleted, entity_id, revision_id, language, delta, taxonomyextra_tid
  165. FROM field_revision_taxonomyextra
  166. WHERE bundle = 'chado_feature')
  167. ";
  168. db_query($sql);
  169. $sql = "DELETE FROM field_revision_taxonomyextra WHERE bundle = 'chado_organism'";
  170. db_query($sql);
  171. }
  172. catch (\PDOException $e) {
  173. $error = $e->getMessage();
  174. throw new DrupalUpdateException('Could not move organism taxonomy terms: '. $error);
  175. }
  176. }
  177. }
  178. /**
  179. * Implementation of hook_update_dependencies(). It specifies a list of
  180. * other modules whose updates must be run prior to this one.
  181. */
  182. function tripal_organism_update_dependencies() {
  183. $dependencies = array();
  184. // the tripal_cv update 7200 must run prior to update 7200 of this module
  185. $dependencies['tripal_organism'][7200] = array(
  186. 'tripal_cv' => 7200
  187. );
  188. return $dependencies;
  189. }