tripal_featuremap.install 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * @file
  4. * @todo Add file header description
  5. */
  6. /**
  7. * Implementation of hook_install().
  8. *
  9. * @ingroup tripal_featuremap
  10. */
  11. function tripal_featuremap_install() {
  12. // create the module's data directory
  13. tripal_create_moddir('tripal_featuremap');
  14. // create the tables that correlate drupal nodes with chado
  15. // features, maps, etc....
  16. drupal_install_schema('tripal_featuremap');
  17. // Add cvterms
  18. tripal_featuremap_add_cvterms();
  19. }
  20. /**
  21. * Implementation of hook_schema().
  22. *
  23. * @ingroup tripal_featuremap
  24. */
  25. function tripal_featuremap_schema() {
  26. $schema = tripal_featuremap_get_schemas();
  27. return $schema;
  28. }
  29. /**
  30. * Implementation of hook_uninstall().
  31. *
  32. * @ingroup tripal_featuremap
  33. */
  34. function tripal_featuremap_uninstall() {
  35. drupal_uninstall_schema('tripal_featuremap');
  36. // Get the list of nodes to remove
  37. $sql_lib_id = "SELECT nid, vid ".
  38. "FROM {node} ".
  39. "WHERE type='chado_featuremap'";
  40. $result = db_query($sql_lib_id);
  41. while ($node = db_fetch_object($result)) {
  42. node_delete($node->nid);
  43. }
  44. }
  45. /**
  46. * This function simply defines all tables needed for the module to work
  47. * correctly. By putting the table definitions in a separate function we
  48. * can easily provide the entire list for hook_install or individual
  49. * tables for an update.
  50. *
  51. * @ingroup tripal_featuremap
  52. */
  53. function tripal_featuremap_get_schemas() {
  54. $schema = array();
  55. $schema['chado_featuremap'] = array(
  56. 'fields' => array(
  57. 'vid' => array(
  58. 'type' => 'int',
  59. 'unsigned' => TRUE,
  60. 'not null' => TRUE,
  61. 'default' => 0
  62. ),
  63. 'nid' => array(
  64. 'type' => 'int',
  65. 'unsigned' => TRUE,
  66. 'not null' => TRUE,
  67. 'default' => 0
  68. ),
  69. 'featuremap_id' => array(
  70. 'type' => 'int',
  71. 'not null' => TRUE,
  72. 'default' => 0
  73. )
  74. ),
  75. 'indexes' => array(
  76. 'featuremap_id' => array('featuremap_id')
  77. ),
  78. 'unique keys' => array(
  79. 'nid_vid' => array('nid', 'vid'),
  80. 'vid' => array('vid')
  81. ),
  82. 'primary key' => array('nid'),
  83. );
  84. return $schema;
  85. }
  86. /**
  87. * Implementation of hook_requirements().
  88. */
  89. function tripal_featuremap_requirements($phase) {
  90. $requirements = array();
  91. if ($phase == 'install') {
  92. // make sure chado is installed
  93. if (!tripal_core_is_chado_installed()) {
  94. $requirements ['tripal_featuremap'] = array(
  95. 'title' => "tripal_featuremap",
  96. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  97. 'severity' => REQUIREMENT_ERROR,
  98. );
  99. }
  100. }
  101. return $requirements;
  102. }
  103. /*
  104. *
  105. */
  106. function tripal_featuremap_add_cvterms() {
  107. // add cvterms for the map unit types
  108. tripal_cv_add_cvterm(array('name' => 'cM','def' => 'Centimorgan units'),
  109. 'tripal_featuremap', 0, 1, 'tripal');
  110. tripal_cv_add_cvterm(array('name' => 'bp','def' => 'Base pairs units'),
  111. 'tripal_featuremap', 0, 1, 'tripal');
  112. tripal_cv_add_cvterm(array('name' => 'bin_unit','def' => 'The bin unit'),
  113. 'tripal_featuremap', 0, 1, 'tripal');
  114. tripal_cv_add_cvterm(array('name' => 'marker_order','def' => 'Units simply to define marker order.'),
  115. 'tripal_featuremap', 0, 1, 'tripal');
  116. tripal_cv_add_cvterm(array('name' => 'undefined','def' => 'A catch-all for an undefined unit type'),
  117. 'tripal_featuremap', 0, 1, 'tripal');
  118. }