tripal_pub.install 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 project manamgenet module allows you to sync data in a chado/Tripal instance with
  9. * multiple project/mysql instances as well as manage and create such project instances
  10. */
  11. /**
  12. * Implementation of hook_requirements().
  13. */
  14. function tripal_pub_requirements($phase) {
  15. $requirements = array();
  16. if ($phase == 'install') {
  17. // make sure chado is installed
  18. if (!tripal_core_is_chado_installed()) {
  19. $requirements ['tripal_pub'] = array(
  20. 'title' => "tripal_pub",
  21. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  22. 'severity' => REQUIREMENT_ERROR,
  23. );
  24. }
  25. }
  26. return $requirements;
  27. }
  28. /**
  29. * Implementation of hook_install().
  30. */
  31. function tripal_pub_install() {
  32. global $base_path;
  33. // create the module's data directory
  34. tripal_create_moddir('tripal_pub');
  35. // add loading of the the tripal pub ontology to the job queue
  36. $obo_path = drupal_realpath(drupal_get_path('module', 'tripal_pub') . '/files/tpub.obo');
  37. $obo_id = tripal_cv_add_obo_ref('Tripal Publication', $obo_path);
  38. tripal_cv_submit_obo_job($obo_id);
  39. // add the custom tables
  40. tripal_pub_add_custom_tables();
  41. }
  42. /**
  43. * Implementation of hook_uninstall().
  44. */
  45. function tripal_pub_uninstall() {
  46. }
  47. /**
  48. *
  49. */
  50. function tripal_pub_enable() {
  51. // make sure we have our supported databases
  52. tripal_db_add_db('PMID', 'PubMed', 'http://www.ncbi.nlm.nih.gov/pubmed', 'http://www.ncbi.nlm.nih.gov/pubmed/', TRUE);
  53. tripal_db_add_db('AGL', 'USDA National Agricultural Library', 'http://agricola.nal.usda.gov/', '', TRUE);
  54. variable_set('tripal_pub_supported_dbs', array('PMID', 'AGL'));
  55. }
  56. /**
  57. * Implementation of hook_schema().
  58. */
  59. function tripal_pub_schema() {
  60. $schema['chado_pub'] = array(
  61. 'fields' => array(
  62. 'vid' => array(
  63. 'type' => 'int',
  64. 'unsigned' => TRUE,
  65. 'not null' => TRUE, 'default' => 0
  66. ),
  67. 'nid' => array(
  68. 'type' => 'int',
  69. 'unsigned' => TRUE,
  70. 'not null' => TRUE,
  71. 'default' => 0
  72. ),
  73. 'pub_id' => array(
  74. 'type' => 'int',
  75. 'not null' => TRUE,
  76. 'default' => 0
  77. ),
  78. 'sync_date' => array(
  79. 'type' => 'int',
  80. 'not null' => FALSE,
  81. 'description' => 'UNIX integer sync date/time'
  82. ),
  83. ),
  84. 'indexes' => array(
  85. 'pub_id' => array('pub_id')
  86. ),
  87. 'unique keys' => array(
  88. 'nid_vid' => array('nid', 'vid'),
  89. 'vid' => array('vid')
  90. ),
  91. 'primary key' => array('nid'),
  92. );
  93. $schema['tripal_pub_import'] = array(
  94. 'fields' => array(
  95. 'pub_import_id' => array(
  96. 'type' => 'serial',
  97. 'not null' => TRUE
  98. ),
  99. 'name' => array(
  100. 'type' => 'varchar',
  101. 'length' => 255,
  102. 'not null' => TRUE
  103. ),
  104. 'criteria' => array(
  105. 'type' => 'text',
  106. 'size' => 'normal',
  107. 'not null' => TRUE,
  108. 'description' => 'Contains a serialized PHP array containing the search criteria'
  109. ),
  110. 'disabled' => array(
  111. 'type' => 'int',
  112. 'unsigned' => TRUE,
  113. 'not NULL' => TRUE,
  114. 'default' => 0
  115. ),
  116. 'do_contact' => array(
  117. 'type' => 'int',
  118. 'unsigned' => TRUE,
  119. 'not NULL' => TRUE,
  120. 'default' => 0
  121. ),
  122. ),
  123. 'primary key' => array('pub_import_id'),
  124. 'indexes' => array(
  125. 'name' => array('name')
  126. ),
  127. );
  128. return $schema;
  129. }
  130. /*
  131. *
  132. */
  133. function tripal_pub_add_custom_tables() {
  134. $schema = array (
  135. 'table' => 'pubauthor_contact',
  136. 'fields' => array (
  137. 'pubauthor_contact_id' => array (
  138. 'type' => 'serial',
  139. 'not null' => true,
  140. ),
  141. 'contact_id' => array (
  142. 'type' => 'int',
  143. 'not null' => true,
  144. ),
  145. 'pubauthor_id' => array (
  146. 'type' => 'int',
  147. 'not null' => true,
  148. ),
  149. ),
  150. 'primary key' => array (
  151. 0 => 'pubauthor_contact_id',
  152. ),
  153. 'unique keys' => array (
  154. 'pubauthor_contact_c1' => array (
  155. 0 => 'contact_id',
  156. 1 => 'pubauthor_id',
  157. ),
  158. ),
  159. 'foreign keys' => array (
  160. 'contact' => array (
  161. 'table' => 'contact',
  162. 'columns' => array (
  163. 'contact_id' => 'contact_id',
  164. ),
  165. ),
  166. 'pubauthor' => array (
  167. 'table' => 'pubauthor',
  168. 'columns' => array (
  169. 'pubauthor_id' => 'pubauthor_id',
  170. ),
  171. ),
  172. ),
  173. );
  174. tripal_core_create_custom_table('pubauthor_contact', $schema, TRUE);
  175. }