tripal_organism.install 5.2 KB

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