tripal_cv.install

  1. 2.x tripal_cv/tripal_cv.install
  2. 3.x legacy/tripal_cv/tripal_cv.install
  3. 1.x tripal_cv/tripal_cv.install

Contains functions executed only on install/uninstall of this module

File

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