From 9c41ad84fa51a47316225411f0a08afbfdb89bde Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 23 Aug 2016 00:00:10 -0700 Subject: [PATCH] CRM_Utils_REST - Always boot CMS, even in error conditions Now-a-days, HTTP headers are outputted using CMS functions, which means that the CMS must always boot -- even if you're only displaying an error message. This caused regressions in the REST error handling. Why? The boot sequence is really quirky with the REST calls... and the required CMS functions were not always available. This revision ensures that (one way or another) the CMS does get booted. Notably, though, in the error scenarios, it boots *without* loading or authenticating a user. --- CRM/Utils/REST.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CRM/Utils/REST.php b/CRM/Utils/REST.php index 35e4e9b123..c6c05788cd 100644 --- a/CRM/Utils/REST.php +++ b/CRM/Utils/REST.php @@ -676,6 +676,7 @@ class CRM_Utils_REST { // Proceed with bootstrap for "?q=civicrm/X/Y" but not "?q=civicrm/ping" if (!empty($q)) { if (count($args) == 2 && $args[1] == 'ping') { + CRM_Utils_System::loadBootStrap(array(), FALSE, FALSE); return NULL; // this is pretty wonky but maybe there's some reason I can't see } if (count($args) != 3) { @@ -691,6 +692,7 @@ class CRM_Utils_REST { // FIXME: At time of writing, this doesn't actually do anything because // authenticateKey abends, but that's a bad behavior which sends a // malformed response. + CRM_Utils_System::loadBootStrap(array(), FALSE, FALSE); return self::error('Failed to authenticate key'); } @@ -699,6 +701,7 @@ class CRM_Utils_REST { $store = NULL; $api_key = CRM_Utils_Request::retrieve('api_key', 'String', $store, FALSE, NULL, 'REQUEST'); if (empty($api_key)) { + CRM_Utils_System::loadBootStrap(array(), FALSE, FALSE); return self::error("FATAL: mandatory param 'api_key' (user key) missing"); } $contact_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $api_key, 'id', 'api_key'); @@ -718,6 +721,7 @@ class CRM_Utils_REST { return NULL; } else { + CRM_Utils_System::loadBootStrap(array(), FALSE, FALSE); return self::error('ERROR: No CMS user associated with given api-key'); } } -- 2.25.1