tripal_pub.install 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. tripal_pub_add_cvs();
  51. tripal_pub_add_cvterms();
  52. // add the custom tables
  53. tripal_pub_add_custom_tables();
  54. }
  55. /**
  56. * Implementation of hook_uninstall().
  57. */
  58. function tripal_pub_uninstall() {
  59. }
  60. /**
  61. *
  62. */
  63. function tripal_pub_enable() {
  64. // make sure we have our supported databases
  65. tripal_db_add_db('PMID', 'PubMed', 'http://www.ncbi.nlm.nih.gov/pubmed', 'http://www.ncbi.nlm.nih.gov/pubmed/', TRUE);
  66. tripal_db_add_db('AGL', 'USDA National Agricultural Library', 'http://agricola.nal.usda.gov/', '', TRUE);
  67. variable_set('tripal_pub_supported_dbs', array('PMID', 'AGL'));
  68. }
  69. /**
  70. * Implementation of hook_schema().
  71. */
  72. function tripal_pub_schema() {
  73. $schema['chado_pub'] = array(
  74. 'fields' => array(
  75. 'vid' => array(
  76. 'type' => 'int',
  77. 'unsigned' => TRUE,
  78. 'not null' => TRUE, 'default' => 0
  79. ),
  80. 'nid' => array(
  81. 'type' => 'int',
  82. 'unsigned' => TRUE,
  83. 'not null' => TRUE,
  84. 'default' => 0
  85. ),
  86. 'pub_id' => array(
  87. 'type' => 'int',
  88. 'not null' => TRUE,
  89. 'default' => 0
  90. ),
  91. 'sync_date' => array(
  92. 'type' => 'int',
  93. 'not null' => FALSE,
  94. 'description' => 'UNIX integer sync date/time'
  95. ),
  96. ),
  97. 'indexes' => array(
  98. 'pub_id' => array('pub_id')
  99. ),
  100. 'unique keys' => array(
  101. 'nid_vid' => array('nid', 'vid'),
  102. 'vid' => array('vid')
  103. ),
  104. 'primary key' => array('nid'),
  105. );
  106. $schema['tripal_pub_import'] = array(
  107. 'fields' => array(
  108. 'pub_import_id' => array(
  109. 'type' => 'serial',
  110. 'not null' => TRUE
  111. ),
  112. 'name' => array(
  113. 'type' => 'varchar',
  114. 'length' => 255,
  115. 'not null' => TRUE
  116. ),
  117. 'criteria' => array(
  118. 'type' => 'text',
  119. 'size' => 'normal',
  120. 'not null' => TRUE,
  121. 'description' => 'Contains a serialized PHP array containing the search criteria'
  122. ),
  123. 'disabled' => array(
  124. 'type' => 'int',
  125. 'unsigned' => TRUE,
  126. 'not NULL' => TRUE,
  127. 'default' => 0
  128. ),
  129. 'do_contact' => array(
  130. 'type' => 'int',
  131. 'unsigned' => TRUE,
  132. 'not NULL' => TRUE,
  133. 'default' => 0
  134. ),
  135. ),
  136. 'primary key' => array('pub_import_id'),
  137. 'indexes' => array(
  138. 'name' => array('name')
  139. ),
  140. );
  141. return $schema;
  142. }
  143. /*
  144. *
  145. */
  146. function tripal_pub_add_custom_tables() {
  147. $schema = array (
  148. 'table' => 'pubauthor_contact',
  149. 'fields' => array (
  150. 'pubauthor_contact_id' => array (
  151. 'type' => 'serial',
  152. 'not null' => true,
  153. ),
  154. 'contact_id' => array (
  155. 'type' => 'int',
  156. 'not null' => true,
  157. ),
  158. 'pubauthor_id' => array (
  159. 'type' => 'int',
  160. 'not null' => true,
  161. ),
  162. ),
  163. 'primary key' => array (
  164. 0 => 'pubauthor_contact_id',
  165. ),
  166. 'unique keys' => array (
  167. 'pubauthor_contact_c1' => array (
  168. 0 => 'contact_id',
  169. 1 => 'pubauthor_id',
  170. ),
  171. ),
  172. 'foreign keys' => array (
  173. 'contact' => array (
  174. 'table' => 'contact',
  175. 'columns' => array (
  176. 'contact_id' => 'contact_id',
  177. ),
  178. ),
  179. 'pubauthor' => array (
  180. 'table' => 'pubauthor',
  181. 'columns' => array (
  182. 'pubauthor_id' => 'pubauthor_id',
  183. ),
  184. ),
  185. ),
  186. );
  187. tripal_core_create_custom_table('pubauthor_contact', $schema, TRUE);
  188. }
  189. /**
  190. *
  191. */
  192. function tripal_project_add_cvs() {
  193. // Add cv for relationship types
  194. tripal_cv_add_cv(
  195. 'pub_relationship_types',
  196. 'Contains Types of relationships between publications.'
  197. );
  198. }
  199. /**
  200. *
  201. */
  202. function tripal_project_add_cvterms() {
  203. }
  204. /**
  205. * This is the required update for tripal_contact when upgrading from Drupal core API 6.x.
  206. */
  207. function tripal_pub_update_7000() {
  208. tripal_pub_add_cvs();
  209. tripal_pub_add_cvterms();
  210. }