tripal_pub.drush.inc 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. function tripal_pub_drush_help($command) {
  13. switch ($command) {
  14. case 'drush:tripal-pub-import':
  15. return dt('Imports publications from remote databases using saved configuration settings.');
  16. }
  17. }
  18. /**
  19. * Registers a drush command and constructs the full help for that command
  20. *
  21. * @return
  22. * And array of command descriptions
  23. */
  24. function tripal_pub_drush_command() {
  25. $items = array();
  26. $items['tripal-pubs-import'] = array(
  27. 'description' => dt('Imports publications from remote databases using saved configuration settings.'),
  28. 'options' => array(
  29. 'create_contacts' => dt('provide this option to create or update contacts for authors. By default contacts are not created or updated.'),
  30. 'dbxref' => dt('An accession number for a publication from a remote database (e.g. PMID:23582642).'),
  31. 'report' => dt("Set to the email address of the recipient who should receive an HTML report of the publications that have been added."),
  32. 'update' => dt("Set to 'Y' to update existing pubs. By default only new pubs are inserted."),
  33. ),
  34. 'examples' => array(
  35. 'Standard example' => 'drush tripal-pubs-import',
  36. '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',
  37. 'Import single publication' => 'drush tripal-pub-import --dbxref=PMID:23582642',
  38. ),
  39. 'aliases' => array('tpubs-import'),
  40. );
  41. $items['tripal-pubs-update'] = array(
  42. 'description' => dt('Updates publication information for publications with a supported database cross-reference.'),
  43. 'options' => array(
  44. 'create_contacts' => dt('provide this option to create or update contacts for authors. By default contacts are not created or updated.'),
  45. 'dbxref' => dt('An accession number for a publication from a remote database (e.g. PMID:23582642)'),
  46. 'db' => dt('The database name (e.g. PMID or AGL)'),
  47. ),
  48. 'examples' => array(
  49. 'Standard example' => 'drush tripal-pubs-update',
  50. 'Create contacts during update' => 'drush tripal-pubs-update --create_contacts=1',
  51. 'Update a single record' => 'drush tripal-pubs-update --dbxref=PMID:23582642',
  52. 'Update all records for a single database' => 'drush tripal-pubs-update --db=PMID'
  53. ),
  54. 'aliases' => array('tpubs-update'),
  55. );
  56. return $items;
  57. }
  58. /**
  59. * Imports publications into Chado
  60. *
  61. */
  62. function drush_tripal_pub_tripal_pubs_import() {
  63. $create_contacts = drush_get_option('create_contacts');
  64. $dbxref = drush_get_option('dbxref');
  65. $do_report = drush_get_option('report');
  66. $update = drush_get_option('update');
  67. if($update == 'Y') {
  68. $update = TRUE;
  69. }
  70. else {
  71. $update = FALSE;
  72. }
  73. if ($dbxref) {
  74. tripal_pub_import_by_dbxref($dbxref, $create_contacts, $update);
  75. }
  76. else {
  77. tripal_pub_import_publications($do_report, $update);
  78. }
  79. }
  80. /**
  81. * Imports publications into Chado
  82. *
  83. */
  84. function drush_tripal_pub_tripal_pubs_update() {
  85. $create_contacts = drush_get_option('create_contacts');
  86. $dbxref = drush_get_option('dbxref');
  87. $db = drush_get_option('db');
  88. tripal_pub_update_publications($create_contacts, $dbxref, $db);
  89. }