From 3f26d74778a16503d860607abeb7f386a3265dce Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Mon, 28 Aug 2023 14:52:56 +1000 Subject: [PATCH] [REF] Improve cron job handling when there is an invalid report instance id passed to mail_report job --- CRM/Report/Utils/Report.php | 70 ++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/CRM/Report/Utils/Report.php b/CRM/Report/Utils/Report.php index 6f837dc9ad..beb1454f30 100644 --- a/CRM/Report/Utils/Report.php +++ b/CRM/Report/Utils/Report.php @@ -395,45 +395,49 @@ WHERE inst.report_id = %1"; $optionVal = self::getValueFromUrl($instanceId); $messages = ['Report Mail Triggered...']; - - $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', $optionVal, 'value'); - $obj = new CRM_Report_Page_Instance(); - $is_error = 0; - if (strstr(CRM_Utils_Array::value('name', $templateInfo), '_Form')) { - $instanceInfo = []; - CRM_Report_BAO_ReportInstance::retrieve(['id' => $instanceId], $instanceInfo); - - if (!empty($instanceInfo['title'])) { - $obj->assign('reportTitle', $instanceInfo['title']); - } - else { - $obj->assign('reportTitle', $templateInfo['label']); - } - - $wrapper = new CRM_Utils_Wrapper(); - $arguments = [ - 'urlToSession' => [ - [ - 'urlVar' => 'instanceId', - 'type' => 'Positive', - 'sessionVar' => 'instanceId', - 'default' => 'null', - ], - ], - 'ignoreKey' => TRUE, - ]; - $messages[] = $wrapper->run($templateInfo['name'], NULL, $arguments); + if (empty($optionVal)) { + $is_error = 1; + $messages[] = 'Did not find a valid instance to execute'; } else { - $is_error = 1; - if (!$instanceId) { - $messages[] = 'Required parameter missing: instanceId'; + $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', $optionVal, 'value'); + $obj = new CRM_Report_Page_Instance(); + $is_error = 0; + if (strstr(CRM_Utils_Array::value('name', $templateInfo), '_Form')) { + $instanceInfo = []; + CRM_Report_BAO_ReportInstance::retrieve(['id' => $instanceId], $instanceInfo); + + if (!empty($instanceInfo['title'])) { + $obj->assign('reportTitle', $instanceInfo['title']); + } + else { + $obj->assign('reportTitle', $templateInfo['label']); + } + + $wrapper = new CRM_Utils_Wrapper(); + $arguments = [ + 'urlToSession' => [ + [ + 'urlVar' => 'instanceId', + 'type' => 'Positive', + 'sessionVar' => 'instanceId', + 'default' => 'null', + ], + ], + 'ignoreKey' => TRUE, + ]; + $messages[] = $wrapper->run($templateInfo['name'], NULL, $arguments); } else { - $messages[] = 'Did not find valid instance to execute'; + $is_error = 1; + if (!$instanceId) { + $messages[] = 'Required parameter missing: instanceId'; + } + else { + $messages[] = 'Did not find valid instance to execute'; + } } } - $result = [ 'is_error' => $is_error, 'messages' => implode("\n", $messages), -- 2.25.1