tripal_contact.install 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. * Disable default views when module is disabled
  13. */
  14. function tripal_contact_disable() {
  15. // Disable all default views provided by this module
  16. require_once("tripal_contact.views_default.inc");
  17. $views = tripal_contact_views_default_views();
  18. foreach (array_keys($views) as $view_name) {
  19. tripal_views_admin_disable_view($view_name,FALSE,array('suppress_error' => TRUE));
  20. }
  21. }
  22. /**
  23. * Implementation of hook_requirements().
  24. *
  25. */
  26. function tripal_contact_requirements($phase) {
  27. $requirements = array();
  28. if ($phase == 'install') {
  29. // make sure chado is installed
  30. if (!$GLOBALS["chado_is_installed"]) {
  31. $requirements ['tripal_contact'] = array(
  32. 'title' => "tripal_contact",
  33. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  34. 'severity' => REQUIREMENT_ERROR,
  35. );
  36. }
  37. }
  38. return $requirements;
  39. }
  40. /**
  41. * Implementation of hook_install().
  42. */
  43. function tripal_contact_install() {
  44. // create the module's data directory
  45. tripal_create_moddir('tripal_contact');
  46. // add the contactprop table to Chado
  47. tripal_contact_add_custom_tables();
  48. // add loading of the the tripal contact ontology to the job queue
  49. $obo_path = drupal_realpath(drupal_get_path('module', 'tripal_contact') . '/files/tcontact.obo');
  50. $obo_id = tripal_cv_add_obo_ref('Tripal Contacts', $obo_path);
  51. tripal_cv_submit_obo_job($obo_id);
  52. /*
  53. // Install our custom block visibility settings per node type
  54. $query = db_insert('block_node_type')
  55. ->fields(array('type', 'module', 'delta'))
  56. ->values(array(
  57. 'type' => 'chado_contact',
  58. 'module' => 'tripal_contact', // My module name
  59. 'delta' => 'contbase', // Same delta used in hook_block_info
  60. )
  61. )->execute();
  62. */
  63. }
  64. /**
  65. * Implementation of hook_uninstall().
  66. */
  67. function tripal_contact_uninstall() {
  68. /*
  69. // remove our custom block visibility settings per node type
  70. db_delete('block_node_type')
  71. ->condition('module', 'chado_contact')
  72. ->condition('delta', 'contbase')
  73. ->execute();
  74. */
  75. }
  76. /**
  77. * Implementation of hook_schema().
  78. */
  79. function tripal_contact_schema() {
  80. $schema['chado_contact'] = array(
  81. 'fields' => array(
  82. 'vid' => array(
  83. 'type' => 'int',
  84. 'unsigned' => TRUE,
  85. 'not null' => TRUE,
  86. 'default' => 0
  87. ),
  88. 'nid' => array(
  89. 'type' => 'int',
  90. 'unsigned' => TRUE,
  91. 'not null' => TRUE,
  92. 'default' => 0
  93. ),
  94. 'contact_id' => array(
  95. 'type' => 'int',
  96. 'not null' => TRUE,
  97. 'default' => 0
  98. )
  99. ),
  100. 'indexes' => array(
  101. 'contact_id' => array('contact_id')
  102. ),
  103. 'unique keys' => array(
  104. 'nid_vid' => array('nid', 'vid'),
  105. 'vid' => array('vid')
  106. ),
  107. 'primary key' => array('nid'),
  108. );
  109. return $schema;
  110. }
  111. /*
  112. *
  113. */
  114. function tripal_contact_add_custom_tables(){
  115. $schema = array (
  116. 'table' => 'contactprop',
  117. 'fields' => array (
  118. 'contactprop_id' => array (
  119. 'type' => 'serial',
  120. 'not null' => true,
  121. ),
  122. 'contact_id' => array (
  123. 'type' => 'int',
  124. 'not null' => true,
  125. ),
  126. 'type_id' => array (
  127. 'type' => 'int',
  128. 'not null' => true,
  129. ),
  130. 'value' => array (
  131. 'type' => 'text',
  132. 'not null' => false,
  133. ),
  134. 'rank' => array (
  135. 'type' => 'int',
  136. 'not null' => true,
  137. 'default' => 0,
  138. ),
  139. ),
  140. 'primary key' => array (
  141. 0 => 'contactprop_id',
  142. ),
  143. 'unique keys' => array (
  144. 'contactprop_c1' => array (
  145. 0 => 'contact_id',
  146. 1 => 'type_id',
  147. 2 => 'rank',
  148. ),
  149. ),
  150. 'indexes' => array (
  151. 'contactprop_idx1' => array (
  152. 0 => 'contact_id',
  153. ),
  154. 'contactprop_idx2' => array (
  155. 0 => 'type_id',
  156. ),
  157. ),
  158. 'foreign keys' => array (
  159. 'cvterm' => array (
  160. 'table' => 'cvterm',
  161. 'columns' => array (
  162. 'type_id' => 'cvterm_id',
  163. ),
  164. ),
  165. 'contact' => array (
  166. 'table' => 'contact',
  167. 'columns' => array (
  168. 'contact_id' => 'contact_id',
  169. ),
  170. ),
  171. ),
  172. );
  173. tripal_core_create_custom_table('contactprop', $schema, TRUE);
  174. }