From 0efb07c095a5fbc0479aa7e363ab1b3c13525450 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 25 Mar 2015 04:27:52 -0700 Subject: [PATCH] CRM-16173 - Cxn.unregister API --- CRM/Cxn/BAO/Cxn.php | 8 ++++++++ api/v3/Cxn.php | 30 +++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/CRM/Cxn/BAO/Cxn.php b/CRM/Cxn/BAO/Cxn.php index bfc7ce364d..4f6fa2f06e 100644 --- a/CRM/Cxn/BAO/Cxn.php +++ b/CRM/Cxn/BAO/Cxn.php @@ -56,4 +56,12 @@ class CRM_Cxn_BAO_Cxn extends CRM_Cxn_DAO_Cxn { 2 => array($appMeta['appId'], 'String'), )); } + + public static function getAppMeta($cxnId) { + $appMetaJson = CRM_Core_DAO::getFieldValue('CRM_Cxn_DAO_Cxn', $cxnId, 'app_meta', 'cxn_id', TRUE); + $appMeta = json_decode($appMetaJson, TRUE); + \Civi\Cxn\Rpc\AppMeta::validate($appMeta); + return $appMeta; + } + } diff --git a/api/v3/Cxn.php b/api/v3/Cxn.php index a136fa7690..f70f1f35c1 100644 --- a/api/v3/Cxn.php +++ b/api/v3/Cxn.php @@ -56,7 +56,7 @@ function civicrm_api3_cxn_register($params) { try { /** @var \Civi\Cxn\Rpc\RegistrationClient $client */ $client = \Civi\Core\Container::singleton()->get('cxn_reg_client'); - list($cxnId, $isOk) = $client->register($params['appMeta']); + list($cxnId, $result) = $client->register($params['appMeta']); CRM_Cxn_BAO_Cxn::updateAppMeta($params['appMeta']); } catch (Exception $e) { @@ -64,13 +64,25 @@ function civicrm_api3_cxn_register($params) { throw $e; } - if ($isOk) { - $result = array( - 'cxnId' => $cxnId, - ); - return civicrm_api3_create_success($result); - } - else { - return civicrm_api3_create_error('Connection failed'); + return $result; +} + +/** + * @param array $params + * Array with keys: + * - cxnId: string + * @return array + */ +function civicrm_api3_cxn_unregister($params) { + if (empty($params['cxnId'])) { + throw new API_Exception('Missing required parameter: cxnId'); } + + $appMeta = CRM_Cxn_BAO_Cxn::getAppMeta($params['cxnId']); + + /** @var \Civi\Cxn\Rpc\RegistrationClient $client */ + $client = \Civi\Core\Container::singleton()->get('cxn_reg_client'); + list($cxnId, $result) = $client->unregister($appMeta, CRM_Utils_Array::value('force', $params, FALSE)); + + return $result; } -- 2.25.1