CRM-16173 - Cxn.unregister API
authorTim Otten <totten@civicrm.org>
Wed, 25 Mar 2015 11:27:52 +0000 (04:27 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 14 Jul 2015 04:00:06 +0000 (21:00 -0700)
CRM/Cxn/BAO/Cxn.php
api/v3/Cxn.php

index bfc7ce364ddbdd5c24e1b8f6d4fb70472ed9d5ee..4f6fa2f06e7fe6cb79e9777ace4f3b2542d13211 100644 (file)
@@ -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;
+  }
+
 }
index a136fa7690b6dcf5da8a71a97cb205c4c8197623..f70f1f35c1b78c1949243787366c657016dc3009 100644 (file)
@@ -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;
 }