tripal_pub.install 5.0 KB

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