tripal_organism.install

  1. 2.x tripal_organism/tripal_organism.install
  2. 3.x legacy/tripal_organism/tripal_organism.install
  3. 1.x tripal_organism/tripal_organism.install

Functions pertaining to the install/uninstall of this module

File

tripal_organism/tripal_organism.install
View source
  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. // Add taxonomic terms.
  32. $obo_id = tripal_insert_obo('Taxonomic Rank', 'http://purl.obolibrary.org/obo/taxrank.obo');
  33. tripal_submit_obo_job(array('obo_id' => $obo_id));
  34. }
  35. /**
  36. * Implementation of hook_schema().
  37. *
  38. * @ingroup tripal_organism
  39. */
  40. function tripal_organism_schema() {
  41. $schema['chado_organism'] = array(
  42. 'fields' => array(
  43. 'vid' => array(
  44. 'type' => 'int',
  45. 'unsigned' => TRUE,
  46. 'not null' => TRUE,
  47. 'default' => 0
  48. ),
  49. 'nid' => array(
  50. 'type' => 'int',
  51. 'unsigned' => TRUE,
  52. 'not null' => TRUE,
  53. 'default' => 0
  54. ),
  55. 'organism_id' => array(
  56. 'type' => 'int',
  57. 'not null' => TRUE,
  58. 'default' => 0
  59. )
  60. ),
  61. 'indexes' => array(
  62. 'organism_id' => array('organism_id')
  63. ),
  64. 'unique keys' => array(
  65. 'nid_vid' => array('nid', 'vid'),
  66. 'vid' => array('vid')
  67. ),
  68. 'primary key' => array('nid'),
  69. );
  70. return $schema;
  71. }
  72. /**
  73. * Implementation of hook_uninstall().
  74. *
  75. * @ingroup tripal_organism
  76. */
  77. function tripal_organism_uninstall() {
  78. }
  79. /**
  80. * Implementation of hook_requirements().
  81. *
  82. * @ingroup tripal_organism
  83. */
  84. function tripal_organism_requirements($phase) {
  85. $requirements = array();
  86. if ($phase == 'install') {
  87. // make sure chado is installed
  88. if (!$GLOBALS["chado_is_installed"]) {
  89. $requirements ['tripal_organism'] = array(
  90. 'title' => "tripal_organism",
  91. 'value' => "ERROR: Chado must be installed before this module can be enabled",
  92. 'severity' => REQUIREMENT_ERROR,
  93. );
  94. }
  95. }
  96. return $requirements;
  97. }
  98. /**
  99. * Add cvterms related to organisms
  100. *
  101. * @ingroup tripal_organism
  102. */
  103. function tripal_organism_add_cvs() {
  104. tripal_insert_cv(
  105. 'organism_property',
  106. 'Contains properties for organisms'
  107. );
  108. }
  109. /**
  110. * Add cvterms pertaining to organisms
  111. *
  112. * @ingroup tripal_organism
  113. */
  114. function tripal_organism_add_cvterms() {
  115. }
  116. /**
  117. * This is the required update for tripal_organism when upgrading from Drupal core API 6.x.
  118. *
  119. */
  120. function tripal_organism_update_7200() {
  121. // Make sure we have the full API loaded this will help during a
  122. // site upgrade when the tripal_core module is disabled.
  123. module_load_include('module', 'tripal_core', 'tripal_core');
  124. tripal_core_import_api();
  125. module_load_include('inc', 'tripal_cv', 'api/tripal_cv.api');
  126. // Add the new organism_property vocabulary
  127. // We cannot use the Tripal API calls in the 7000 update
  128. // because during upgrade the tripal_core should also be disabled
  129. try {
  130. tripal_insert_cv(
  131. 'organism_property',
  132. 'Contains properties for organisms'
  133. );
  134. tripal_set_default_cv('organismprop', 'type_id', 'organism_property');
  135. }
  136. catch (\PDOException $e) {
  137. $error = $e->getMessage();
  138. throw new DrupalUpdateException('Failed to add organism_property vocabulary: '. $error);
  139. }
  140. // During the upgrade from D6 to D7 the vocabulary terms assigned to organisms were
  141. // copied to the field_data_taxonomyextra table rather than to the correct
  142. // field_data_taxonomy_vocabulary_[vid] table. We'll move them.
  143. $vid = db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE name = 'Organism'")->fetchField();
  144. if ($vid) {
  145. try {
  146. if (db_table_exists('field_data_taxonomyextra')) {
  147. // first move from the field_data_taxonomyextra table
  148. $sql = "
  149. INSERT INTO {field_data_taxonomy_vocabulary_$vid}
  150. (entity_type, bundle, deleted, entity_id, revision_id, language, delta, taxonomy_vocabulary_" . $vid. "_tid)
  151. (SELECT entity_type, bundle, deleted, entity_id, revision_id, language, delta, taxonomyextra_tid
  152. FROM field_data_taxonomyextra
  153. WHERE bundle = 'chado_feature')
  154. ";
  155. db_query($sql);
  156. $sql = "DELETE FROM field_data_taxonomyextra WHERE bundle = 'chado_organism'";
  157. db_query($sql);
  158. // next move from the field_revision_taxonomyextra table
  159. $sql = "
  160. INSERT INTO {field_revision_taxonomy_vocabulary_$vid}
  161. (entity_type, bundle, deleted, entity_id, revision_id, language, delta, taxonomy_vocabulary_" . $vid. "_tid)
  162. (SELECT entity_type, bundle, deleted, entity_id, revision_id, language, delta, taxonomyextra_tid
  163. FROM field_revision_taxonomyextra
  164. WHERE bundle = 'chado_feature')
  165. ";
  166. db_query($sql);
  167. $sql = "DELETE FROM field_revision_taxonomyextra WHERE bundle = 'chado_organism'";
  168. db_query($sql);
  169. }
  170. }
  171. catch (\PDOException $e) {
  172. $error = $e->getMessage();
  173. throw new DrupalUpdateException('Could not move organism taxonomy terms: '. $error);
  174. }
  175. }
  176. }
  177. /**
  178. * Adds the taxonomic rank vocabulary.
  179. */
  180. function tripal_organism_update_7201() {
  181. try {
  182. // Make sure we have the full API loaded this will help during a
  183. // site upgrade when the tripal_core module is disabled.
  184. module_load_include('module', 'tripal_core', 'tripal_core');
  185. tripal_core_import_api();
  186. module_load_include('inc', 'tripal_cv', 'api/tripal_cv.api');
  187. // Add taxonomic terms.
  188. $obo_id = tripal_insert_obo('Taxonomic Rank', 'http://purl.obolibrary.org/obo/taxrank.obo');
  189. tripal_submit_obo_job(array('obo_id' => $obo_id));
  190. }
  191. catch (\PDOException $e) {
  192. $error = $e->getMessage();
  193. throw new DrupalUpdateException('Could not add taxrank ontology: '. $error);
  194. }
  195. }
  196. /**
  197. * Implementation of hook_update_dependencies().
  198. *
  199. * It specifies a list of other modules whose updates must be run prior to
  200. * this one. It also ensures the the Tripal API is in scope for site
  201. * upgrades when tripal_core is disabled.
  202. */
  203. function tripal_organism_update_dependencies() {
  204. $dependencies = array();
  205. // the tripal_cv update 7200 must run prior to update 7200 of this module
  206. $dependencies['tripal_organism'][7200] = array(
  207. 'tripal_cv' => 7200
  208. );
  209. return $dependencies;
  210. }