tripal_organism.install 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. // Make sure we have the full API loaded this will help during a
  119. // site upgrade when the tripal_core module is disabled.
  120. module_load_include('module', 'tripal_core', 'tripal_core');
  121. tripal_core_import_api();
  122. module_load_include('inc', 'tripal_cv', 'api/tripal_cv.api');
  123. // Add the new organism_property vocabulary
  124. // We cannot use the Tripal API calls in the 7000 update
  125. // because during upgrade the tripal_core should also be disabled
  126. try {
  127. tripal_insert_cv(
  128. 'organism_property',
  129. 'Contains properties for organisms'
  130. );
  131. tripal_set_default_cv('organismprop', 'type_id', 'organism_property');
  132. }
  133. catch (\PDOException $e) {
  134. $error = $e->getMessage();
  135. throw new DrupalUpdateException('Failed to add organism_property vocabulary: '. $error);
  136. }
  137. // During the upgrade from D6 to D7 the vocabulary terms assigned to organisms were
  138. // copied to the field_data_taxonomyextra table rather than to the correct
  139. // field_data_taxonomy_vocabulary_[vid] table. We'll move them.
  140. $vid = db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE name = 'Organism'")->fetchField();
  141. if ($vid) {
  142. try {
  143. if (db_table_exists('field_data_taxonomyextra')) {
  144. // first move from the field_data_taxonomyextra table
  145. $sql = "
  146. INSERT INTO {field_data_taxonomy_vocabulary_$vid}
  147. (entity_type, bundle, deleted, entity_id, revision_id, language, delta, taxonomy_vocabulary_" . $vid. "_tid)
  148. (SELECT entity_type, bundle, deleted, entity_id, revision_id, language, delta, taxonomyextra_tid
  149. FROM field_data_taxonomyextra
  150. WHERE bundle = 'chado_feature')
  151. ";
  152. db_query($sql);
  153. $sql = "DELETE FROM field_data_taxonomyextra WHERE bundle = 'chado_organism'";
  154. db_query($sql);
  155. // next move from the field_revision_taxonomyextra table
  156. $sql = "
  157. INSERT INTO {field_revision_taxonomy_vocabulary_$vid}
  158. (entity_type, bundle, deleted, entity_id, revision_id, language, delta, taxonomy_vocabulary_" . $vid. "_tid)
  159. (SELECT entity_type, bundle, deleted, entity_id, revision_id, language, delta, taxonomyextra_tid
  160. FROM field_revision_taxonomyextra
  161. WHERE bundle = 'chado_feature')
  162. ";
  163. db_query($sql);
  164. $sql = "DELETE FROM field_revision_taxonomyextra WHERE bundle = 'chado_organism'";
  165. db_query($sql);
  166. }
  167. }
  168. catch (\PDOException $e) {
  169. $error = $e->getMessage();
  170. throw new DrupalUpdateException('Could not move organism taxonomy terms: '. $error);
  171. }
  172. }
  173. }
  174. /**
  175. * Implementation of hook_update_dependencies().
  176. *
  177. * It specifies a list of other modules whose updates must be run prior to
  178. * this one. It also ensures the the Tripal API is in scope for site
  179. * upgrades when tripal_core is disabled.
  180. */
  181. function tripal_organism_update_dependencies() {
  182. $dependencies = array();
  183. // the tripal_cv update 7200 must run prior to update 7200 of this module
  184. $dependencies['tripal_organism'][7200] = array(
  185. 'tripal_cv' => 7200
  186. );
  187. return $dependencies;
  188. }