tripal_contact.install 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. // add the tripal_contact table to Drupal
  16. drupal_install_schema('tripal_contact');
  17. // add the contactprop table to Chado
  18. tripal_contact_add_custom_tables();
  19. // add loading of the the tripal contact ontology to the job queue
  20. $obo_path = realpath('./') . '/' . drupal_get_path('module', 'tripal_contact') . '/files/tcontact.obo';
  21. $obo_id = tripal_cv_add_obo_ref('Tripal Contacts', $obo_path);
  22. tripal_cv_submit_obo_job($obo_id);
  23. }
  24. /**
  25. * Implementation of hook_uninstall().
  26. */
  27. function tripal_contact_uninstall() {
  28. drupal_uninstall_schema('tripal_contact');
  29. }
  30. /**
  31. * Implementation of hook_schema().
  32. */
  33. function tripal_contact_schema() {
  34. $schema['chado_contact'] = array(
  35. 'fields' => array(
  36. 'nid' => array(
  37. 'type' => 'int',
  38. 'unsigned' => TRUE,
  39. 'not null' => TRUE,
  40. ),
  41. 'vid' => array(
  42. 'type' => 'int',
  43. 'not null' => TRUE,
  44. ),
  45. 'contact_id' => array(
  46. 'type' => 'int',
  47. 'unsigned' => TRUE,
  48. 'not null' => TRUE,
  49. ),
  50. ),
  51. 'primary key' => array('nid', 'vid', 'contact_id'),
  52. );
  53. return $schema;
  54. }
  55. /**
  56. * Implementation of hook_requirements().
  57. *
  58. */
  59. function tripal_contact_requirements($phase) {
  60. $requirements = array();
  61. if ($phase == 'install') {
  62. // make sure chado is installed
  63. if (!tripal_core_is_chado_installed()) {
  64. $requirements ['tripal_contact'] = array(
  65. 'title' => "tripal_contact",
  66. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  67. 'severity' => REQUIREMENT_ERROR,
  68. );
  69. }
  70. }
  71. return $requirements;
  72. }
  73. /*
  74. *
  75. */
  76. function tripal_contact_add_custom_tables(){
  77. $schema = array (
  78. 'table' => 'contactprop',
  79. 'fields' => array (
  80. 'contactprop_id' => array (
  81. 'type' => 'serial',
  82. 'not null' => true,
  83. ),
  84. 'contact_id' => array (
  85. 'type' => 'int',
  86. 'not null' => true,
  87. ),
  88. 'type_id' => array (
  89. 'type' => 'int',
  90. 'not null' => true,
  91. ),
  92. 'value' => array (
  93. 'type' => 'text',
  94. 'not null' => false,
  95. ),
  96. 'rank' => array (
  97. 'type' => 'int',
  98. 'not null' => true,
  99. 'default' => 0,
  100. ),
  101. ),
  102. 'primary key' => array (
  103. 0 => 'contactprop_id',
  104. ),
  105. 'unique keys' => array (
  106. 'contactprop_c1' => array (
  107. 0 => 'contact_id',
  108. 1 => 'type_id',
  109. 2 => 'rank',
  110. ),
  111. ),
  112. 'indexes' => array (
  113. 'contactprop_idx1' => array (
  114. 0 => 'contact_id',
  115. ),
  116. 'contactprop_idx2' => array (
  117. 0 => 'type_id',
  118. ),
  119. ),
  120. 'foreign keys' => array (
  121. 'cvterm' => array (
  122. 'table' => 'cvterm',
  123. 'columns' => array (
  124. 'type_id' => 'cvterm_id',
  125. ),
  126. ),
  127. 'contact' => array (
  128. 'table' => 'contact',
  129. 'columns' => array (
  130. 'contact_id' => 'contact_id',
  131. ),
  132. ),
  133. ),
  134. );
  135. tripal_core_create_custom_table(&$ret, 'contactprop', $schema, TRUE);
  136. }
  137. /**
  138. * Update for Drupal 6.x, Tripal 1.0
  139. * This update
  140. * - adds a new contact node
  141. *
  142. * @ingroup tripal_contact
  143. */
  144. function tripal_contact_update_6001() {
  145. // add the tripal_contact table
  146. drupal_install_schema('tripal_contact');
  147. // add the custom tables
  148. tripal_contact_add_custom_tables();
  149. // add loading of the the tripal contact ontology to the job queue
  150. $obo_path = realpath('./') . '/' . drupal_get_path('module', 'tripal_contact') . '/tcontact.obo';
  151. $obo_id = tripal_cv_add_obo_ref('Tripal Contacts', $obo_path);
  152. tripal_cv_submit_obo_job($obo_id);
  153. return $ret;
  154. }