tripal_organism.install 5.9 KB

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