CRM-20588, code cleanup
authorPradeep Nayak <pradpnayak@gmail.com>
Tue, 16 May 2017 22:25:14 +0000 (03:55 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Tue, 16 May 2017 22:25:14 +0000 (03:55 +0530)
----------------------------------------
* CRM-20588: Pre and Post hook for Batch
  https://issues.civicrm.org/jira/browse/CRM-20588

CRM/Batch/BAO/Batch.php
CRM/Financial/Form/Export.php
CRM/Financial/Form/FinancialBatch.php
CRM/Financial/Page/AJAX.php

index 541669a584e487be24563b69981e85dad82741c9..ad4e487d2aec8670cb4258fe1a73fd4f309334b5 100644 (file)
@@ -51,24 +51,16 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch {
    * Create a new batch.
    *
    * @param array $params
-   * @param array $ids
-   *   Associated array of ids.
-   * @param string $context
-   *   String.
    *
    * @return object
    *   $batch batch object
    */
-  public static function create(&$params, $ids = NULL, $context = NULL) {
+  public static function create(&$params) {
     if (empty($params['id'])) {
       $params['name'] = CRM_Utils_String::titleToVar($params['title']);
     }
-
     $batch = new CRM_Batch_DAO_Batch();
     $batch->copyValues($params);
-    if ($context == 'financialBatch' && !empty($ids['batchID'])) {
-      $batch->id = $ids['batchID'];
-    }
     $batch->save();
 
     return $batch;
index 7267d0469c16cc8b837d336010ffb7c90e3c7ba1..31e3b3b1e464cf36cae9f9143412174fd29a2bf5 100644 (file)
@@ -167,12 +167,11 @@ class CRM_Financial_Form_Export extends CRM_Core_Form {
     $batchParams['modified_id'] = $session->get('userID');
     $batchParams['status_id'] = $this->_exportStatusId;
 
-    $ids = array();
     foreach ($batchIds as $batchId) {
-      $batchParams['id'] = $ids['batchID'] = $batchId;
+      $batchParams['id'] = $batchId;
       // Update totals
       $batchParams = array_merge($batchParams, $totals[$batchId]);
-      CRM_Batch_BAO_Batch::create($batchParams, $ids, 'financialBatch');
+      CRM_Batch_BAO_Batch::create($batchParams);
     }
 
     CRM_Batch_BAO_Batch::exportFinancialBatch($batchIds, $this->_exportFormat);
index c64287de4d137225bb48fbba62fc266568902780..d1755ba36a96480dfae22342577e08bcc5bbcc3b 100644 (file)
@@ -196,11 +196,9 @@ class CRM_Financial_Form_FinancialBatch extends CRM_Contribute_Form {
    */
   public function postProcess() {
     $session = CRM_Core_Session::singleton();
-    $ids = array();
     $params = $this->exportValues();
     $batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id');
     if ($this->_id) {
-      $ids['batchID'] = $this->_id;
       $params['id'] = $this->_id;
     }
 
@@ -228,7 +226,7 @@ class CRM_Financial_Form_FinancialBatch extends CRM_Contribute_Form {
       $activityTypeName = 'Edit Batch';
     }
 
-    $batch = CRM_Batch_BAO_Batch::create($params, $ids, 'financialBatch');
+    $batch = CRM_Batch_BAO_Batch::create($params);
 
     $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name');
 
index 2715e99b9e184e0f588b1ef49a7f5422e83d7ea6..d20b4d4dee7985988ccfeccef38dd6193c1eb07e 100644 (file)
@@ -183,7 +183,6 @@ class CRM_Financial_Page_AJAX {
     if ($recordClass[0] == 'CRM' && count($recordClass) >= 3) {
       foreach ($records as $recordID) {
         $params = array();
-        $ids = NULL;
         switch ($op) {
           case 'assign':
           case 'remove':
@@ -207,14 +206,12 @@ class CRM_Financial_Page_AJAX {
             $params = $totals[$recordID];
           case 'reopen':
             $status = $op == 'close' ? 'Closed' : 'Reopened';
-            $ids['batchID'] = $recordID;
             $batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name'));
             $params['status_id'] = CRM_Utils_Array::key($status, $batchStatus);
             $session = CRM_Core_Session::singleton();
             $params['modified_date'] = date('YmdHis');
             $params['modified_id'] = $session->get('userID');
             $params['id'] = $recordID;
-            $context = "financialBatch";
             break;
 
           case 'export':
@@ -223,17 +220,11 @@ class CRM_Financial_Page_AJAX {
 
           case 'delete':
             $params = $recordID;
-            $context = "financialBatch";
             break;
         }
 
         if (method_exists($recordBAO, $methods[$op]) & !empty($params)) {
-          if (isset($context)) {
-            $updated = call_user_func_array(array($recordBAO, $methods[$op]), array(&$params, $ids, $context));
-          }
-          else {
-            $updated = call_user_func_array(array($recordBAO, $methods[$op]), array(&$params, $ids));
-          }
+          $updated = call_user_func_array(array($recordBAO, $methods[$op]), array(&$params));
           if ($updated) {
             $redirectStatus = $updated->status_id;
             if ($batchStatus[$updated->status_id] == "Reopened") {