tripal_library.install 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * @file
  4. * @todo Add file header description
  5. */
  6. /**
  7. * Implementation of hook_install().
  8. *
  9. * @ingroup tripal_library
  10. */
  11. function tripal_library_install() {
  12. // create the module's data directory
  13. tripal_create_moddir('tripal_library');
  14. // create the tables that correlate drupal nodes with chado
  15. // features, librarys, etc....
  16. drupal_install_schema('tripal_library');
  17. // Add the materialized view needed to count the features for the library
  18. // Create the MView
  19. tripal_add_mview('library_feature_count', 'tripal_library',
  20. 'library_feature_count',
  21. 'library_id integer, name character varying(255), '.
  22. ' num_features integer, feature_type character varying(255)',
  23. 'library_id',
  24. 'SELECT '.
  25. ' L.library_id, '.
  26. ' L.name, '.
  27. ' count(F.feature_id) as num_features, '.
  28. ' CVT.name as feature_type '.
  29. 'FROM Library L '.
  30. ' INNER JOIN Library_Feature LF ON LF.library_id = L.library_id '.
  31. ' INNER JOIN Feature F ON LF.feature_id = F.feature_id '.
  32. ' INNER JOIN Cvterm CVT ON F.type_id = CVT.cvterm_id '.
  33. 'GROUP BY L.library_id, L.name, CVT.name',
  34. ''
  35. );
  36. // Add cvterms
  37. tripal_library_add_cvterms();
  38. }
  39. /**
  40. * Implementation of hook_schema().
  41. *
  42. * @ingroup tripal_library
  43. */
  44. function tripal_library_schema() {
  45. $schema = tripal_library_get_schemas();
  46. return $schema;
  47. }
  48. /**
  49. * Implementation of hook_uninstall().
  50. *
  51. * @ingroup tripal_library
  52. */
  53. function tripal_library_uninstall() {
  54. drupal_uninstall_schema('tripal_library');
  55. // remove the materialized view
  56. $sql = "SELECT * FROM {tripal_mviews} ".
  57. "WHERE name = 'library_feature_count'";
  58. if (db_table_exists('tripal_mviews')) {
  59. $mview = db_fetch_object(db_query($sql));
  60. if ($mview) {
  61. tripal_mviews_action('delete', $mview->mview_id);
  62. }
  63. }
  64. // Get the list of nodes to remove
  65. $sql_lib_id = "SELECT nid, vid ".
  66. "FROM {node} ".
  67. "WHERE type='chado_library'";
  68. $result = db_query($sql_lib_id);
  69. while ($node = db_fetch_object($result)) {
  70. node_delete($node->nid);
  71. }
  72. }
  73. /**
  74. * This function simply defines all tables needed for the module to work
  75. * correctly. By putting the table definitions in a separate function we
  76. * can easily provide the entire list for hook_install or individual
  77. * tables for an update.
  78. *
  79. * @ingroup tripal_library
  80. */
  81. function tripal_library_get_schemas() {
  82. $schema = array();
  83. $schema['chado_library'] = array(
  84. 'fields' => array(
  85. 'vid' => array(
  86. 'type' => 'int',
  87. 'unsigned' => TRUE,
  88. 'not null' => TRUE,
  89. 'default' => 0
  90. ),
  91. 'nid' => array(
  92. 'type' => 'int',
  93. 'unsigned' => TRUE,
  94. 'not null' => TRUE,
  95. 'default' => 0
  96. ),
  97. 'library_id' => array(
  98. 'type' => 'int',
  99. 'not null' => TRUE,
  100. 'default' => 0
  101. )
  102. ),
  103. 'indexes' => array(
  104. 'library_id' => array('library_id')
  105. ),
  106. 'unique keys' => array(
  107. 'nid_vid' => array('nid', 'vid'),
  108. 'vid' => array('vid')
  109. ),
  110. 'primary key' => array('nid'),
  111. );
  112. return $schema;
  113. }
  114. /**
  115. * Implementation of hook_requirements().
  116. */
  117. function tripal_library_requirements($phase) {
  118. $requirements = array();
  119. if ($phase == 'install') {
  120. // make sure chado is installed
  121. if (!tripal_core_is_chado_installed()) {
  122. $requirements ['tripal_library'] = array(
  123. 'title' => "tripal_library",
  124. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  125. 'severity' => REQUIREMENT_ERROR,
  126. );
  127. }
  128. }
  129. return $requirements;
  130. }
  131. /*
  132. *
  133. */
  134. function tripal_library_add_cvterms() {
  135. // Insert cvterm 'library_description' into cvterm table of chado
  136. // database. This CV term is used to keep track of the library
  137. // description in the libraryprop table.
  138. tripal_cv_add_cvterm(array('name' => 'library_description', 'def' => 'Description of a library'),
  139. 'tripal', 0, 1, 'tripal');
  140. // add cvterms for the map unit types
  141. tripal_cv_add_cvterm(array('name' => 'cdna_library','def' => 'cDNA library'),
  142. 'tripal_library_types', 0, 1, 'tripal');
  143. tripal_cv_add_cvterm(array('name' => 'bac_library','def' => 'Bacterial Artifical Chromsome (BAC) library'),
  144. 'tripal_library_types', 0, 1, 'tripal');
  145. tripal_cv_add_cvterm(array('name' => 'fosmid_library','def' => 'Fosmid library'),
  146. 'tripal_library_types', 0, 1, 'tripal');
  147. tripal_cv_add_cvterm(array('name' => 'cosmid_library','def' => 'Cosmid library'),
  148. 'tripal_library_types', 0, 1, 'tripal');
  149. tripal_cv_add_cvterm(array('name' => 'yac_library','def' => 'Yeast Artificial Chromosome (YAC) library'),
  150. 'tripal_library_types', 0, 1, 'tripal');
  151. tripal_cv_add_cvterm(array('name' => 'genomic_library','def' => 'Genomic Library'),
  152. 'tripal_library_types', 0, 1, 'tripal');
  153. }
  154. /**
  155. * Update for Drupal 6.x, Tripal 1.0
  156. * This update
  157. * - adds the library types
  158. *
  159. * @ingroup tripal_library
  160. */
  161. function tripal_library_update_6000() {
  162. // add in the missing library typ cv terms
  163. tripal_library_add_cvterms();
  164. return $ret;
  165. }