tripal_contact.install 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <?php
  2. /**
  3. * @file
  4. * Handles install, uninstall, disable and enable functionality including database tables.
  5. *
  6. * @ingroup tripal_contact
  7. */
  8. /**
  9. * Implements hook_disable().
  10. * Disable default views when module is disabled
  11. *
  12. * @ingroup tripal_contact
  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. * @ingroup tripal_contact
  26. */
  27. function tripal_contact_requirements($phase) {
  28. $requirements = array();
  29. if ($phase == 'install') {
  30. // make sure chado is installed
  31. if (!$GLOBALS["chado_is_installed"]) {
  32. $requirements ['tripal_contact'] = array(
  33. 'title' => "tripal_contact",
  34. 'value' => "ERROR: Chado must be installed before this module can be enabled",
  35. 'severity' => REQUIREMENT_ERROR,
  36. );
  37. }
  38. }
  39. return $requirements;
  40. }
  41. /**
  42. * Implementation of hook_install().
  43. *
  44. * @ingroup tripal_contact
  45. */
  46. function tripal_contact_install() {
  47. // create the module's data directory
  48. tripal_create_files_dir('tripal_contact');
  49. // add the contactprop table to Chado
  50. tripal_contact_add_custom_tables();
  51. // add loading of the the tripal contact ontology to the job queue
  52. $obo_path = drupal_realpath(drupal_get_path('module', 'tripal_contact') . '/files/tcontact.obo');
  53. $obo_id = tripal_cv_add_obo_ref('Tripal Contacts', $obo_path);
  54. tripal_cv_submit_obo_job($obo_id);
  55. // Add cvterms for relationship types
  56. tripal_contact_add_cvs();
  57. tripal_contact_add_cvterms();
  58. /*
  59. // Install our custom block visibility settings per node type
  60. $query = db_insert('block_node_type')
  61. ->fields(array('type', 'module', 'delta'))
  62. ->values(array(
  63. 'type' => 'chado_contact',
  64. 'module' => 'tripal_contact', // My module name
  65. 'delta' => 'contbase', // Same delta used in hook_block_info
  66. )
  67. )->execute();
  68. */
  69. }
  70. /**
  71. * Implementation of hook_uninstall().
  72. *
  73. * @ingroup tripal_contact
  74. */
  75. function tripal_contact_uninstall() {
  76. /*
  77. // remove our custom block visibility settings per node type
  78. db_delete('block_node_type')
  79. ->condition('module', 'chado_contact')
  80. ->condition('delta', 'contbase')
  81. ->execute();
  82. */
  83. }
  84. /**
  85. * Adds any cvs needed by this module.
  86. *
  87. * @ingroup tripal_contact
  88. */
  89. function tripal_contact_add_cvs() {
  90. tripal_cv_add_cv(
  91. 'contact_relationship_types',
  92. 'Contains Types of relationships between contacts.'
  93. );
  94. }
  95. /**
  96. * Adds any cvterms needed by this module.
  97. *
  98. * @ingroup tripal_contact
  99. */
  100. function tripal_contact_add_cvterms() {
  101. }
  102. /**
  103. * Implementation of hook_schema().
  104. *
  105. * @ingroup tripal_contact
  106. */
  107. function tripal_contact_schema() {
  108. $schema['chado_contact'] = array(
  109. 'fields' => array(
  110. 'vid' => array(
  111. 'type' => 'int',
  112. 'unsigned' => TRUE,
  113. 'not null' => TRUE,
  114. 'default' => 0
  115. ),
  116. 'nid' => array(
  117. 'type' => 'int',
  118. 'unsigned' => TRUE,
  119. 'not null' => TRUE,
  120. 'default' => 0
  121. ),
  122. 'contact_id' => array(
  123. 'type' => 'int',
  124. 'not null' => TRUE,
  125. 'default' => 0
  126. )
  127. ),
  128. 'indexes' => array(
  129. 'contact_id' => array('contact_id')
  130. ),
  131. 'unique keys' => array(
  132. 'nid_vid' => array('nid', 'vid'),
  133. 'vid' => array('vid')
  134. ),
  135. 'primary key' => array('nid'),
  136. );
  137. return $schema;
  138. }
  139. /**
  140. * Add any custom tables needed by this module.
  141. * - Contactprop: keep track of properties of contact
  142. *
  143. * @ingroup tripal_contact
  144. */
  145. function tripal_contact_add_custom_tables(){
  146. $schema = array (
  147. 'table' => 'contactprop',
  148. 'fields' => array (
  149. 'contactprop_id' => array (
  150. 'type' => 'serial',
  151. 'not null' => true,
  152. ),
  153. 'contact_id' => array (
  154. 'type' => 'int',
  155. 'not null' => true,
  156. ),
  157. 'type_id' => array (
  158. 'type' => 'int',
  159. 'not null' => true,
  160. ),
  161. 'value' => array (
  162. 'type' => 'text',
  163. 'not null' => false,
  164. ),
  165. 'rank' => array (
  166. 'type' => 'int',
  167. 'not null' => true,
  168. 'default' => 0,
  169. ),
  170. ),
  171. 'primary key' => array (
  172. 0 => 'contactprop_id',
  173. ),
  174. 'unique keys' => array (
  175. 'contactprop_c1' => array (
  176. 0 => 'contact_id',
  177. 1 => 'type_id',
  178. 2 => 'rank',
  179. ),
  180. ),
  181. 'indexes' => array (
  182. 'contactprop_idx1' => array (
  183. 0 => 'contact_id',
  184. ),
  185. 'contactprop_idx2' => array (
  186. 0 => 'type_id',
  187. ),
  188. ),
  189. 'foreign keys' => array (
  190. 'cvterm' => array (
  191. 'table' => 'cvterm',
  192. 'columns' => array (
  193. 'type_id' => 'cvterm_id',
  194. ),
  195. ),
  196. 'contact' => array (
  197. 'table' => 'contact',
  198. 'columns' => array (
  199. 'contact_id' => 'contact_id',
  200. ),
  201. ),
  202. ),
  203. );
  204. chado_create_custom_table('contactprop', $schema, TRUE);
  205. }
  206. /**
  207. * This is the required update for tripal_contact when upgrading from Drupal core API 6.x.
  208. *
  209. * @ingroup tripal_contact
  210. */
  211. function tripal_contact_update_7200() {
  212. // add the new contact_relationship_types vocabulary
  213. // We cannot use the Tripal API calls in the 7000 update
  214. // because during upgrade the tripal_core should also be disabled
  215. try {
  216. $check = db_query("SELECT cv_id FROM chado.cv WHERE name = 'contact_relationship_types'")->fetchObject();
  217. if (!$check->cv_id) {
  218. $sql = "INSERT INTO chado.cv (name, definition) VALUES (
  219. 'contact_relationship_types',
  220. 'Contains Types of relationships between contacts.')
  221. ";
  222. db_query($sql);
  223. }
  224. }
  225. catch (\PDOException $e) {
  226. $error = $e->getMessage();
  227. throw new DrupalUpdateException('Failed to add contact_relationship_types vocabulary: '. $error);
  228. }
  229. }