tripal_pub.install

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

Installation of the publication module

File

tripal_pub/tripal_pub.install
View source
  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_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. // add loading of the the tripal pub ontology to the job queue
  47. $obo_path = '{tripal_pub}/files/tpub.obo';
  48. $obo_id = tripal_insert_obo('Tripal Publication', $obo_path);
  49. tripal_submit_obo_job(array('obo_id' => $obo_id));
  50. tripal_pub_add_cvs();
  51. tripal_pub_add_cvterms();
  52. // add the custom tables
  53. tripal_pub_add_custom_tables();
  54. // set the default vocabularies
  55. tripal_set_default_cv('pub', 'type_id', 'tripal_pub');
  56. tripal_set_default_cv('pubprop', 'type_id', 'tripal_pub');
  57. tripal_set_default_cv('pub_relationship', 'type_id', 'pub_relationship');
  58. }
  59. /**
  60. * Implementation of hook_uninstall().
  61. *
  62. * @ingroup tripal_pub
  63. */
  64. function tripal_pub_uninstall() {
  65. }
  66. /**
  67. * Implements hook_enable().
  68. *
  69. * @ingroup tripal_pub
  70. */
  71. function tripal_pub_enable() {
  72. // make sure we have our supported databases
  73. tripal_insert_db(
  74. array(
  75. 'name' => 'PMID',
  76. 'description' => 'PubMed',
  77. 'url' => 'http://www.ncbi.nlm.nih.gov/pubmed',
  78. 'urlprefix' => 'http://www.ncbi.nlm.nih.gov/pubmed/'
  79. ),
  80. array('update_existing' => TRUE)
  81. );
  82. tripal_insert_db(
  83. array(
  84. 'name' => 'AGL',
  85. 'description' => 'USDA National Agricultural Library',
  86. 'url' => 'http://agricola.nal.usda.gov/'
  87. ),
  88. array('update_existing' => TRUE)
  89. );
  90. variable_set('tripal_pub_supported_dbs', array('PMID', 'AGL'));
  91. }
  92. /**
  93. * Implementation of hook_schema().
  94. *
  95. * @ingroup tripal_pub
  96. */
  97. function tripal_pub_schema() {
  98. $schema['chado_pub'] = array(
  99. 'fields' => array(
  100. 'vid' => array(
  101. 'type' => 'int',
  102. 'unsigned' => TRUE,
  103. 'not null' => TRUE, 'default' => 0
  104. ),
  105. 'nid' => array(
  106. 'type' => 'int',
  107. 'unsigned' => TRUE,
  108. 'not null' => TRUE,
  109. 'default' => 0
  110. ),
  111. 'pub_id' => array(
  112. 'type' => 'int',
  113. 'not null' => TRUE,
  114. 'default' => 0
  115. ),
  116. 'sync_date' => array(
  117. 'type' => 'int',
  118. 'not null' => FALSE,
  119. 'description' => 'UNIX integer sync date/time'
  120. ),
  121. ),
  122. 'indexes' => array(
  123. 'pub_id' => array('pub_id')
  124. ),
  125. 'unique keys' => array(
  126. 'nid_vid' => array('nid', 'vid'),
  127. 'vid' => array('vid')
  128. ),
  129. 'primary key' => array('nid'),
  130. );
  131. $schema['tripal_pub_import'] = array(
  132. 'fields' => array(
  133. 'pub_import_id' => array(
  134. 'type' => 'serial',
  135. 'not null' => TRUE
  136. ),
  137. 'name' => array(
  138. 'type' => 'varchar',
  139. 'length' => 255,
  140. 'not null' => TRUE
  141. ),
  142. 'criteria' => array(
  143. 'type' => 'text',
  144. 'size' => 'normal',
  145. 'not null' => TRUE,
  146. 'description' => 'Contains a serialized PHP array containing the search criteria'
  147. ),
  148. 'disabled' => array(
  149. 'type' => 'int',
  150. 'unsigned' => TRUE,
  151. 'not NULL' => TRUE,
  152. 'default' => 0
  153. ),
  154. 'do_contact' => array(
  155. 'type' => 'int',
  156. 'unsigned' => TRUE,
  157. 'not NULL' => TRUE,
  158. 'default' => 0
  159. ),
  160. ),
  161. 'primary key' => array('pub_import_id'),
  162. 'indexes' => array(
  163. 'name' => array('name')
  164. ),
  165. );
  166. return $schema;
  167. }
  168. /**
  169. * Add custom table related to publications
  170. * - pubauthor_contact
  171. *
  172. * @ingroup tripal_pub
  173. */
  174. function tripal_pub_add_custom_tables() {
  175. $schema = array (
  176. 'table' => 'pubauthor_contact',
  177. 'fields' => array (
  178. 'pubauthor_contact_id' => array (
  179. 'type' => 'serial',
  180. 'not null' => true,
  181. ),
  182. 'contact_id' => array (
  183. 'type' => 'int',
  184. 'not null' => true,
  185. ),
  186. 'pubauthor_id' => array (
  187. 'type' => 'int',
  188. 'not null' => true,
  189. ),
  190. ),
  191. 'primary key' => array (
  192. 0 => 'pubauthor_contact_id',
  193. ),
  194. 'unique keys' => array (
  195. 'pubauthor_contact_c1' => array (
  196. 0 => 'contact_id',
  197. 1 => 'pubauthor_id',
  198. ),
  199. ),
  200. 'foreign keys' => array (
  201. 'contact' => array (
  202. 'table' => 'contact',
  203. 'columns' => array (
  204. 'contact_id' => 'contact_id',
  205. ),
  206. ),
  207. 'pubauthor' => array (
  208. 'table' => 'pubauthor',
  209. 'columns' => array (
  210. 'pubauthor_id' => 'pubauthor_id',
  211. ),
  212. ),
  213. ),
  214. );
  215. chado_create_custom_table('pubauthor_contact', $schema, TRUE);
  216. }
  217. /**
  218. * Add cvs related to publications
  219. *
  220. * @ingroup tripal_pub
  221. */
  222. function tripal_pub_add_cvs() {
  223. // Add the cv for pub properties
  224. tripal_insert_cv(
  225. 'tripal_pub',
  226. 'A heirarchical set of terms for describing a publication. It is intended to be used as the default vocabularies in Tripal for publication types and contact properties.'
  227. );
  228. // Add the cv for pub types
  229. tripal_insert_cv(
  230. 'pub_type',
  231. 'Contains types of publications. This can be used if the tripal_pub vocabulary (which is default for publications in Tripal) is not desired.'
  232. );
  233. // Add the cv for pub properties
  234. tripal_insert_cv(
  235. 'pub_property',
  236. 'Contains properties for publications. This can be used if the tripal_pub vocabulary (which is default for publications in Tripal) is not desired.'
  237. );
  238. // Add cv for relationship types
  239. tripal_insert_cv(
  240. 'pub_relationship',
  241. 'Contains types of relationships between publications.'
  242. );
  243. }
  244. /**
  245. * Add cvterms related to publications
  246. *
  247. * @ingroup tripal_pub
  248. */
  249. function tripal_pub_add_cvterms() {
  250. }
  251. /**
  252. * This is the required update for tripal_pub when upgrading from Drupal core API 6.x.
  253. *
  254. */
  255. function tripal_pub_update_7200() {
  256. // Make sure we have the full API loaded this will help during a
  257. // site upgrade when the tripal_core module is disabled.
  258. module_load_include('module', 'tripal_core', 'tripal_core');
  259. tripal_core_import_api();
  260. module_load_include('inc', 'tripal_cv', 'api/tripal_cv.api');
  261. // add the tripal_pub CV and set it to be the default for pub types and pub properties
  262. try {
  263. // First we add the cv.
  264. // Notice that tripal_insert_cv() will only add it if it doesn't exist already.
  265. $cv = tripal_insert_cv(
  266. 'tripal_pub',
  267. 'A heirarchical set of terms for describing a publication. It is intended to be used as the default vocabularies in Tripal for publication types and contact properties.'
  268. );
  269. if ($cv) {
  270. $cv_id = $cv->cv_id;
  271. // Set as Default CV for pub types.
  272. $is_set = tripal_get_default_cv('pub', 'type_id');
  273. if (!$is_set) {
  274. tripal_set_default_cv('pub','type_id', 'tripal_pub', $cv_id);
  275. }
  276. // Set as Default CV for pub properties.
  277. $is_set = tripal_get_default_cv('pub', 'type_id');
  278. if (!$is_set) {
  279. tripal_set_default_cv('pubprop','type_id', 'tripal_pub', $cv_id);
  280. }
  281. }
  282. }
  283. catch (\PDOException $e) {
  284. $error = $e->getMessage();
  285. throw new DrupalUpdateException('Failed to add pub_property vocabulary: '. $error);
  286. }
  287. // add the pub_property CV
  288. try {
  289. tripal_insert_cv(
  290. 'pub_property',
  291. 'Contains properties for publications. This can be used if the tripal_pub vocabulary (which is default for publications in Tripal) is not desired.'
  292. );
  293. }
  294. catch (\PDOException $e) {
  295. $error = $e->getMessage();
  296. throw new DrupalUpdateException('Failed to add pub_property vocabulary: '. $error);
  297. }
  298. // add the pub_type CV
  299. try {
  300. $cv = tripal_insert_cv(
  301. 'pub_type',
  302. 'Contains types of publications. This can be used if the tripal_pub vocabulary (which is default for publications in Tripal) is not desired.'
  303. );
  304. }
  305. catch (\PDOException $e) {
  306. $error = $e->getMessage();
  307. throw new DrupalUpdateException('Failed to add pub_type vocabulary: '. $error);
  308. }
  309. // add the pub_relationship CV
  310. try {
  311. $cv = tripal_insert_cv(
  312. 'pub_relationship',
  313. 'Contains types of relationships between publications.'
  314. );
  315. if ($cv) {
  316. $cv_id = $cv->cv_id;
  317. // Set as Default CV for pub relationships.
  318. $is_set = tripal_get_default_cv('pub_relationship', 'type_id');
  319. if (!$is_set) {
  320. tripal_set_default_cv('pub_relationship','type_id', 'pub_relationship', $cv_id);
  321. }
  322. }
  323. }
  324. catch (\PDOException $e) {
  325. $error = $e->getMessage();
  326. throw new DrupalUpdateException('Failed to add pub_relationship vocabulary: '. $error);
  327. }
  328. }
  329. /**
  330. * Implementation of hook_update_dependencies().
  331. *
  332. * It specifies a list of other modules whose updates must be run prior to
  333. * this one. It also ensures the the Tripal API is in scope for site
  334. * upgrades when tripal_core is disabled.
  335. */
  336. function tripal_pub_update_dependencies() {
  337. $dependencies = array();
  338. // the tripal_cv update 7200 must run prior to update 7200 of this module
  339. $dependencies['tripal_pub'][7200] = array(
  340. 'tripal_cv' => 7200
  341. );
  342. return $dependencies;
  343. }
  344. /**
  345. * Adds missing foreign key constraints
  346. *
  347. */
  348. function tripal_pub_update_7201() {
  349. // Make sure we have the full API loaded this will help during a
  350. // site upgrade when the tripal_core module is disabled.
  351. module_load_include('module', 'tripal_core', 'tripal_core');
  352. tripal_core_import_api();
  353. // there was a bug in the function for creating a custom table that
  354. // kept foreign key constraints from being added. So, we need to add those
  355. // to keep from error messages appear, we will drop the FK if it already
  356. // exists and then re-add it.
  357. try {
  358. $fkey_exists = db_query('SELECT TRUE FROM pg_constraint WHERE conname = :constraint', array(':constraint' => 'pubauthor_contact_pubauthor_id_fkey'))->fetchField();
  359. if ($fkey_exists) {
  360. chado_query('
  361. ALTER TABLE {pubauthor_contact}
  362. DROP CONSTRAINT pubauthor_contact_pubauthor_id_fkey CASCADE
  363. ');
  364. chado_query('
  365. ALTER TABLE {pubauthor_contact}
  366. DROP CONSTRAINT pubauthor_contact_contact_id_fkey CASCADE
  367. ');
  368. }
  369. chado_query('
  370. ALTER TABLE {pubauthor_contact}
  371. ADD CONSTRAINT pubauthor_contact_pubauthor_id_fkey
  372. FOREIGN KEY (pubauthor_id) REFERENCES {pubauthor} (pubauthor_id)
  373. ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
  374. ');
  375. chado_query('
  376. ALTER TABLE {pubauthor_contact}
  377. ADD CONSTRAINT pubauthor_contact_contact_id_fkey
  378. FOREIGN KEY (contact_id) REFERENCES {contact} (contact_id)
  379. ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
  380. ');
  381. }
  382. catch (\PDOException $e) {
  383. $error = $e->getMessage();
  384. throw new DrupalUpdateException('Failed to update foriegn key: '. $error);
  385. }
  386. }
  387. /**
  388. * Updates path of tripal_pub OBO to be relative.
  389. */
  390. function tripal_pub_update_7202() {
  391. // Make sure we have the full API loaded this will help during a
  392. // site upgrade when the tripal_core module is disabled.
  393. module_load_include('module', 'tripal_core', 'tripal_core');
  394. tripal_core_import_api();
  395. module_load_include('inc', 'tripal_cv', 'api/tripal_cv.api');
  396. try {
  397. // Remove duplicates.
  398. db_delete('tripal_cv_obo')
  399. ->condition('name', 'Tripal Publication')
  400. ->execute();
  401. // Add in the updated path.
  402. $obo_path = '{tripal_pub}/files/tpub.obo';
  403. $obo_id = tripal_insert_obo('Tripal Publication', $obo_path);
  404. }
  405. catch (\PDOException $e) {
  406. $error = $e->getMessage();
  407. throw new DrupalUpdateException('Failed to update tripal_pub OBO path: '. $error);
  408. }
  409. }