tripal_featuremap.install 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. }
  18. /**
  19. * Implementation of hook_schema().
  20. *
  21. * @ingroup tripal_featuremap
  22. */
  23. function tripal_featuremap_schema() {
  24. $schema = tripal_featuremap_get_schemas();
  25. return $schema;
  26. }
  27. /**
  28. * Implementation of hook_uninstall().
  29. *
  30. * @ingroup tripal_featuremap
  31. */
  32. function tripal_featuremap_uninstall() {
  33. drupal_uninstall_schema('tripal_featuremap');
  34. // Get the list of nodes to remove
  35. $sql_lib_id = "SELECT nid, vid ".
  36. "FROM {node} ".
  37. "WHERE type='chado_featuremap'";
  38. $result = db_query($sql_lib_id);
  39. while ($node = db_fetch_object($result)) {
  40. node_delete($node->nid);
  41. }
  42. }
  43. /**
  44. * This function simply defines all tables needed for the module to work
  45. * correctly. By putting the table definitions in a separate function we
  46. * can easily provide the entire list for hook_install or individual
  47. * tables for an update.
  48. *
  49. * @ingroup tripal_featuremap
  50. */
  51. function tripal_featuremap_get_schemas() {
  52. $schema = array();
  53. $schema['chado_featuremap'] = array(
  54. 'fields' => array(
  55. 'vid' => array(
  56. 'type' => 'int',
  57. 'unsigned' => TRUE,
  58. 'not null' => TRUE,
  59. 'default' => 0
  60. ),
  61. 'nid' => array(
  62. 'type' => 'int',
  63. 'unsigned' => TRUE,
  64. 'not null' => TRUE,
  65. 'default' => 0
  66. ),
  67. 'featuremap_id' => array(
  68. 'type' => 'int',
  69. 'not null' => TRUE,
  70. 'default' => 0
  71. )
  72. ),
  73. 'indexes' => array(
  74. 'featuremap_id' => array('featuremap_id')
  75. ),
  76. 'unique keys' => array(
  77. 'nid_vid' => array('nid', 'vid'),
  78. 'vid' => array('vid')
  79. ),
  80. 'primary key' => array('nid'),
  81. );
  82. return $schema;
  83. }
  84. /**
  85. * Implementation of hook_requirements().
  86. */
  87. function tripal_featuremap_requirements($phase) {
  88. $requirements = array();
  89. if ($phase == 'install') {
  90. // make sure chado is installed
  91. if (!tripal_core_is_chado_installed()) {
  92. $requirements ['tripal_featuremap'] = array(
  93. 'title' => "tripal_featuremap",
  94. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  95. 'severity' => REQUIREMENT_ERROR,
  96. );
  97. }
  98. }
  99. return $requirements;
  100. }