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;
+ }
+
}
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) {
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;
}