4 * Class CRM_Cxn_CiviCxnStore
6 class CRM_Cxn_CiviCxnStore
implements Civi\Cxn\Rpc\CxnStore\CxnStoreInterface
{
8 protected $cxns = array();
13 public function getAll() {
15 $this->cxns
= array();
16 $dao = new CRM_Cxn_DAO_Cxn();
18 while ($dao->fetch()) {
19 $cxn = $this->convertDaoToCxn($dao);
20 $this->cxns
[$cxn['cxnId']] = $cxn;
29 public function getByCxnId($cxnId) {
30 if (isset($this->cxns
[$cxnId])) {
31 return $this->cxns
[$cxnId];
33 $dao = new CRM_Cxn_DAO_Cxn();
34 $dao->cxn_guid
= $cxnId;
35 if ($dao->find(TRUE)) {
36 $this->cxns
[$cxnId] = $this->convertDaoToCxn($dao);
37 return $this->cxns
[$cxnId];
47 public function getByAppId($appId) {
48 $dao = new CRM_Cxn_DAO_Cxn();
49 $dao->app_guid
= $appId;
50 if ($dao->find(TRUE)) {
51 $this->cxns
[$dao->cxn_guid
] = $this->convertDaoToCxn($dao);
52 return $this->cxns
[$dao->cxn_guid
];
62 public function add($cxn) {
63 $dao = new CRM_Cxn_DAO_Cxn();
64 $dao->cxn_guid
= $cxn['cxnId'];
66 $this->convertCxnToDao($cxn, $dao);
70 UPDATE civicrm_cxn SET created_date = modified_date
71 WHERE created_date IS NULL
74 CRM_Core_DAO
::executeQuery($sql, array(
75 1 => array($cxn['cxnId'], 'String'),
78 $this->cxns
[$cxn['cxnId']] = $cxn;
84 public function remove($cxnId) {
85 CRM_Core_DAO
::executeQuery('DELETE FROM civicrm_cxn WHERE cxn_guid = %1', array(
86 1 => array($cxnId, 'String'),
88 unset($this->cxns
[$cxnId]);
92 * @param CRM_Cxn_DAO_Cxn $dao
94 * Array-encoded connection details.
96 protected function convertDaoToCxn($dao) {
97 $appMeta = json_decode($dao->app_meta
, TRUE);
99 'cxnId' => $dao->cxn_guid
,
100 'secret' => $dao->secret
,
101 'appId' => $dao->app_guid
,
102 'appUrl' => $appMeta['appUrl'],
103 'siteUrl' => CRM_Cxn_BAO_Cxn
::getSiteCallbackUrl(),
104 'perm' => json_decode($dao->perm
, TRUE),
110 * Array-encoded connection details.
111 * @param CRM_Cxn_DAO_Cxn $dao
113 protected function convertCxnToDao($cxn, $dao) {
114 $dao->cxn_guid
= $cxn['cxnId'];
115 $dao->secret
= $cxn['secret'];
116 $dao->app_guid
= $cxn['appId'];
117 $dao->perm
= json_encode($cxn['perm']);
119 // Note: we don't save siteUrl because it's more correct to regenerate on-demand.
120 // Note: we don't save appUrl, but other processes will update appMeta.