tripal_organism.install 3.3 KB

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