tripal_organism.install

  1. 2.x tripal_organism/tripal_organism.install
  2. 3.x legacy/tripal_organism/tripal_organism.install
  3. 1.x tripal_organism/tripal_organism.install

Functions pertaining to the install/uninstall of this module

File

tripal_organism/tripal_organism.install
View source
  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. }