tripal_stock.install 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. /**
  3. * Install the tripal stock module including it's content type
  4. * @file
  5. */
  6. /**
  7. * Implements hook_disable().
  8. * Disable default views when module is disabled
  9. *
  10. * @ingroup tripal_stock
  11. */
  12. function tripal_stock_disable() {
  13. // Disable all default views provided by this module
  14. require_once("tripal_stock.views_default.inc");
  15. $views = tripal_stock_views_default_views();
  16. foreach (array_keys($views) as $view_name) {
  17. tripal_views_admin_disable_view($view_name,FALSE,array('suppress_error' => TRUE));
  18. }
  19. }
  20. /**
  21. * Implementation of hook_requirements().
  22. *
  23. * @ingroup tripal_stock
  24. */
  25. function tripal_stock_requirements($phase) {
  26. $requirements = array();
  27. if ($phase == 'install') {
  28. // make sure chado is installed
  29. if (!$GLOBALS["chado_is_installed"]) {
  30. $requirements ['tripal_stock'] = array(
  31. 'title' => "tripal_stock",
  32. 'value' => "ERROR: Chado must be installed before this module can be enabled",
  33. 'severity' => REQUIREMENT_ERROR,
  34. );
  35. }
  36. }
  37. return $requirements;
  38. }
  39. /**
  40. * Implementation of hook_install().
  41. *
  42. * @ingroup tripal_stock
  43. */
  44. function tripal_stock_install() {
  45. // create the module's data directory
  46. tripal_create_files_dir('tripal_stock');
  47. // set the default vocabularies
  48. tripal_set_default_cv('stock', 'type_id', 'stock_type');
  49. tripal_set_default_cv('stockprop', 'type_id', 'stock_property');
  50. tripal_set_default_cv('stock_relationship', 'type_id', 'stock_relationship');
  51. }
  52. /**
  53. * Implementation of hook_uninstall().
  54. *
  55. * @ingroup tripal_stock
  56. */
  57. function tripal_stock_uninstall() {
  58. }
  59. /**
  60. * Implementation of hook_schema().
  61. *
  62. * @ingroup tripal_stock
  63. */
  64. function tripal_stock_schema() {
  65. $schema['chado_stock'] = array(
  66. 'fields' => array(
  67. 'vid' => array(
  68. 'type' => 'int',
  69. 'unsigned' => TRUE,
  70. 'not null' => TRUE,
  71. ),
  72. 'nid' => array(
  73. 'type' => 'int',
  74. 'unsigned' => TRUE,
  75. 'not null' => TRUE,
  76. ),
  77. 'stock_id' => array(
  78. 'type' => 'int',
  79. 'unsigned' => TRUE,
  80. 'not null' => TRUE,
  81. ),
  82. ),
  83. 'indexes' => array(
  84. 'stock_id' => array('stock_id'),
  85. 'nid' => array('nid'),
  86. ),
  87. 'unique' => array(
  88. 'stock_id' => array('stock_id'),
  89. ),
  90. 'primary key' => array('vid'),
  91. );
  92. return $schema;
  93. }
  94. /**
  95. * Add cvs related to publications
  96. *
  97. * @ingroup tripal_pub
  98. */
  99. function tripal_stock_add_cvs() {
  100. // Add cv for relationship types
  101. tripal_cv_add_cv(
  102. 'stock_relationship',
  103. 'Contains types of relationships between stocks.'
  104. );
  105. tripal_cv_add_cv(
  106. 'stock_property',
  107. 'Contains properties for stocks.'
  108. );
  109. tripal_cv_add_cv(
  110. 'stock_type',
  111. 'Contains a list of types for stocks.'
  112. );
  113. }
  114. /**
  115. * Add cvterms related to publications
  116. *
  117. * @ingroup tripal_pub
  118. */
  119. function tripal_stock_add_cvterms() {
  120. }
  121. /**
  122. * This is the required update for tripal_stock when upgrading from Drupal core API 6.x.
  123. *
  124. */
  125. function tripal_stock_update_7200() {
  126. // add the new CVs. We can't use the Tripal API because during
  127. // an upgrade from D6 to D7 Tripal is disable. So, we have to manually add these
  128. // new vocabularies.
  129. // add the stock_relationshp CV
  130. try {
  131. $check = db_query("SELECT cv_id FROM chado.cv WHERE name = 'stock_relationship'")->fetchObject();
  132. if (!$check->cv_id) {
  133. // add the vocabulary
  134. $cv_id = db_insert('chado.cv')
  135. ->fields(array(
  136. 'name' => 'stock_relationship',
  137. 'definition' => 'Contains types of relationships between stocks.'
  138. ))
  139. ->execute();
  140. // make this the default cv for the stock_relationships.type_id field
  141. db_insert('tripal_cv_defaults')
  142. ->fields(array(
  143. 'table_name' => 'stock_relationship',
  144. 'field_name' => 'type_id',
  145. 'cv_id' => $cv_id
  146. ))
  147. ->execute();
  148. }
  149. }
  150. catch (\PDOException $e) {
  151. $error = $e->getMessage();
  152. throw new DrupalUpdateException('Failed to add stock_relationship vocabulary: '. $error);
  153. }
  154. // add the stock_property CV
  155. try {
  156. $check = db_query("SELECT cv_id FROM chado.cv WHERE name = 'stock_property'")->fetchObject();
  157. if (!$check->cv_id) {
  158. // add the vocabulary
  159. $cv_id = db_insert('chado.cv')
  160. ->fields(array(
  161. 'name' => 'stock_property',
  162. 'definition' => 'Contains properties for stocks.'
  163. ))
  164. ->execute();
  165. // make this the default vocabulary for the stockprop.type_id field
  166. db_insert('tripal_cv_defaults')
  167. ->fields(array(
  168. 'table_name' => 'stockprop',
  169. 'field_name' => 'type_id',
  170. 'cv_id' => $cv_id
  171. ))
  172. ->execute();
  173. }
  174. }
  175. catch (\PDOException $e) {
  176. $error = $e->getMessage();
  177. throw new DrupalUpdateException('Failed to add stock_property vocabulary: '. $error);
  178. }
  179. // add the stock_type CV
  180. try {
  181. $check = db_query("SELECT cv_id FROM chado.cv WHERE name = 'stock_type'")->fetchObject();
  182. if (!$check->cv_id) {
  183. // add the vocabulary
  184. $cv_id = db_insert('chado.cv')
  185. ->fields(array(
  186. 'name' => 'stock_type',
  187. 'definition' => 'Contains a list of types for stocks.'
  188. ))
  189. ->execute();
  190. // add this vocabulary as the default cv for stock.type_id
  191. db_insert('tripal_cv_defaults')
  192. ->fields(array(
  193. 'table_name' => 'stock',
  194. 'field_name' => 'type_id',
  195. 'cv_id' => $cv_id
  196. ))
  197. ->execute();
  198. }
  199. }
  200. catch (\PDOException $e) {
  201. $error = $e->getMessage();
  202. throw new DrupalUpdateException('Failed to add stock_type vocabulary: '. $error);
  203. }
  204. }