[REF] Improve cron job handling when there is an invalid report instance id passed...
authorSeamus Lee <seamuslee001@gmail.com>
Mon, 28 Aug 2023 04:52:56 +0000 (14:52 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Mon, 28 Aug 2023 04:52:56 +0000 (14:52 +1000)
CRM/Report/Utils/Report.php

index 6f837dc9ad1cd624ea73af7d0b87d740c4e32ab9..beb1454f30575cbc15623b21a2e3d695b19089fb 100644 (file)
@@ -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),