Merge branch '5.34' of https://github.com/civicrm/civicrm-core into upit
[civicrm-core.git] / api / v3 / ReportTemplate.php
index 8f0aba9fa1daf3133358c977a6ee014afde71034..2b96179265d1c7561a6c60e8b3fd2a4267d5bba8 100644 (file)
@@ -97,6 +97,9 @@ function civicrm_api3_report_template_delete($params) {
  *
  * @return array
  *   API result array
+ *
+ * @throws \API_Exception
+ * @throws \CiviCRM_API3_Exception
  */
 function civicrm_api3_report_template_getrows($params) {
   civicrm_api3_verify_one_mandatory($params, NULL, ['report_id', 'instance_id']);
@@ -180,6 +183,10 @@ function _civicrm_api3_report_template_getrows($params) {
 function civicrm_api3_report_template_getstatistics($params) {
   list($rows, $reportInstance, $metadata) = _civicrm_api3_report_template_getrows($params);
   $stats = $reportInstance->statistics($rows);
+  if (isset($metadata['metadata']['sql'])) {
+    // Update for stats queries.
+    $metadata['metadata']['sql'] = $reportInstance->getReportSql();
+  }
   $reportInstance->cleanUpTemporaryTables();
   return civicrm_api3_create_success($stats, $params, 'ReportTemplate', 'getstatistics', CRM_Core_DAO::$_nullObject, $metadata);
 }