Skip to content

Commit a6b7583

Browse files
committed
refs #39637, gh-111, add syncing ajax endpoint.
1 parent 74bdb9b commit a6b7583

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

Diff for: CRM/Group/Form/Edit.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ private function initSmartMarketingGroup() {
527527
$smartMarketingVendor = ucfirst($smartMarketingVendor);
528528
$smartMarketingClass = 'CRM_Mailing_External_SmartMarketing_'.$smartMarketingVendor;
529529
if (class_exists($smartMarketingClass)) {
530-
$providers = CRM_SMS_BAO_Provider::getProviders(NULL, array('name' => 'CRM_SMS_Provider_Flydove'));
530+
$providers = CRM_SMS_BAO_Provider::getProviders(NULL, array('name' => 'CRM_SMS_Provider_'.$smartMarketingVendor));
531531
if (!empty($providers)) {
532532
$provider = reset($providers);
533533
$this->_smartMarketingService = new $smartMarketingClass($provider['id']);

Diff for: CRM/Mailing/External/SmartMarketing/Flydove.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ class CRM_Mailing_External_SmartMarketing_Flydove extends CRM_Mailing_External_S
44
const API_BASE_PATH = 'https://api.flydove.net/index.php?r=api/';
55
const BATCH_NUM = 500;
66

7+
/**
8+
* Check initialized
9+
*
10+
* @var int
11+
*/
12+
public $_init;
13+
714
/**
815
* tokens of flydove
916
*
@@ -34,10 +41,12 @@ public function __construct($providerId) {
3441
if (!empty($apiParams['tokens'])) {
3542
$this->_tokens = $apiParams['tokens'];
3643
$this->_apiUrl = $dao->api_url;
44+
$this->_init = TRUE;
3745
return TRUE;
3846
}
3947
}
4048
}
49+
$this->_init = FALSE;
4150
return FALSE;
4251
}
4352

@@ -133,7 +142,7 @@ private function apiRequestSend($apiType, $data = NULL) {
133142
}
134143
}
135144

136-
private function batchSchedule($contactIds, $destRemoteGroup, $providerId) {
145+
public function batchSchedule($contactIds, $destRemoteGroup, $providerId) {
137146
$remoteGroups = $this->getRemoteGroups();
138147
if (isset($remoteGroups[$destRemoteGroup])) {
139148
if (!empty(count($contactIds))) {

Diff for: CRM/Mailing/Page/AJAX.php

+45
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,50 @@ static function template() {
6060
echo json_encode($messages);
6161
CRM_Utils_System::civiExit();
6262
}
63+
64+
/**
65+
* AJAX wrapper for sync contact
66+
*
67+
* @return string
68+
*/
69+
public static function addContactToRemote() {
70+
$providerId = CRM_Utils_Request::retrieve('provider_id', 'Integer', CRM_Core_DAO::$_nullObject, TRUE, NULL, 'POST');
71+
$groupId = CRM_Utils_Request::retrieve('group_id', 'Integer', CRM_Core_DAO::$_nullObject, TRUE, NULL, 'POST');
72+
$providers = CRM_SMS_BAO_Provider::getProviders(NULL, array('id' => $providerId));
73+
74+
$groupParams = array(
75+
'id' => $groupId,
76+
);
77+
$group = array();
78+
CRM_Contact_BAO_Group::retrieve($groupParams, $group);
79+
$syncData = json_decode($group['sync_data'], TRUE);
80+
if (!empty($providers) && $group['id'] == $groupId && !empty($syncData['remote_group_id'])) {
81+
$apiParams = array(
82+
'group_id' => $groupId,
83+
'version' => 3,
84+
);
85+
$result = civicrm_api('group_contact', 'get', $apiParams);
86+
if (!empty($result['values'])) {
87+
$contactIds = array();
88+
array_walk($result['values'], function($item) {
89+
$contactIds[$item['contact_id']] = $item['contact_id'];
90+
}, $contactIds);
91+
$provider = reset($providers);
92+
$names = explode('_', $provider['name']);
93+
$vendorName = end($names);
94+
$smartMarketingClass = 'CRM_Mailing_External_SmartMarketing_'.$vendorName;
95+
$smartMarketingService = new $smartMarketingClass($providerId);
96+
try {
97+
$smartMarketingService->batchSchedule($contactIds, $syncData['remote_group_id'], $providerId);
98+
$remoteResult = array('success' => TRUE, 'message' => '');
99+
}
100+
catch(CRM_Core_Exception $e) {
101+
$remoteResult = array('success' => FALSE, 'message' => $e->getMessage());
102+
}
103+
echo json_encode($remoteResult);
104+
CRM_Utils_System::civiExit();
105+
}
106+
}
107+
}
63108
}
64109

Diff for: CRM/Mailing/xml/Menu/Mailing.xml

+5
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,9 @@
203203
<access_arguments>approve mailings</access_arguments>
204204
<weight>850</weight>
205205
</item>
206+
<item>
207+
<path>civicrm/ajax/addContactToRemote</path>
208+
<page_callback>CRM_Mailing_Page_AJAX::addContactToRemote</page_callback>
209+
<access_arguments>access CiviCRM,edit groups</access_arguments>
210+
</item>
206211
</menu>

0 commit comments

Comments
 (0)