tripal_organism.install 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. tripal_create_mod_subdir('tripal_organism', '/images');
  16. }
  17. /**
  18. * Implementation of hook_schema().
  19. *
  20. * @ingroup tripal_organism
  21. */
  22. function tripal_organism_schema() {
  23. $schema['chado_organism'] = array(
  24. 'fields' => array(
  25. 'vid' => array(
  26. 'type' => 'int',
  27. 'unsigned' => TRUE,
  28. 'not null' => TRUE,
  29. 'default' => 0
  30. ),
  31. 'nid' => array(
  32. 'type' => 'int',
  33. 'unsigned' => TRUE,
  34. 'not null' => TRUE,
  35. 'default' => 0
  36. ),
  37. 'organism_id' => array(
  38. 'type' => 'int',
  39. 'not null' => TRUE,
  40. 'default' => 0
  41. )
  42. ),
  43. 'indexes' => array(
  44. 'organism_id' => array('organism_id')
  45. ),
  46. 'unique keys' => array(
  47. 'nid_vid' => array('nid', 'vid'),
  48. 'vid' => array('vid')
  49. ),
  50. 'primary key' => array('nid'),
  51. );
  52. return $schema;
  53. }
  54. /**
  55. * Implementation of hook_uninstall().
  56. *
  57. * @ingroup tripal_organism
  58. */
  59. function tripal_organism_uninstall() {
  60. // Get the list of nodes to remove
  61. $sql_lib_id = "
  62. SELECT nid, vid
  63. FROM {node}
  64. WHERE type='chado_organism'
  65. ";
  66. $result = db_query($sql_lib_id);
  67. foreach ($result as $node) {
  68. node_delete($node->nid);
  69. }
  70. }
  71. /**
  72. * Implementation of hook_requirements().
  73. *
  74. */
  75. function tripal_organism_requirements($phase) {
  76. $requirements = array();
  77. if ($phase == 'install') {
  78. // make sure chado is installed
  79. if (!tripal_core_is_chado_installed()) {
  80. $requirements ['tripal_organism'] = array(
  81. 'title' => "tripal_organism",
  82. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  83. 'severity' => REQUIREMENT_ERROR,
  84. );
  85. }
  86. }
  87. return $requirements;
  88. }