tripal_analysis.install 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. //$Id:
  3. /*******************************************************************************
  4. * Implementation of hook_install().
  5. */
  6. function tripal_analysis_install() {
  7. // create the module's data directory
  8. tripal_create_moddir('tripal_analysis');
  9. // Use schema API to create database table.
  10. drupal_install_schema('tripal_analysis');
  11. // Create analysisfeatureprop table in chado. This cannot be accomplished
  12. // by calling drupal_install_schema because it's not in the drupal db. This
  13. // table is used to store Blast xml and Interpro html/goterms
  14. $previous_db = tripal_db_set_active('chado');
  15. if (!db_table_exists('analysisfeatureprop')) {
  16. $sql = "CREATE TABLE {analysisfeatureprop} (".
  17. " analysisfeatureprop_id SERIAL PRIMARY KEY, ".
  18. " analysisfeature_id INTEGER NOT NULL REFERENCES analysisfeature(analysisfeature_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, ".
  19. " type_id INTEGER NOT NULL REFERENCES cvterm(cvterm_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, ".
  20. " value TEXT, ".
  21. " rank INTEGER NOT NULL, ".
  22. " CONSTRAINT analysisfeature_id_type_id_rank UNIQUE(analysisfeature_id, type_id, rank)".
  23. ")";
  24. db_query($sql);
  25. }
  26. tripal_db_set_active($previous_db);
  27. tripal_add_cvterms('analysis_type','The type of analysis was performed. This value is automatically set by each Tripal Analysis module and should be equal to the module name (e.g. tripal_analysis_blast, tripal_analysis_go).');
  28. tripal_add_cvterms('analysis_date','The date that an analysis was performed.');
  29. tripal_add_cvterms('analysis_short_name','A computer legible (no spaces '.
  30. 'or special characters) abbreviation for the analysis.');
  31. }
  32. /*******************************************************************************
  33. * Implementation of hook_uninstall().
  34. */
  35. function tripal_analysis_uninstall() {
  36. // Use schema API to delete database table.
  37. drupal_uninstall_schema('tripal_analysis');
  38. // Remove analysis nodes from drupal.
  39. $sql_ana_id = "SELECT nid, vid ".
  40. "FROM {node} ".
  41. "WHERE type like 'chado_analysi%'";
  42. $result = db_query($sql_ana_id);
  43. while ($ana = db_fetch_object($result)) {
  44. node_delete($ana->nid);
  45. }
  46. }
  47. /*******************************************************************************
  48. * Implementation of hook_schema() creates two tables. chado_analysis table
  49. * stores nodes that are also saved in the analysis table of chado database.
  50. * tripal_analysis table stores the sub-module names, such as
  51. * tripal_analysis_blast, that are registered with this module.
  52. */
  53. function tripal_analysis_schema() {
  54. // chado_analysis table
  55. $schema['chado_analysis'] = array(
  56. 'fields' => array(
  57. 'vid' => array(
  58. 'type' => 'int',
  59. 'unsigned' => TRUE,
  60. 'not null' => TRUE,
  61. 'default' => 0
  62. ),
  63. 'nid' => array(
  64. 'type' => 'int',
  65. 'unsigned' => TRUE,
  66. 'not null' => TRUE,
  67. 'default' => 0
  68. ),
  69. 'analysis_id' => array(
  70. 'type' => 'int',
  71. 'not null' => TRUE,
  72. 'default' => 0
  73. )
  74. ),
  75. 'indexes' => array(
  76. 'analysis_id' => array('analysis_id')
  77. ),
  78. 'unique keys' => array(
  79. 'nid_vid' => array('nid','vid'),
  80. 'vid' => array('vid')
  81. ),
  82. 'primary key' => array('nid'),
  83. );
  84. // tripal_analysis table
  85. $schema['tripal_analysis'] = array(
  86. 'description' => t('Table to store analysis sub-modules'),
  87. 'fields' => array(
  88. 'modulename' => array(
  89. 'type' => 'text',
  90. 'size' => 'small',
  91. 'not null' => TRUE,
  92. 'description' => t('The module name. Tripal Analysis will use the '.
  93. 'module name to call module_setting_form()')
  94. )
  95. ),
  96. 'unique keys' => array(
  97. 'modulename' => array('modulename')
  98. )
  99. );
  100. return $schema;
  101. }
  102. /*******************************************************************************
  103. * Implementation of hook_requirements(). Make sure 'Tripal Core' is enabled
  104. * before installation
  105. */
  106. function tripal_analysis_requirements($phase) {
  107. $requirements = array();
  108. if ($phase == 'install') {
  109. if (!function_exists('tripal_create_moddir')) {
  110. $requirements ['tripal_analysis'] = array(
  111. 'title' => "tripal_analysis",
  112. 'value' => "error. Some required modules are just being installed. Please try again.",
  113. 'severity' => REQUIREMENT_ERROR,
  114. );
  115. }
  116. }
  117. return $requirements;
  118. }