tripal_cv.install 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /**
  3. * @file
  4. * Contains functions executed only on install/uninstall of this module
  5. */
  6. /**
  7. * Implementation of hook_install().
  8. *
  9. * @ingroup tripal_cv
  10. */
  11. function tripal_cv_install() {
  12. // create the module's data directory
  13. tripal_create_moddir('tripal_cv');
  14. // Add the materialized view needed to keep track of the
  15. //
  16. $previous_db = tripal_db_set_active('chado');
  17. if (db_table_exists('cv_root_mview')) {
  18. $sql = "DROP TABLE cv_root_mview";
  19. db_query($sql);
  20. }
  21. tripal_db_set_active($previous_db);
  22. // Create the MView
  23. tripal_add_mview(
  24. // view name
  25. 'cv_root_mview',
  26. // module name
  27. 'tripal_cv',
  28. // table name
  29. 'cv_root_mview',
  30. // table schema
  31. 'name character varying(1024), cvterm_id integer, cv_id integer,
  32. cv_name character varying(255)',
  33. // indexed columns
  34. 'cvterm_id, cv_id',
  35. // SQL statement that populates the view
  36. 'SELECT DISTINCT CVT.name,CVT.cvterm_id, CV.cv_id, CV.name
  37. FROM {cvterm_relationship} CVTR
  38. INNER JOIN cvterm CVT on CVTR.object_id = CVT.cvterm_id
  39. INNER JOIN CV on CV.cv_id = CVT.cv_id
  40. WHERE CVTR.object_id not in
  41. (SELECT subject_id FROM {cvterm_relationship}) ',
  42. // special index
  43. ''
  44. );
  45. // create the tables that correlate OBO files/references with a chado CV
  46. drupal_install_schema('tripal_cv');
  47. tripal_cv_add_obo_defaults();
  48. }
  49. /**
  50. * This update adds the new tripal_obo table. This is an upgrade from
  51. * Tripal version 0.2
  52. *
  53. * @ingroup tripal_cv
  54. */
  55. function tripal_cv_update_6000() {
  56. drupal_install_schema('tripal_cv');
  57. tripal_cv_add_obo_defaults();
  58. $ret = array(
  59. '#finished' => 1,
  60. );
  61. return $ret;
  62. }
  63. /**
  64. * Implementation of hook_uninstall().
  65. *
  66. * @ingroup tripal_cv
  67. */
  68. function tripal_cv_uninstall() {
  69. // remove the materialized view
  70. $mview = tripal_mviews_get_mview_id('cv_root_mview');
  71. if ($mview) {
  72. tripal_mviews_action('delete', $mview);
  73. }
  74. drupal_uninstall_schema('tripal_cv');
  75. }
  76. /**
  77. * Implementation of hook_schema().
  78. *
  79. * @ingroup tripal_cv
  80. */
  81. function tripal_cv_schema() {
  82. $schema = tripal_cv_get_schemas();
  83. return $schema;
  84. }
  85. /**
  86. * This function simply defines all tables needed for the module to work
  87. * correctly. By putting the table definitions in a separate function we
  88. * can easily provide the entire list for hook_install or individual
  89. * tables for an update.
  90. *
  91. * @ingroup tripal_cv
  92. */
  93. function tripal_cv_get_schemas() {
  94. $schema = array();
  95. $schema['tripal_cv_obo'] = array(
  96. 'fields' => array(
  97. 'obo_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
  98. 'name' => array('type' => 'varchar', 'length' => 255),
  99. 'path' => array('type' => 'varchar', 'length' => 1024),
  100. ),
  101. 'indexes' => array(
  102. 'obo_id' => array('obo_id'),
  103. ),
  104. 'primary key' => array('obo_id'),
  105. );
  106. return $schema;
  107. }
  108. /**
  109. * Add's defaults to the tripal_cv_obo table
  110. *
  111. * @ingroup tripal_cv
  112. */
  113. function tripal_cv_add_obo_defaults() {
  114. // insert commonly used ontologies into the tables
  115. $ontologies = array(
  116. array('Chado Feature Properties', drupal_get_path('module', 'tripal_cv') . '/feature_property.obo'),
  117. array('Relationship Ontology', 'http://www.obofoundry.org/ro/ro.obo'),
  118. array('Sequence Ontology', 'http://song.cvs.sourceforge.net/*checkout*/song/ontology/so.obo'),
  119. array('Gene Ontology', 'http://www.geneontology.org/ontology/gene_ontology.obo'),
  120. array('Cell Ontology', 'http://obo.cvs.sourceforge.net/obo/obo/ontology/anatomy/cell_type/cell.obo?rev=HEAD'),
  121. array('Plant Structure Ontology', 'http://palea.cgrb.oregonstate.edu/viewsvn/Poc/trunk/ontology/OBO_format/po_anatomy.obo?view=co'),
  122. array('Plant Growth and Development Stages Ontology', 'http://palea.cgrb.oregonstate.edu/viewsvn/Poc/trunk/ontology/OBO_format/po_temporal.obo?view=co')
  123. );
  124. foreach ($ontologies as $o) {
  125. db_query(
  126. "INSERT INTO {tripal_cv_obo} (name,path) VALUES ('%s','%s')",
  127. $o[0],
  128. $o[1]
  129. );
  130. }
  131. }
  132. /**
  133. * Implementation of hook_requirements().
  134. */
  135. function tripal_cv_requirements($phase) {
  136. $requirements = array();
  137. if ($phase == 'install') {
  138. // make sure chado is installed
  139. $version = tripal_core_set_chado_version();
  140. if ($version == 'not installed') {
  141. $requirements ['tripal_cv'] = array(
  142. 'title' => "tripal_cv",
  143. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  144. 'severity' => REQUIREMENT_ERROR,
  145. );
  146. }
  147. }
  148. return $requirements;
  149. }