Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-21155

Hook batchItems does not change the csv export

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Minor
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.6.28, 4.7.23
    • Fix Version/s: 4.7.31
    • Component/s: CiviContribute
    • Labels:
    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      Developer Doc
    • Funding Source:
      Contributed Code
    • Verified?:
      No

      Description

      When using the hook civicrm_batchItems to transform the csv export format, the hook itself functions as expected. My code:

      function fintrxn_civicrm_batchItems(&$results, &$items) {
        // change batch items when exporting to meet aivl criteria
        CRM_Fintrxn_Batch::batchItems($results, $items);
      }
      public static function batchItems ($results, &$items) {
        // clean out items array
        $items = array();
        // get mapping from JSON file
        $mapping = self::getExportMapping();
        // go through all results
        foreach ($results as $result) {
          // split transaction date in year and month
          $transactionDate = new DateTime($result['trxn_date']);
          $result['trxn_year'] = $transactionDate->format('Y');
          $result['trxn_month'] = $transactionDate->format('n');
          // create item array based on mapping
          $item = $mapping;
          foreach ($item as $itemKey => $itemValue) {
            if (isset($result[$itemValue])) {
              $item[$itemKey] = $result[$itemValue];
            }
          }
          $items[] = $item;
        }
      }
      
      
      

      But the actual output does not reflect my changes in the hook. This is because the code in

      CRM_Financial_BAO_ExportFormat_CSV does not actually process the hook results.

      In my opinion it should be:

        $batchItems[] = &$financialItems[key($financialItems)];
        $queryResults[] = get_object_vars($dao);
      }
      
      CRM_Utils_Hook::batchItems($queryResults, $batchItems);
      
      $batchItems['headers'] = self::formatHeaders($batchItems);
      self::export($batchItems);
      
      

      I have tested this locally and it works.

        Attachments

          Activity

            People

            • Assignee:
              erikhommel Erik Hommel
              Reporter:
              erikhommel Erik Hommel
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1 hour
                1h
                Remaining:
                Remaining Estimate - 1 hour
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified