tripal_cv.install 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /*******************************************************************************
  3. * Implementation of hook_install();
  4. */
  5. function tripal_cv_install(){
  6. // create the module's data directory
  7. tripal_create_moddir('tripal_cv');
  8. // Add the materialized view needed to keep track of the
  9. //
  10. $previous_db = db_set_active('chado');
  11. if (db_table_exists('cv_root_mview')) {
  12. $sql = "DROP TABLE cv_root_mview";
  13. db_query($sql);
  14. }
  15. db_set_active($previous_db);
  16. // Create the MView
  17. tripal_add_mview(
  18. // view name
  19. 'cv_root_mview',
  20. // module name
  21. 'tripal_cv',
  22. // table name
  23. 'cv_root_mview',
  24. // table schema
  25. 'name character varying(1024), cvterm_id integer, cv_id integer,
  26. cv_name character varying(255)',
  27. // indexed columns
  28. 'cvterm_id, cv_id',
  29. // SQL statement that populates the view
  30. 'SELECT DISTINCT CVT.name,CVT.cvterm_id, CV.cv_id, CV.name
  31. FROM {cvterm_relationship} CVTR
  32. INNER JOIN cvterm CVT on CVTR.object_id = CVT.cvterm_id
  33. INNER JOIN CV on CV.cv_id = CVT.cv_id
  34. WHERE CVTR.object_id not in
  35. (SELECT subject_id FROM {cvterm_relationship}) ',
  36. // special index
  37. ''
  38. );
  39. // create the tables that correlate OBO files/references with a chado CV
  40. drupal_install_schema('tripal_cv');
  41. }
  42. /*******************************************************************************
  43. * This update adds the new tripal_obo table. This is an upgrade from
  44. * Tripal version 0.2
  45. */
  46. function tripal_cv_update_6000(){
  47. drupal_install_schema('tripal_cv');
  48. $ret = array(
  49. '#finished' => 1,
  50. );
  51. return $ret;
  52. }
  53. /************************************************************************
  54. * Implementation of hook_schema().
  55. */
  56. function tripal_cv_schema() {
  57. $schema = tripal_cv_get_schemas();
  58. return $schema;
  59. }
  60. /*******************************************************************************
  61. * Implementation of hook_uninstall()
  62. */
  63. function tripal_cv_uninstall(){
  64. // remove the materialized view
  65. $mview = tripal_mviews_get_mview_id('cv_root_mview');
  66. if($mview){
  67. tripal_mviews_action('delete',$mview);
  68. }
  69. drupal_uninstall_schema('tripal_cv');
  70. }
  71. /*******************************************************************************
  72. * Implementation of hook_requirements(). Make sure 'Tripal Core' is enabled
  73. * before installation
  74. */
  75. function tripal_cv_requirements($phase) {
  76. $requirements = array();
  77. if ($phase == 'install') {
  78. if (!function_exists('tripal_create_moddir')) {
  79. $requirements ['tripal_cv'] = array(
  80. 'title' => "tripal_cv",
  81. 'value' => "Required modules must be installed first before Tripal CV module can be installed",
  82. 'severity' => REQUIREMENT_ERROR,
  83. );
  84. }
  85. }
  86. return $requirements;
  87. }
  88. /************************************************************************
  89. * This function simply defines all tables needed for the module to work
  90. * correctly. By putting the table definitions in a separate function we
  91. * can easily provide the entire list for hook_install or individual
  92. * tables for an update.
  93. */
  94. function tripal_cv_get_schemas (){
  95. $schema = array();
  96. $schema['tripal_obo'] = array(
  97. 'fields' => array(
  98. 'cv_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
  99. 'file' => array('type' => 'varchar','length' => 1024),
  100. 'url' => array('type' => 'varchar','length' => 1024),
  101. ),
  102. 'indexes' => array(
  103. 'cv_id' => array('cv_id')
  104. ),
  105. 'primary key' => array('cv_id'),
  106. );
  107. return $schema;
  108. }