tripal_pub.drush.inc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * @file
  4. * Contains function relating to drush-integration of this module.
  5. */
  6. /**
  7. * Describes each drush command implemented by the module
  8. *
  9. * @return
  10. * The first line of description when executing the help for a given command
  11. *
  12. * @ingroup tripal_drush
  13. */
  14. function tripal_pub_drush_help($command) {
  15. switch ($command) {
  16. case 'drush:tripal-pub-import':
  17. return dt('Imports publications from remote databases using saved configuration settings.');
  18. }
  19. }
  20. /**
  21. * Registers a drush command and constructs the full help for that command
  22. *
  23. * @return
  24. * And array of command descriptions
  25. *
  26. * @ingroup tripal_drush
  27. */
  28. function tripal_pub_drush_command() {
  29. $items = array();
  30. $items['tripal-pubs-import'] = array(
  31. 'description' => dt('Imports publications from remote databases using saved configuration settings.'),
  32. 'options' => array(
  33. 'create_contacts' => dt('provide this option to create or update contacts for authors. By default contacts are not created or updated.'),
  34. 'dbxref' => dt('An accession number for a publication from a remote database (e.g. PMID:23582642).'),
  35. 'report' => dt("Set to the email address of the recipient who should receive an HTML report of the publications that have been added."),
  36. 'update' => dt("Set to 'Y' to update existing pubs. By default only new pubs are inserted."),
  37. ),
  38. 'examples' => array(
  39. 'Standard example' => 'drush tripal-pubs-import',
  40. 'Standard example' => 'drush -l http://[site url] tripal-pubs-import --report=[email]. Where [site url] is the URL of the website and [email] is the email address of the recipient to receive the HTML report',
  41. 'Import single publication' => 'drush tripal-pub-import --dbxref=PMID:23582642',
  42. ),
  43. 'aliases' => array('tpubs-import'),
  44. );
  45. $items['tripal-pubs-update'] = array(
  46. 'description' => dt('Updates publication information for publications with a supported database cross-reference.'),
  47. 'options' => array(
  48. 'create_contacts' => dt('provide this option to create or update contacts for authors. By default contacts are not created or updated.'),
  49. 'dbxref' => dt('An accession number for a publication from a remote database (e.g. PMID:23582642)'),
  50. 'db' => dt('The database name (e.g. PMID or AGL)'),
  51. ),
  52. 'examples' => array(
  53. 'Standard example' => 'drush tripal-pubs-update',
  54. 'Create contacts during update' => 'drush tripal-pubs-update --create_contacts=1',
  55. 'Update a single record' => 'drush tripal-pubs-update --dbxref=PMID:23582642',
  56. 'Update all records for a single database' => 'drush tripal-pubs-update --db=PMID'
  57. ),
  58. 'aliases' => array('tpubs-update'),
  59. );
  60. return $items;
  61. }
  62. /**
  63. * Imports publications into Chado
  64. *
  65. * @ingroup tripal_drush
  66. */
  67. function drush_tripal_pub_tripal_pubs_import() {
  68. $create_contacts = drush_get_option('create_contacts');
  69. $dbxref = drush_get_option('dbxref');
  70. $do_report = drush_get_option('report');
  71. $update = drush_get_option('update');
  72. if($update == 'Y') {
  73. $update = TRUE;
  74. }
  75. else {
  76. $update = FALSE;
  77. }
  78. if ($dbxref) {
  79. tripal_import_pub_by_dbxref($dbxref, $create_contacts, $update);
  80. }
  81. else {
  82. tripal_execute_active_pub_importers($do_report, $update);
  83. }
  84. }
  85. /**
  86. * Imports publications into Chado
  87. *
  88. * @ingroup tripal_drush
  89. */
  90. function drush_tripal_pub_tripal_pubs_update() {
  91. $create_contacts = drush_get_option('create_contacts');
  92. $dbxref = drush_get_option('dbxref');
  93. $db = drush_get_option('db');
  94. chado_reimport_publications($create_contacts, $dbxref, $db);
  95. }