tripal_organism.install 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * @file
  4. * Functions pertaining to the install/uninstall of this module
  5. */
  6. /**
  7. * Implementation of hook_install().
  8. *
  9. * @ingroup tripal_organism
  10. */
  11. function tripal_organism_install() {
  12. // create the module's data directory
  13. tripal_create_moddir('tripal_organism');
  14. // create the directory where image files will be stored. We create this
  15. // here otherwise it will get created when the first organism is synced.
  16. // The user that performs the syncing will receive ownership of the
  17. // images directory which may not allow for write access by the web server
  18. // user. So, we create it here
  19. $dest = file_directory_path() . "/tripal/tripal_organism/images";
  20. file_check_directory($dest, FILE_CREATE_DIRECTORY);
  21. // create the tables that correlate drupal nodes with chado
  22. // features, organisms, etc....
  23. drupal_install_schema('tripal_organism');
  24. }
  25. /**
  26. * Implementation of hook_schema().
  27. *
  28. * @ingroup tripal_organism
  29. */
  30. function tripal_organism_schema() {
  31. $schema = tripal_organism_get_schemas();
  32. return $schema;
  33. }
  34. /**
  35. * Implementation of hook_uninstall().
  36. *
  37. * @ingroup tripal_organism
  38. */
  39. function tripal_organism_uninstall() {
  40. drupal_uninstall_schema('tripal_organism');
  41. // Get the list of nodes to remove
  42. $sql_lib_id = "SELECT nid, vid ".
  43. "FROM {node} ".
  44. "WHERE type='chado_organism'";
  45. $result = db_query($sql_lib_id);
  46. while ($node = db_fetch_object($result)) {
  47. node_delete($node->nid);
  48. }
  49. // remove the materialized views
  50. // Remove the custom view if exists
  51. if (db_table_exists('tripal_organism_views_common_name')) {
  52. $sql = "DROP TABLE {tripal_organism_views_common_name}";
  53. db_query($sql);
  54. }
  55. }
  56. /**
  57. * This function simply defines all tables needed for the module to work
  58. * correctly. By putting the table definitions in a separate function we
  59. * can easily provide the entire list for hook_install or individual
  60. * tables for an update.
  61. *
  62. * @ingroup tripal_organism
  63. */
  64. function tripal_organism_get_schemas() {
  65. $schema = array();
  66. $schema['chado_organism'] = array(
  67. 'fields' => array(
  68. 'vid' => array(
  69. 'type' => 'int',
  70. 'unsigned' => TRUE,
  71. 'not null' => TRUE,
  72. 'default' => 0
  73. ),
  74. 'nid' => array(
  75. 'type' => 'int',
  76. 'unsigned' => TRUE,
  77. 'not null' => TRUE,
  78. 'default' => 0
  79. ),
  80. 'organism_id' => array(
  81. 'type' => 'int',
  82. 'not null' => TRUE,
  83. 'default' => 0
  84. )
  85. ),
  86. 'indexes' => array(
  87. 'organism_id' => array('organism_id')
  88. ),
  89. 'unique keys' => array(
  90. 'nid_vid' => array('nid', 'vid'),
  91. 'vid' => array('vid')
  92. ),
  93. 'primary key' => array('nid'),
  94. );
  95. return $schema;
  96. }
  97. /**
  98. * Implementation of hook_requirements().
  99. *
  100. */
  101. function tripal_organism_requirements($phase) {
  102. $requirements = array();
  103. if ($phase == 'install') {
  104. // make sure chado is installed
  105. if (!tripal_core_is_chado_installed()) {
  106. $requirements ['tripal_organism'] = array(
  107. 'title' => "tripal_organism",
  108. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  109. 'severity' => REQUIREMENT_ERROR,
  110. );
  111. }
  112. }
  113. return $requirements;
  114. }