tripal_contact.install 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 must 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_files_dir('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. // Add cvterms for relationship types
  53. tripal_contact_add_cvs();
  54. tripal_contact_add_cvterms();
  55. /*
  56. // Install our custom block visibility settings per node type
  57. $query = db_insert('block_node_type')
  58. ->fields(array('type', 'module', 'delta'))
  59. ->values(array(
  60. 'type' => 'chado_contact',
  61. 'module' => 'tripal_contact', // My module name
  62. 'delta' => 'contbase', // Same delta used in hook_block_info
  63. )
  64. )->execute();
  65. */
  66. }
  67. /**
  68. * Implementation of hook_uninstall().
  69. */
  70. function tripal_contact_uninstall() {
  71. /*
  72. // remove our custom block visibility settings per node type
  73. db_delete('block_node_type')
  74. ->condition('module', 'chado_contact')
  75. ->condition('delta', 'contbase')
  76. ->execute();
  77. */
  78. }
  79. function tripal_contact_add_cvs() {
  80. tripal_cv_add_cv(
  81. 'contact_relationship_types',
  82. 'Contains Types of relationships between contacts.'
  83. );
  84. }
  85. function tripal_contact_add_cvterms() {
  86. }
  87. /**
  88. * Implementation of hook_schema().
  89. */
  90. function tripal_contact_schema() {
  91. $schema['chado_contact'] = array(
  92. 'fields' => array(
  93. 'vid' => array(
  94. 'type' => 'int',
  95. 'unsigned' => TRUE,
  96. 'not null' => TRUE,
  97. 'default' => 0
  98. ),
  99. 'nid' => array(
  100. 'type' => 'int',
  101. 'unsigned' => TRUE,
  102. 'not null' => TRUE,
  103. 'default' => 0
  104. ),
  105. 'contact_id' => array(
  106. 'type' => 'int',
  107. 'not null' => TRUE,
  108. 'default' => 0
  109. )
  110. ),
  111. 'indexes' => array(
  112. 'contact_id' => array('contact_id')
  113. ),
  114. 'unique keys' => array(
  115. 'nid_vid' => array('nid', 'vid'),
  116. 'vid' => array('vid')
  117. ),
  118. 'primary key' => array('nid'),
  119. );
  120. return $schema;
  121. }
  122. /*
  123. *
  124. */
  125. function tripal_contact_add_custom_tables(){
  126. $schema = array (
  127. 'table' => 'contactprop',
  128. 'fields' => array (
  129. 'contactprop_id' => array (
  130. 'type' => 'serial',
  131. 'not null' => true,
  132. ),
  133. 'contact_id' => array (
  134. 'type' => 'int',
  135. 'not null' => true,
  136. ),
  137. 'type_id' => array (
  138. 'type' => 'int',
  139. 'not null' => true,
  140. ),
  141. 'value' => array (
  142. 'type' => 'text',
  143. 'not null' => false,
  144. ),
  145. 'rank' => array (
  146. 'type' => 'int',
  147. 'not null' => true,
  148. 'default' => 0,
  149. ),
  150. ),
  151. 'primary key' => array (
  152. 0 => 'contactprop_id',
  153. ),
  154. 'unique keys' => array (
  155. 'contactprop_c1' => array (
  156. 0 => 'contact_id',
  157. 1 => 'type_id',
  158. 2 => 'rank',
  159. ),
  160. ),
  161. 'indexes' => array (
  162. 'contactprop_idx1' => array (
  163. 0 => 'contact_id',
  164. ),
  165. 'contactprop_idx2' => array (
  166. 0 => 'type_id',
  167. ),
  168. ),
  169. 'foreign keys' => array (
  170. 'cvterm' => array (
  171. 'table' => 'cvterm',
  172. 'columns' => array (
  173. 'type_id' => 'cvterm_id',
  174. ),
  175. ),
  176. 'contact' => array (
  177. 'table' => 'contact',
  178. 'columns' => array (
  179. 'contact_id' => 'contact_id',
  180. ),
  181. ),
  182. ),
  183. );
  184. chado_create_custom_table('contactprop', $schema, TRUE);
  185. }
  186. /**
  187. * This is the required update for tripal_contact when upgrading from Drupal core API 6.x.
  188. */
  189. function tripal_contact_update_7000() {
  190. tripal_contact_add_cvs();
  191. tripal_contact_add_cvterms();
  192. }