tripal_pub.install 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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_install().
  13. */
  14. function tripal_pub_install() {
  15. // create the module's data directory
  16. tripal_create_moddir('tripal_pub');
  17. // install the tripal_oub
  18. drupal_install_schema('tripal_pub');
  19. // add loading of the the tripal pub ontology to the job queue
  20. $obo_path = realpath('./') . '/' . drupal_get_path('module', 'tripal_pub') . '/tpub.obo';
  21. $obo_id = tripal_cv_add_obo_ref('Tripal Publication', $obo_path);
  22. tripal_cv_submit_obo_job($obo_id);
  23. // add the custom tables
  24. tripal_pub_add_custom_tables();
  25. }
  26. /**
  27. * Implementation of hook_uninstall().
  28. */
  29. function tripal_pub_uninstall() {
  30. //Remove tables
  31. drupal_uninstall_schema('tripal_pub');
  32. }
  33. /**
  34. * Implementation of hook_schema().
  35. */
  36. function tripal_pub_schema() {
  37. $schema['chado_pub'] = array(
  38. 'fields' => array(
  39. 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
  40. 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
  41. 'pub_id' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
  42. 'sync_date' => array('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer sync date/time'),
  43. ),
  44. 'indexes' => array(
  45. 'pub_id' => array('pub_id')
  46. ),
  47. 'unique keys' => array(
  48. 'nid_vid' => array('nid', 'vid'),
  49. 'vid' => array('vid')
  50. ),
  51. 'primary key' => array('nid'),
  52. );
  53. $schema['tripal_pub_import'] = array(
  54. 'fields' => array(
  55. 'pub_import_id' => array('type' => 'serial', 'not null' => TRUE),
  56. 'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
  57. 'criteria' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE, 'description' => 'Contains a serialized PHP array containing the search criteria'),
  58. 'disabled' => array('type' => 'int', 'unsigned' => TRUE, 'not NULL' => TRUE, 'default' => 0),
  59. 'do_contact' => array('type' => 'int', 'unsigned' => TRUE, 'not NULL' => TRUE, 'default' => 0),
  60. ),
  61. 'primary key' => array('pub_import_id'),
  62. 'indexes' => array(
  63. 'name' => array('name')
  64. ),
  65. );
  66. return $schema;
  67. }
  68. /**
  69. * Implementation of hook_requirements().
  70. */
  71. function tripal_pub_requirements($phase) {
  72. $requirements = array();
  73. if ($phase == 'install') {
  74. // make sure chado is installed
  75. if (!tripal_core_is_chado_installed()) {
  76. $requirements ['tripal_pub'] = array(
  77. 'title' => "tripal_pub",
  78. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  79. 'severity' => REQUIREMENT_ERROR,
  80. );
  81. }
  82. }
  83. return $requirements;
  84. }
  85. /*
  86. *
  87. */
  88. function tripal_pub_add_custom_tables() {
  89. $schema = array (
  90. 'table' => 'pubauthor_contact',
  91. 'fields' => array (
  92. 'pubauthor_contact_id' => array (
  93. 'type' => 'serial',
  94. 'not null' => true,
  95. ),
  96. 'contact_id' => array (
  97. 'type' => 'int',
  98. 'not null' => true,
  99. ),
  100. 'pubauthor_id' => array (
  101. 'type' => 'int',
  102. 'not null' => true,
  103. ),
  104. ),
  105. 'primary key' => array (
  106. 0 => 'pubauthor_contact_id',
  107. ),
  108. 'unique keys' => array (
  109. 'pubauthor_contact_c1' => array (
  110. 0 => 'contact_id',
  111. 1 => 'pubauthor_id',
  112. ),
  113. ),
  114. 'foreign keys' => array (
  115. 'contact' => array (
  116. 'table' => 'contact',
  117. 'columns' => array (
  118. 'contact_id' => 'contact_id',
  119. ),
  120. ),
  121. 'pubauthor' => array (
  122. 'table' => 'pubauthor',
  123. 'columns' => array (
  124. 'pubauthor_id' => 'pubauthor_id',
  125. ),
  126. ),
  127. ),
  128. );
  129. tripal_core_create_custom_table(&$ret, 'pubauthor_contact', $schema, TRUE);
  130. }