tripal_contact.install 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /**
  3. * @file
  4. * This file contains all the functions which describe and implement drupal database tables
  5. * needed by this module. This module was developed by Chad N.A. Krilow and Lacey-Anne Sanderson,
  6. * University of Saskatchewan.
  7. *
  8. * The contact manamgenet module allows you to sync data in a chado/Tripal instance with
  9. * multiple contact/mysql instances as well as manage and create such contact instances
  10. */
  11. /**
  12. * Implementation of hook_install().
  13. */
  14. function tripal_contact_install() {
  15. // create the module's data directory
  16. tripal_create_moddir('tripal_contact');
  17. // add the tripal_contact table to Drupal
  18. drupal_install_schema('tripal_contact');
  19. // add the contactprop table to Chado
  20. tripal_contact_add_custom_tables();
  21. // add loading of the the tripal contact ontology to the job queue
  22. $obo_path = realpath('./') . '/' . drupal_get_path('module', 'tripal_contact') . '/files/tcontact.obo';
  23. $obo_id = tripal_cv_add_obo_ref('Tripal Contacts', $obo_path);
  24. tripal_cv_submit_obo_job($obo_id);
  25. }
  26. /**
  27. * Implementation of hook_uninstall().
  28. */
  29. function tripal_contact_uninstall() {
  30. drupal_uninstall_schema('tripal_contact');
  31. }
  32. /**
  33. * Implementation of hook_schema().
  34. */
  35. function tripal_contact_schema() {
  36. $schema['chado_contact'] = array(
  37. 'fields' => array(
  38. 'vid' => array(
  39. 'type' => 'int',
  40. 'unsigned' => TRUE,
  41. 'not null' => TRUE,
  42. 'default' => 0
  43. ),
  44. 'nid' => array(
  45. 'type' => 'int',
  46. 'unsigned' => TRUE,
  47. 'not null' => TRUE,
  48. 'default' => 0
  49. ),
  50. 'contact_id' => array(
  51. 'type' => 'int',
  52. 'not null' => TRUE,
  53. 'default' => 0
  54. )
  55. ),
  56. 'indexes' => array(
  57. 'contact_id' => array('contact_id')
  58. ),
  59. 'unique keys' => array(
  60. 'nid_vid' => array('nid', 'vid'),
  61. 'vid' => array('vid')
  62. ),
  63. 'primary key' => array('nid'),
  64. );
  65. return $schema;
  66. }
  67. /**
  68. * Implementation of hook_requirements().
  69. *
  70. */
  71. function tripal_contact_requirements($phase) {
  72. $requirements = array();
  73. if ($phase == 'install') {
  74. // make sure chado is installed
  75. if (!tripal_core_is_chado_installed()) {
  76. $requirements ['tripal_contact'] = array(
  77. 'title' => "tripal_contact",
  78. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  79. 'severity' => REQUIREMENT_ERROR,
  80. );
  81. }
  82. }
  83. return $requirements;
  84. }
  85. /*
  86. *
  87. */
  88. function tripal_contact_add_custom_tables(){
  89. $schema = array (
  90. 'table' => 'contactprop',
  91. 'fields' => array (
  92. 'contactprop_id' => array (
  93. 'type' => 'serial',
  94. 'not null' => true,
  95. ),
  96. 'contact_id' => array (
  97. 'type' => 'int',
  98. 'not null' => true,
  99. ),
  100. 'type_id' => array (
  101. 'type' => 'int',
  102. 'not null' => true,
  103. ),
  104. 'value' => array (
  105. 'type' => 'text',
  106. 'not null' => false,
  107. ),
  108. 'rank' => array (
  109. 'type' => 'int',
  110. 'not null' => true,
  111. 'default' => 0,
  112. ),
  113. ),
  114. 'primary key' => array (
  115. 0 => 'contactprop_id',
  116. ),
  117. 'unique keys' => array (
  118. 'contactprop_c1' => array (
  119. 0 => 'contact_id',
  120. 1 => 'type_id',
  121. 2 => 'rank',
  122. ),
  123. ),
  124. 'indexes' => array (
  125. 'contactprop_idx1' => array (
  126. 0 => 'contact_id',
  127. ),
  128. 'contactprop_idx2' => array (
  129. 0 => 'type_id',
  130. ),
  131. ),
  132. 'foreign keys' => array (
  133. 'cvterm' => array (
  134. 'table' => 'cvterm',
  135. 'columns' => array (
  136. 'type_id' => 'cvterm_id',
  137. ),
  138. ),
  139. 'contact' => array (
  140. 'table' => 'contact',
  141. 'columns' => array (
  142. 'contact_id' => 'contact_id',
  143. ),
  144. ),
  145. ),
  146. );
  147. tripal_core_create_custom_table($ret, 'contactprop', $schema, TRUE);
  148. }
  149. /**
  150. * Update for Drupal 6.x, Tripal 1.0
  151. * This update
  152. * - adds a new contact node
  153. *
  154. * @ingroup tripal_contact
  155. */
  156. function tripal_contact_update_6001() {
  157. // add the tripal_contact table
  158. drupal_install_schema('tripal_contact');
  159. // add the custom tables
  160. tripal_contact_add_custom_tables();
  161. // add loading of the the tripal contact ontology to the job queue
  162. $obo_path = realpath('./') . '/' . drupal_get_path('module', 'tripal_contact') . '/tcontact.obo';
  163. $obo_id = tripal_cv_add_obo_ref('Tripal Contacts', $obo_path);
  164. tripal_cv_submit_obo_job($obo_id);
  165. return $ret;
  166. }