CRM-20615 Export only those batches whose status is exported
authorPradeep Nayak <pradpnayak@gmail.com>
Sat, 20 May 2017 23:40:04 +0000 (05:10 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Mon, 22 May 2017 11:41:38 +0000 (17:11 +0530)
----------------------------------------
* CRM-20615: Export only those batches having status Exported
  https://issues.civicrm.org/jira/browse/CRM-20615

CRM/Batch/BAO/Batch.php

index 6dda28ebb5f0d491a2b2964cd387083a522003a3..64380c5a5986276e77af9180e7bde941f4715e88 100644 (file)
@@ -594,10 +594,21 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch {
     else {
       CRM_Core_Error::fatal("Could not locate exporter: $exporterClass");
     }
+    $export = array();
     foreach ($batchIds as $batchId) {
+      // export only batches whose status is set to Exported.
+      $result = civicrm_api3('Batch', 'getcount', array(
+        'id' => $batchId,
+        'status_id' => "Exported",
+      ));
+      if (!$result) {
+        continue;
+      }
       $export[$batchId] = $exporter->generateExportQuery($batchId);
     }
-    $exporter->makeExport($export);
+    if ($export) {
+      $exporter->makeExport($export);
+    }
   }
 
   /**