From ac8302238985d7780bab1cc63045f270e407f47e Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 7 Aug 2013 21:28:21 -0700 Subject: [PATCH] CRM-13163 - CRM_Utils_API_ReloadOption - Switch to stateless operation ---------------------------------------- * CRM-13163: hrjob: Display/edit dates with jQuery date picker http://issues.civicrm.org/jira/browse/CRM-13163 --- CRM/Utils/API/ReloadOption.php | 32 +++++++++++++++++++++++++------- api/api.php | 2 +- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/CRM/Utils/API/ReloadOption.php b/CRM/Utils/API/ReloadOption.php index 45677c6fb8..0c6600ad65 100644 --- a/CRM/Utils/API/ReloadOption.php +++ b/CRM/Utils/API/ReloadOption.php @@ -46,17 +46,24 @@ require_once 'api/Wrapper.php'; class CRM_Utils_API_ReloadOption implements API_Wrapper { /** - * @var null|'null'|'default'|'selected' + * @var CRM_Utils_API_ReloadOption */ - private $reloadMode = NULL; + private static $_singleton = NULL; + + /** + * @return CRM_Utils_API_ReloadOption + */ + public static function singleton() { + if (self::$_singleton === NULL) { + self::$_singleton = new CRM_Utils_API_ReloadOption(); + } + return self::$_singleton; + } /** * {@inheritDoc} */ public function fromApiInput($apiRequest) { - if ($apiRequest['action'] === 'create' && isset($apiRequest['params'], $apiRequest['params']['options'], $apiRequest['params']['options']['reload'])) { - $this->reloadMode = $apiRequest['params']['options']['reload']; - } return $apiRequest; } @@ -67,7 +74,15 @@ class CRM_Utils_API_ReloadOption implements API_Wrapper { if ($result['is_error']) { return $result; } - switch ($this->reloadMode) { + + if ($apiRequest['action'] === 'create' && isset($apiRequest['params'], $apiRequest['params']['options'], $apiRequest['params']['options']['reload'])) { + $reloadMode = $apiRequest['params']['options']['reload']; + } + else { + $reloadMode = NULL; + } + + switch ($reloadMode) { case NULL: case '0': case 'null': @@ -79,6 +94,9 @@ class CRM_Utils_API_ReloadOption implements API_Wrapper { 'id' => $result['id'], ); $reloadResult = civicrm_api3($apiRequest['entity'], 'get', $params); + if ($reloadResult['is_error']) { + throw new API_Exception($reloadResult['error_message']); + } $result['values'][$result['id']] = array_merge($result['values'][$result['id']], $reloadResult['values'][$result['id']]); return $result; @@ -92,7 +110,7 @@ class CRM_Utils_API_ReloadOption implements API_Wrapper { return $result; default: - throw new API_Exception("Unknown reload mode: " . var_export($this->reloadMode, TRUE)); + throw new API_Exception("Unknown reload mode"); } } diff --git a/api/api.php b/api/api.php index d339644e98..2564b1898b 100644 --- a/api/api.php +++ b/api/api.php @@ -22,7 +22,7 @@ function civicrm_api($entity, $action, $params, $extra = NULL) { $apiWrappers = array( CRM_Utils_API_HTMLInputCoder::singleton(), CRM_Utils_API_NullOutputCoder::singleton(), - new CRM_Utils_API_ReloadOption(), + CRM_Utils_API_ReloadOption::singleton(), ); try { require_once ('api/v3/utils.php'); -- 2.25.1