3 class CRM_Cxn_CiviCxnStore
implements Civi\Cxn\Rpc\CxnStore\CxnStoreInterface
{
5 protected $cxns = array();
10 public function getAll() {
12 $this->cxns
= array();
13 $dao = new CRM_Cxn_DAO_Cxn();
15 while ($dao->fetch()) {
16 $cxn = $this->convertDaoToCxn($dao);
17 $this->cxns
[$cxn['cxnId']] = $cxn;
26 public function getByCxnId($cxnId) {
27 if (isset($this->cxns
[$cxnId])) {
28 return $this->cxns
[$cxnId];
30 $dao = new CRM_Cxn_DAO_Cxn();
31 $dao->cxn_guid
= $cxnId;
32 if ($dao->find(TRUE)) {
33 $this->cxns
[$cxnId] = $this->convertDaoToCxn($dao);
34 return $this->cxns
[$cxnId];
44 public function getByAppId($appId) {
45 $dao = new CRM_Cxn_DAO_Cxn();
46 $dao->app_guid
= $appId;
47 if ($dao->find(TRUE)) {
48 $this->cxns
[$dao->cxn_guid
] = $this->convertDaoToCxn($dao);
49 return $this->cxns
[$dao->cxn_guid
];
59 public function add($cxn) {
60 $dao = new CRM_Cxn_DAO_Cxn();
61 $dao->cxn_guid
= $cxn['cxnId'];
63 $this->convertCxnToDao($cxn, $dao);
67 UPDATE civicrm_cxn SET created_date = modified_date
68 WHERE created_date IS NULL
71 CRM_Core_DAO
::executeQuery($sql, array(
72 1 => array($cxn['cxnId'], 'String'),
75 $this->cxns
[$cxn['cxnId']] = $cxn;
81 public function remove($cxnId) {
82 CRM_Core_DAO
::executeQuery('DELETE FROM civicrm_cxn WHERE cxn_guid = %1', array(
83 1 => array($cxnId, 'String'),
85 unset($this->cxns
[$cxnId]);
89 * @param CRM_Cxn_DAO_Cxn $dao
91 * Array-encoded connection details.
93 protected function convertDaoToCxn($dao) {
94 $appMeta = json_decode($dao->app_meta
, TRUE);
96 'cxnId' => $dao->cxn_guid
,
97 'secret' => $dao->secret
,
98 'appId' => $dao->app_guid
,
99 'appUrl' => $appMeta['appUrl'],
100 'siteUrl' => CRM_Cxn_BAO_Cxn
::getSiteCallbackUrl(),
101 'perm' => json_decode($dao->perm
, TRUE),
107 * Array-encoded connection details.
108 * @param CRM_Cxn_DAO_Cxn $dao
110 protected function convertCxnToDao($cxn, $dao) {
111 $dao->cxn_guid
= $cxn['cxnId'];
112 $dao->secret
= $cxn['secret'];
113 $dao->app_guid
= $cxn['appId'];
114 $dao->perm
= json_encode($cxn['perm']);
116 // Note: we don't save siteUrl because it's more correct to regenerate on-demand.
117 // Note: we don't save appUrl, but other processes will update appMeta.