tripal_cv.install 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. }
  40. /*******************************************************************************
  41. * Implementation of hook_uninstall()
  42. */
  43. function tripal_cv_uninstall(){
  44. // remove the materialized view
  45. $mview = tripal_mviews_get_mview_id('cv_root_mview');
  46. if($mview){
  47. tripal_mviews_action('delete',$mview);
  48. }
  49. }
  50. /*******************************************************************************
  51. * Implementation of hook_requirements(). Make sure 'Tripal Core' is enabled
  52. * before installation
  53. */
  54. function tripal_cv_requirements($phase) {
  55. $requirements = array();
  56. if ($phase == 'install') {
  57. if (!function_exists('tripal_create_moddir')) {
  58. $requirements ['tripal_cv'] = array(
  59. 'title' => "tripal_cv",
  60. 'value' => "Required modules must be installed first before Tripal CV module can be installed",
  61. 'severity' => REQUIREMENT_ERROR,
  62. );
  63. }
  64. }
  65. return $requirements;
  66. }