tripal_pub.drush.inc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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-import-pubs':
  17. return dt('Imports publications from remote databases using saved configuration settings.');
  18. case 'drush:tripal-update-pubs':
  19. return dt('Updates publication information for publications with a supported database cross-reference.');
  20. }
  21. }
  22. /**
  23. * Registers a drush command and constructs the full help for that command
  24. *
  25. * @return
  26. * And array of command descriptions
  27. *
  28. * @ingroup tripal_drush
  29. */
  30. function tripal_pub_drush_command() {
  31. $items = array();
  32. $items['trp-import-pubs'] = array(
  33. 'description' => dt('Imports publications from remote databases using saved configuration settings.'),
  34. 'options' => array(
  35. 'create_contacts' => dt('provide this option to create or update contacts for authors. By default contacts are not created or updated.'),
  36. 'dbxref' => dt('An accession number for a publication from a remote database (e.g. PMID:23582642).'),
  37. 'report' => dt("Set to the email address of the recipient who should receive an HTML report of the publications that have been added."),
  38. 'update' => dt("Set to 'Y' to update existing pubs. By default only new pubs are inserted."),
  39. ),
  40. 'examples' => array(
  41. 'Standard example' => 'drush tripal-pubs-import',
  42. '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',
  43. 'Import single publication' => 'drush tripal-pub-import --dbxref=PMID:23582642',
  44. ),
  45. );
  46. $items['trp-update-pubs'] = array(
  47. 'description' => dt('Updates publication information for publications with a supported database cross-reference.'),
  48. 'options' => array(
  49. 'create_contacts' => dt('provide this option to create or update contacts for authors. By default contacts are not created or updated.'),
  50. 'dbxref' => dt('An accession number for a publication from a remote database (e.g. PMID:23582642)'),
  51. 'db' => dt('The database name (e.g. PMID or AGL)'),
  52. ),
  53. 'examples' => array(
  54. 'Standard example' => 'drush tripal-pubs-update',
  55. 'Create contacts during update' => 'drush tripal-pubs-update --create_contacts=1',
  56. 'Update a single record' => 'drush tripal-pubs-update --dbxref=PMID:23582642',
  57. 'Update all records for a single database' => 'drush tripal-pubs-update --db=PMID'
  58. ),
  59. );
  60. // Deprecated commands
  61. $items['tripal-pubs-import'] = array(
  62. 'description' => dt('DEPRECATED. Please see: trp-import-pubs.'),
  63. 'options' => array(
  64. 'create_contacts' => dt('provide this option to create or update contacts for authors. By default contacts are not created or updated.'),
  65. 'dbxref' => dt('An accession number for a publication from a remote database (e.g. PMID:23582642).'),
  66. 'report' => dt("Set to the email address of the recipient who should receive an HTML report of the publications that have been added."),
  67. 'update' => dt("Set to 'Y' to update existing pubs. By default only new pubs are inserted."),
  68. ),
  69. 'examples' => array(
  70. 'Standard example' => 'drush tripal-pubs-import',
  71. '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',
  72. 'Import single publication' => 'drush tripal-pub-import --dbxref=PMID:23582642',
  73. ),
  74. 'aliases' => array('tpubs-import'),
  75. );
  76. $items['tripal-pubs-update'] = array(
  77. 'description' => dt('DEPRECATED. Please see: trp-update-pubs.'),
  78. 'options' => array(
  79. 'create_contacts' => dt('provide this option to create or update contacts for authors. By default contacts are not created or updated.'),
  80. 'dbxref' => dt('An accession number for a publication from a remote database (e.g. PMID:23582642)'),
  81. 'db' => dt('The database name (e.g. PMID or AGL)'),
  82. ),
  83. 'examples' => array(
  84. 'Standard example' => 'drush tripal-pubs-update',
  85. 'Create contacts during update' => 'drush tripal-pubs-update --create_contacts=1',
  86. 'Update a single record' => 'drush tripal-pubs-update --dbxref=PMID:23582642',
  87. 'Update all records for a single database' => 'drush tripal-pubs-update --db=PMID'
  88. ),
  89. 'aliases' => array('tpubs-update'),
  90. );
  91. return $items;
  92. }
  93. /**
  94. * Imports publications into Chado
  95. *
  96. * @ingroup tripal_drush
  97. */
  98. function drush_tripal_pub_trp_import_pubs() {
  99. $create_contacts = drush_get_option('create_contacts');
  100. $dbxref = drush_get_option('dbxref');
  101. $do_report = drush_get_option('report');
  102. $update = drush_get_option('update');
  103. if($update == 'Y') {
  104. $update = TRUE;
  105. }
  106. else {
  107. $update = FALSE;
  108. }
  109. if ($dbxref) {
  110. tripal_import_pub_by_dbxref($dbxref, $create_contacts, $update);
  111. }
  112. else {
  113. tripal_execute_active_pub_importers($do_report, $update);
  114. }
  115. }
  116. /**
  117. * DEPRECATED. Imports publications into Chado
  118. *
  119. * @ingroup tripal_drush
  120. */
  121. function drush_tripal_pub_tripal_pubs_import() {
  122. drush_print("\n\nDEPRECATED: This drush command is outdated.\nIt will ".
  123. "continue to work but please consider using the 'trp-import-pubs' command.\n\n");
  124. drush_tripal_pub_trp_import_pubs();
  125. }
  126. /**
  127. * Imports publications into Chado
  128. *
  129. * @ingroup tripal_drush
  130. */
  131. function drush_tripal_pub_trp_update_pubs() {
  132. $create_contacts = drush_get_option('create_contacts');
  133. $dbxref = drush_get_option('dbxref');
  134. $db = drush_get_option('db');
  135. tripal_reimport_publications($create_contacts, $dbxref, $db);
  136. }
  137. /**
  138. * DEPRECATED. Imports publications into Chado
  139. *
  140. * @ingroup tripal_drush
  141. */
  142. function drush_tripal_pub_tripal_pubs_update() {
  143. drush_print("\n\nDEPRECATED: This drush command is outdated.\nIt will ".
  144. "continue to work but please consider using the 'trp-update-pubs' command.\n\n");
  145. drush_tripal_pub_trp_update_pubs();
  146. }