tripal_pub.install 4.2 KB

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