Browse Source

Changed code so that HTML report is sent by email rather than returned on command-lie

spficklin 12 years ago
parent
commit
6cefa3cae8
3 changed files with 32 additions and 10 deletions
  1. 13 5
      tripal_pub/api/tripal_pub.api.inc
  2. 6 5
      tripal_pub/tripal_pub.drush.inc
  3. 13 0
      tripal_pub/tripal_pub.module

+ 13 - 5
tripal_pub/api/tripal_pub.api.inc

@@ -197,7 +197,7 @@ function tripal_pub_update_publications($do_contact = FALSE, $dbxref = NULL, $db
 /*
  * @ingroup tripal_pub_api
  */
-function tripal_pub_import_publications($do_report = 'N') {
+function tripal_pub_import_publications($report_email = FALSE) {
   $num_to_retrieve = 100;
   $pager_id = 0;
   $page = 0;
@@ -258,21 +258,29 @@ function tripal_pub_import_publications($do_report = 'N') {
   }
   
   // iterate through each of the reports and generate a final report with HTML links
-  if ($do_report == 'Y') {
+  $HTML_report = '';
+  if ($report_email) {
+    $HTML_report .= "<html>";
     global $base_url;  
     foreach ($reports as $importer => $report) {
       $total = count($report['inserted']);
-      print "<b>$total new publications from importer: $importer</b><br><ol>\n";
+      $HTML_report .= "<b>$total new publications from importer: $importer</b><br><ol>\n";
       foreach ($report['inserted'] as $pub) {
         $item = $pub['Title'];
         if ($pub['pub_id']) {
           $nid = chado_get_node_id('pub', $pub['pub_id']);
           $item = l($pub['Title'], "$base_url/node/$nid");
         } 
-        print "<li>$item</li>\n";      
+        $HTML_report .= "<li>$item</li>\n";      
       }
-      print "</ol>\n";   
+      $HTML_report .= "</ol>\n";   
     }  
+    $HTML_report .= "</html>";
+    $site_email = variable_get('site_mail', '');
+    $params = array(
+      'message' => $HTML_report
+    );
+    drupal_mail('tripal_pub', 'import_report', $report_email, language_default(), $params, $site_email, TRUE);
   }
   
   // if any of the importers wanted to create contacts from the authors then sync them

+ 6 - 5
tripal_pub/tripal_pub.drush.inc

@@ -28,14 +28,15 @@ function tripal_pub_drush_command() {
   $items = array();
   $items['tripal-pubs-import'] = array(
     'description' => dt('Imports publications from remote databases using saved configuration settings.'),
-    'examples' => array(
-      'Standard example' => 'drush tripal-pubs-import',
-      'Import single publication' => 'drush tripal-pub-import --dbxref=PMID:23582642',  
-    ),
     'options' => array(
       'create_contacts' => dt('provide this option to create or update contacts for authors. By default contacts are not created or updated.'),
       'dbxref' => dt('An accession number for a publication from a remote database (e.g. PMID:23582642).'),
-      'report' => dt("Set to 'Y' to generate an HTML report of the publications that have been added."),
+      'report' => dt("Set to the email address of the recipient who should receive an HTML report of the publications that have been added."),
+    ),
+    'examples' => array(
+      'Standard example' => 'drush tripal-pubs-import',
+      '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',
+      'Import single publication' => 'drush tripal-pub-import --dbxref=PMID:23582642',  
     ),
     'aliases' => array('tpubs-import'),
   );

+ 13 - 0
tripal_pub/tripal_pub.module

@@ -801,4 +801,17 @@ function tripal_pub_preprocess_tripal_pub_relationships(&$variables) {
   }
 
   $pub->all_relationships = $relationships;
+}
+/**
+ * 
+ */
+function tripal_pub_mail($key, &$message, $params) {
+  $language = $message['language'];
+  $variables = user_mail_tokens($params['account'], $language);
+  switch($key) {
+    case 'import_report':
+      $message['subject'] = t('Publication import from !site', $variables, $language->language);
+      $message['body'][] = $params['message'];
+      break;
+  }
 }