tripal_organism.install 3.5 KB

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