tripal_pub.install 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?php
  2. /**
  3. * @file
  4. * Installation of the publication module
  5. */
  6. /**
  7. * Implements hook_disable().
  8. * Disable default views when module is disabled
  9. *
  10. * @ingroup tripal_pub
  11. */
  12. function tripal_pub_disable() {
  13. // Disable all default views provided by this module
  14. require_once("tripal_pub.views_default.inc");
  15. $views = tripal_pub_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_pub
  24. */
  25. function tripal_pub_requirements($phase) {
  26. $requirements = array();
  27. if ($phase == 'install') {
  28. // make sure chado is installed
  29. if (!$GLOBALS["chado_is_installed"]) {
  30. $requirements ['tripal_pub'] = array(
  31. 'title' => "tripal_pub",
  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_pub
  43. */
  44. function tripal_pub_install() {
  45. global $base_path;
  46. // create the module's data directory
  47. tripal_create_files_dir('tripal_pub');
  48. // add loading of the the tripal pub ontology to the job queue
  49. $obo_path = drupal_realpath(drupal_get_path('module', 'tripal_pub') . '/files/tpub.obo');
  50. $obo_id = tripal_cv_add_obo_ref('Tripal Publication', $obo_path);
  51. tripal_cv_submit_obo_job($obo_id);
  52. tripal_pub_add_cvs();
  53. tripal_pub_add_cvterms();
  54. // add the custom tables
  55. tripal_pub_add_custom_tables();
  56. }
  57. /**
  58. * Implementation of hook_uninstall().
  59. *
  60. * @ingroup tripal_pub
  61. */
  62. function tripal_pub_uninstall() {
  63. }
  64. /**
  65. * Implements hook_enable().
  66. *
  67. * @ingroup tripal_pub
  68. */
  69. function tripal_pub_enable() {
  70. // make sure we have our supported databases
  71. tripal_db_add_db('PMID', 'PubMed', 'http://www.ncbi.nlm.nih.gov/pubmed', 'http://www.ncbi.nlm.nih.gov/pubmed/', TRUE);
  72. tripal_db_add_db('AGL', 'USDA National Agricultural Library', 'http://agricola.nal.usda.gov/', '', TRUE);
  73. variable_set('tripal_pub_supported_dbs', array('PMID', 'AGL'));
  74. }
  75. /**
  76. * Implementation of hook_schema().
  77. *
  78. * @ingroup tripal_pub
  79. */
  80. function tripal_pub_schema() {
  81. $schema['chado_pub'] = array(
  82. 'fields' => array(
  83. 'vid' => array(
  84. 'type' => 'int',
  85. 'unsigned' => TRUE,
  86. 'not null' => TRUE, 'default' => 0
  87. ),
  88. 'nid' => array(
  89. 'type' => 'int',
  90. 'unsigned' => TRUE,
  91. 'not null' => TRUE,
  92. 'default' => 0
  93. ),
  94. 'pub_id' => array(
  95. 'type' => 'int',
  96. 'not null' => TRUE,
  97. 'default' => 0
  98. ),
  99. 'sync_date' => array(
  100. 'type' => 'int',
  101. 'not null' => FALSE,
  102. 'description' => 'UNIX integer sync date/time'
  103. ),
  104. ),
  105. 'indexes' => array(
  106. 'pub_id' => array('pub_id')
  107. ),
  108. 'unique keys' => array(
  109. 'nid_vid' => array('nid', 'vid'),
  110. 'vid' => array('vid')
  111. ),
  112. 'primary key' => array('nid'),
  113. );
  114. $schema['tripal_pub_import'] = array(
  115. 'fields' => array(
  116. 'pub_import_id' => array(
  117. 'type' => 'serial',
  118. 'not null' => TRUE
  119. ),
  120. 'name' => array(
  121. 'type' => 'varchar',
  122. 'length' => 255,
  123. 'not null' => TRUE
  124. ),
  125. 'criteria' => array(
  126. 'type' => 'text',
  127. 'size' => 'normal',
  128. 'not null' => TRUE,
  129. 'description' => 'Contains a serialized PHP array containing the search criteria'
  130. ),
  131. 'disabled' => array(
  132. 'type' => 'int',
  133. 'unsigned' => TRUE,
  134. 'not NULL' => TRUE,
  135. 'default' => 0
  136. ),
  137. 'do_contact' => array(
  138. 'type' => 'int',
  139. 'unsigned' => TRUE,
  140. 'not NULL' => TRUE,
  141. 'default' => 0
  142. ),
  143. ),
  144. 'primary key' => array('pub_import_id'),
  145. 'indexes' => array(
  146. 'name' => array('name')
  147. ),
  148. );
  149. return $schema;
  150. }
  151. /**
  152. * Add custom table related to publications
  153. * - pubauthor_contact
  154. *
  155. * @ingroup tripal_pub
  156. */
  157. function tripal_pub_add_custom_tables() {
  158. $schema = array (
  159. 'table' => 'pubauthor_contact',
  160. 'fields' => array (
  161. 'pubauthor_contact_id' => array (
  162. 'type' => 'serial',
  163. 'not null' => true,
  164. ),
  165. 'contact_id' => array (
  166. 'type' => 'int',
  167. 'not null' => true,
  168. ),
  169. 'pubauthor_id' => array (
  170. 'type' => 'int',
  171. 'not null' => true,
  172. ),
  173. ),
  174. 'primary key' => array (
  175. 0 => 'pubauthor_contact_id',
  176. ),
  177. 'unique keys' => array (
  178. 'pubauthor_contact_c1' => array (
  179. 0 => 'contact_id',
  180. 1 => 'pubauthor_id',
  181. ),
  182. ),
  183. 'foreign keys' => array (
  184. 'contact' => array (
  185. 'table' => 'contact',
  186. 'columns' => array (
  187. 'contact_id' => 'contact_id',
  188. ),
  189. ),
  190. 'pubauthor' => array (
  191. 'table' => 'pubauthor',
  192. 'columns' => array (
  193. 'pubauthor_id' => 'pubauthor_id',
  194. ),
  195. ),
  196. ),
  197. );
  198. chado_create_custom_table('pubauthor_contact', $schema, TRUE);
  199. }
  200. /**
  201. * Add cvs related to publications
  202. *
  203. * @ingroup tripal_pub
  204. */
  205. function tripal_pub_add_cvs() {
  206. // Add cv for relationship types
  207. tripal_cv_add_cv(
  208. 'pub_relationship_types',
  209. 'Contains Types of relationships between publications.'
  210. );
  211. }
  212. /**
  213. * Add cvterms related to publications
  214. *
  215. * @ingroup tripal_pub
  216. */
  217. function tripal_pub_add_cvterms() {
  218. }
  219. /**
  220. * This is the required update for tripal_contact when upgrading from Drupal core API 6.x.
  221. *
  222. * @ingroup tripal_pub
  223. */
  224. function tripal_pub_update_7200() {
  225. // add the new pub_relationship_types vocabulary
  226. // We cannot use the Tripal API calls in the 7000 update
  227. // because during upgrade the tripal_core should also be disabled
  228. try {
  229. $check = db_query("SELECT cv_id FROM chado.cv WHERE name = 'pub_relationship_types'")->fetchObject();
  230. if (!$check->cv_id) {
  231. $sql = "INSERT INTO chado.cv (name, definition) VALUES (
  232. 'pub_relationship_types',
  233. 'Contains Types of relationships between publications.')
  234. ";
  235. db_query($sql);
  236. }
  237. }
  238. catch (\PDOException $e) {
  239. $error = $e->getMessage();
  240. throw new DrupalUpdateException('Failed to add pub_relationship_types vocabulary: '. $error);
  241. }
  242. }