🔖 Version 1.0.0-beta
This commit is contained in:
parent
c93a06972b
commit
460a811554
26 changed files with 2480 additions and 771 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
use Civi\Mailinglistsync\ADGroupMailingList;
|
||||
use Civi\Mailinglistsync\Exceptions\MailinglistException;
|
||||
use Civi\Mailinglistsync\MailingListSettings;
|
||||
use CRM_Mailinglistsync_ExtensionUtil as E;
|
||||
|
||||
/**
|
||||
|
@ -14,31 +15,31 @@ use CRM_Mailinglistsync_ExtensionUtil as E;
|
|||
*/
|
||||
function _civicrm_api3_mailinglistsync_Adgroupsync_spec(&$spec) {
|
||||
$spec['sid'] = [
|
||||
'api.required' => 1,
|
||||
'api.required' => 0,
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => E::ts('Active Directory SID'),
|
||||
'description' => E::ts('The Active Directory SID of the group'),
|
||||
];
|
||||
$spec['email'] = [
|
||||
'api.required' => 1,
|
||||
'api.required' => 0,
|
||||
'type' => CRM_Utils_Type::T_EMAIL,
|
||||
'title' => 'Email Address',
|
||||
'description' => 'Email address of the mailing list',
|
||||
];
|
||||
$spec['recipients'] = [
|
||||
'api.required' => 1,
|
||||
'api.required' => 0,
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => E::ts('Recipients'),
|
||||
'description' => E::ts('Array of email addresses and SIDs'),
|
||||
];
|
||||
$spec['name'] = [
|
||||
'api.required' => 1,
|
||||
'api.required' => 0,
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => E::ts('Mail List Name'),
|
||||
'description' => E::ts('Name of the mailing list'),
|
||||
];
|
||||
$spec['description'] = [
|
||||
'api.required' => 1,
|
||||
'api.required' => 0,
|
||||
'type' => CRM_Utils_Type::T_LONGTEXT,
|
||||
'title' => E::ts('Mail List Description'),
|
||||
'description' => E::ts('Description of the mailing list'),
|
||||
|
@ -58,123 +59,180 @@ function _civicrm_api3_mailinglistsync_Adgroupsync_spec(&$spec) {
|
|||
* @see civicrm_api3_create_success
|
||||
*/
|
||||
function civicrm_api3_mailinglistsync_Adgroupsync($params) {
|
||||
|
||||
// Filter illegal params
|
||||
$allowed_params = [];
|
||||
_civicrm_api3_mailinglistsync_Adgroupsync_spec($allowed_params);
|
||||
$params = array_intersect_key($params, $allowed_params);
|
||||
|
||||
// Prepare result array
|
||||
$result = [
|
||||
'sid' => $params['sid'],
|
||||
'email' => $params['email'],
|
||||
'name' => $params['name'],
|
||||
'description' => $params['description'],
|
||||
'group_created' => FALSE,
|
||||
'group_updated' => FALSE,
|
||||
];
|
||||
// Check if the mailing list sync is enabled
|
||||
$enabled = (bool) MailingListSettings::get('enable');
|
||||
if (!$enabled) {
|
||||
return civicrm_api3_create_success(
|
||||
['message' => 'Mailing list sync is disabled'], [], 'Mailinglist', 'Adgroupsync'
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
// Try to get mailing list by SID
|
||||
$adGroupMailingList = ADGroupMailingList::getBySID($params['sid']);
|
||||
// Validate params
|
||||
|
||||
// If no AD group mailing list found, create new
|
||||
if (!$adGroupMailingList) {
|
||||
// Decode recipients JSON if it's a string
|
||||
if (!empty($params['recipients'])) {
|
||||
if (is_string($params['recipients'])) {
|
||||
try {
|
||||
$adGroupMailingList = ADGroupMailingList::createGroup(
|
||||
title: $params['name'],
|
||||
description: $params['description'],
|
||||
email: $params['email'],
|
||||
sid: $params['sid'],
|
||||
);
|
||||
$result['group_created']['group_id'] = $adGroupMailingList->getId();
|
||||
$result['group_created']['is_error'] = FALSE;
|
||||
$params['recipients'] = json_decode($params['recipients'], TRUE);
|
||||
}
|
||||
catch (MailinglistException $e) {
|
||||
\Civi::log(E::LONG_NAME)->error($e->getLogMessage());
|
||||
$result['group_created']['is_error'] = TRUE;
|
||||
catch (Exception $e) {
|
||||
return civicrm_api3_create_error(
|
||||
'Failed to decode recipients JSON',
|
||||
[
|
||||
'params' => $params,
|
||||
'entity' => 'Mailinglistsync',
|
||||
'action' => 'Adgroupsync',
|
||||
]);
|
||||
}
|
||||
}
|
||||
// Throw error if recipients is not an array
|
||||
if (!is_array($params['recipients'])) {
|
||||
return civicrm_api3_create_error(
|
||||
'Recipients must be an array',
|
||||
[
|
||||
'params' => $params,
|
||||
'entity' => 'Mailinglistsync',
|
||||
'action' => 'Adgroupsync',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Sync AD group mailing list values
|
||||
else {
|
||||
if ($adGroupMailingList->getTitle() !== $params['name']) {
|
||||
try {
|
||||
$adGroupMailingList->updateGroupTitle($params['name']);
|
||||
\Civi::log(E::LONG_NAME)->info(
|
||||
"Updated group '{$adGroupMailingList->getId()}' title from '{$adGroupMailingList->getTitle()}' to '{$params['name']}'"
|
||||
);
|
||||
$result['group_updated']['title'] = [
|
||||
'is_error' => FALSE,
|
||||
'old' => $adGroupMailingList->getTitle(),
|
||||
'new' => $params['name'],
|
||||
];
|
||||
}
|
||||
catch (MailinglistException $e) {
|
||||
\Civi::log(E::LONG_NAME)->error($e->getLogMessage());
|
||||
$result['group_updated']['title'] = [
|
||||
'is_error' => TRUE,
|
||||
'error' => $e->getLogMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
if ($adGroupMailingList->getGroupDescription() !== $params['description']) {
|
||||
try {
|
||||
$adGroupMailingList->updateGroupDescription($params['description']);
|
||||
\Civi::log(E::LONG_NAME)->info(
|
||||
"Updated group '{$adGroupMailingList->getId()}' description.'"
|
||||
);
|
||||
$result['group_updated']['description'] = [
|
||||
'is_error' => FALSE,
|
||||
'old' => $adGroupMailingList->getGroupDescription(),
|
||||
'new' => $params['description'],
|
||||
];
|
||||
}
|
||||
catch (MailinglistException $e) {
|
||||
\Civi::log(E::LONG_NAME)->error($e->getLogMessage());
|
||||
$result['group_updated']['description'] = [
|
||||
'is_error' => TRUE,
|
||||
'error' => $e->getLogMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
if ($adGroupMailingList->getEmailAddress() !== $params['email']) {
|
||||
try {
|
||||
$adGroupMailingList->updateEmailAddress($params['email']);
|
||||
\Civi::log(E::LONG_NAME)->info(
|
||||
"Updated group '{$adGroupMailingList->getId()}' email address from '{$adGroupMailingList->getEmailAddress()}' to '{$params['email']}'"
|
||||
);
|
||||
$result['group_updated']['email'] = [
|
||||
'is_error' => FALSE,
|
||||
'old' => $adGroupMailingList->getEmailAddress(),
|
||||
'new' => $params['email'],
|
||||
];
|
||||
}
|
||||
catch (MailinglistException $e) {
|
||||
\Civi::log(E::LONG_NAME)->error($e->getLogMessage());
|
||||
$result['group_updated']['email'] = [
|
||||
'is_error' => TRUE,
|
||||
'error' => $e->getLogMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
$adGroupMailingList->save();
|
||||
// If group is updated
|
||||
if (
|
||||
!empty($params['sid']) &&
|
||||
!empty($params['email']) &&
|
||||
!empty($params['name'])
|
||||
) {
|
||||
// Prepare result array
|
||||
$result = [
|
||||
'group' =>
|
||||
[
|
||||
'sid' => $params['sid'],
|
||||
'email' => $params['email'],
|
||||
'name' => $params['name'],
|
||||
'description' => $params['description'] ?? '',
|
||||
'created' => FALSE,
|
||||
'updated' => FALSE,
|
||||
],
|
||||
];
|
||||
|
||||
if ($result['group_updated'] ?? FALSE) {
|
||||
$result['group_updated']['error_count'] = count(array_filter($result['group_updated'], fn($v) => $v['is_error']));
|
||||
$result['group_updated']['is_error'] = $result['group_updated']['error_count'] > 0;
|
||||
$result['group_updated']['group_id'] = $adGroupMailingList->getId();
|
||||
try {
|
||||
// Try to get mailing list by SID
|
||||
$adGroupMailingList = ADGroupMailingList::getBySID($params['sid']);
|
||||
|
||||
// If no AD group mailing list found, create new
|
||||
if (!$adGroupMailingList) {
|
||||
try {
|
||||
$adGroupMailingList = ADGroupMailingList::createGroup(
|
||||
title: $params['name'],
|
||||
email: $params['email'],
|
||||
description: $params['description'],
|
||||
sid: $params['sid'],
|
||||
);
|
||||
$result['group']['created']['group_id'] = $adGroupMailingList->getId();
|
||||
$result['group']['created']['is_error'] = 0;
|
||||
}
|
||||
catch (MailinglistException $e) {
|
||||
\Civi::log(E::LONG_NAME)->error($e->getLogMessage());
|
||||
$result['group']['created']['is_error'] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Sync AD group mailing list values
|
||||
else {
|
||||
if ($adGroupMailingList->getTitle() !== $params['name']) {
|
||||
try {
|
||||
$adGroupMailingList->updateGroupTitle($params['name']);
|
||||
\Civi::log(E::LONG_NAME)->info(
|
||||
"Updated group '{$adGroupMailingList->getId()}' title from '{$adGroupMailingList->getTitle()}' to '{$params['name']}'"
|
||||
);
|
||||
$result['group']['updated']['title'] = [
|
||||
'is_error' => 0,
|
||||
'old' => $adGroupMailingList->getTitle(),
|
||||
'new' => $params['name'],
|
||||
];
|
||||
}
|
||||
catch (MailinglistException $e) {
|
||||
\Civi::log(E::LONG_NAME)->error($e->getLogMessage());
|
||||
$result['group']['updated']['title'] = [
|
||||
'is_error' => 1,
|
||||
'error' => $e->getLogMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
if ($adGroupMailingList->getGroupDescription() !== ($params['description'] ?? '')) {
|
||||
try {
|
||||
$adGroupMailingList->updateGroupDescription($params['description']);
|
||||
\Civi::log(E::LONG_NAME)->info(
|
||||
"Updated group '{$adGroupMailingList->getId()}' description.'"
|
||||
);
|
||||
$result['group']['updated']['description'] = [
|
||||
'is_error' => 0,
|
||||
'old' => $adGroupMailingList->getGroupDescription(),
|
||||
'new' => $params['description'],
|
||||
];
|
||||
}
|
||||
catch (MailinglistException $e) {
|
||||
\Civi::log(E::LONG_NAME)->error($e->getLogMessage());
|
||||
$result['group']['updated']['description'] = [
|
||||
'is_error' => 1,
|
||||
'error' => $e->getLogMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
if ($adGroupMailingList->getEmailAddress() !== $params['email']) {
|
||||
try {
|
||||
$adGroupMailingList->updateEmailAddress($params['email']);
|
||||
\Civi::log(E::LONG_NAME)->info(
|
||||
"Updated group '{$adGroupMailingList->getId()}' email address from '{$adGroupMailingList->getEmailAddress()}' to '{$params['email']}'"
|
||||
);
|
||||
$result['group']['updated']['email'] = [
|
||||
'is_error' => 0,
|
||||
'old' => $adGroupMailingList->getEmailAddress(),
|
||||
'new' => $params['email'],
|
||||
];
|
||||
}
|
||||
catch (MailinglistException $e) {
|
||||
\Civi::log(E::LONG_NAME)->error($e->getLogMessage());
|
||||
$result['group']['updated']['email'] = [
|
||||
'is_error' => 1,
|
||||
'error' => $e->getLogMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
$adGroupMailingList->save();
|
||||
|
||||
if ($result['group']['updated'] ?? FALSE) {
|
||||
$result['group']['updated']['error_count'] = count(array_filter($result['group']['updated'], fn($v) => $v['is_error']));
|
||||
$result['group']['updated']['is_error'] = (int) ($result['group']['updated']['error_count'] > 0);
|
||||
}
|
||||
$result['group']['group_id'] = $adGroupMailingList->getId();
|
||||
}
|
||||
}
|
||||
catch (MailinglistException $me) {
|
||||
\Civi::log(E::LONG_NAME)->error($me->getLogMessage());
|
||||
return civicrm_api3_create_error($me->getLogMessage(),
|
||||
[
|
||||
'values' => $result,
|
||||
'params' => $params,
|
||||
'entity' => 'Mailinglistsync',
|
||||
'action' => 'Adgroupsync',
|
||||
]);
|
||||
}
|
||||
|
||||
// Sync group mailing list members
|
||||
$result['recipients_updated'] = $adGroupMailingList->syncRecipients($params['recipients']);
|
||||
$result['recipients'] = $adGroupMailingList->syncRecipients($params['recipients']);
|
||||
|
||||
// Return error response if any errors occurred
|
||||
$totalErrors = (int) ($result['group_created']['is_error'] ?? 0)
|
||||
+ ($result['group_updated']['error_count'] ?? 0)
|
||||
+ ($result['recipients_updated']['error_count'] ?? 0);
|
||||
$result['is_error'] = $totalErrors > 0;
|
||||
$totalErrors = (int) ($result['group']['created']['is_error'] ?? 0)
|
||||
+ ($result['group']['updated']['error_count'] ?? 0)
|
||||
+ ($result['recipients']['error_count'] ?? 0);
|
||||
$result['is_error'] = (int) ($totalErrors > 0);
|
||||
$result['error_count'] = $totalErrors;
|
||||
if ($totalErrors > 0) {
|
||||
return civicrm_api3_create_error(
|
||||
|
@ -185,15 +243,45 @@ function civicrm_api3_mailinglistsync_Adgroupsync($params) {
|
|||
'entity' => 'Mailinglistsync',
|
||||
'action' => 'Adgroupsync',
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
// Else return success response
|
||||
return civicrm_api3_create_success($result, $params, 'Mailinglistsync', 'Adgroupsync');
|
||||
}
|
||||
catch (MailinglistException $me) {
|
||||
\Civi::log(E::LONG_NAME)->error($me->getLogMessage());
|
||||
return civicrm_api3_create_error($me->getLogMessage(),
|
||||
|
||||
// If only recipients are updated
|
||||
elseif (
|
||||
!empty($params['recipients']) &&
|
||||
empty($params['sid']) &&
|
||||
empty($params['email']) &&
|
||||
empty($params['name']) &&
|
||||
empty($params['description'])
|
||||
) {
|
||||
$result = [];
|
||||
|
||||
// Update recipients
|
||||
$result['recipients'] = ADGroupMailingList::syncContacts($params['recipients']);
|
||||
|
||||
// Return error response if any errors occurred
|
||||
$totalErrors = $result['recipients']['error_count'] ?? 0;
|
||||
$result['count'] = $result['recipients']['count'] ?? 0;
|
||||
$result['is_error'] = (int) ($totalErrors > 0);
|
||||
$result['error_count'] = $totalErrors;
|
||||
if ($totalErrors > 0) {
|
||||
return civicrm_api3_create_error(
|
||||
"Failed to sync recipients. $totalErrors errors occurred.",
|
||||
[
|
||||
'values' => $result,
|
||||
'params' => $params,
|
||||
'entity' => 'Mailinglistsync',
|
||||
'action' => 'Adgroupsync',
|
||||
]);
|
||||
}
|
||||
// Else return success response
|
||||
return civicrm_api3_create_success($result ? $result['count'] : [], $params, 'Mailinglistsync', 'Adgroupsync');
|
||||
}
|
||||
else {
|
||||
return civicrm_api3_create_error(
|
||||
'Missing required parameters',
|
||||
[
|
||||
'params' => $params,
|
||||
'entity' => 'Mailinglistsync',
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
|
||||
use Civi\Mailinglistsync\MailingListSettings;
|
||||
use Civi\Mailinglistsync\QueueHelper;
|
||||
use Civi\Mailinglistsync\MailingListRecipient;
|
||||
use CRM_Mailinglist_ExtensionUtil as E;
|
||||
|
||||
/**
|
||||
|
@ -11,7 +13,9 @@ use CRM_Mailinglist_ExtensionUtil as E;
|
|||
*
|
||||
* @see https://docs.civicrm.org/dev/en/latest/framework/api-architecture/
|
||||
*/
|
||||
function _civicrm_api3_mailinglistsync_Mlmmjsync_spec(&$spec) {}
|
||||
function _civicrm_api3_mailinglistsync_Mlmmjsync_spec(&$spec) {
|
||||
return $spec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mailinglistsync.Mlmmjsync API
|
||||
|
@ -21,77 +25,121 @@ function _civicrm_api3_mailinglistsync_Mlmmjsync_spec(&$spec) {}
|
|||
* @return array
|
||||
* API result descriptor
|
||||
*
|
||||
* @throws CRM_Core_Exception
|
||||
* @see civicrm_api3_create_success
|
||||
*
|
||||
* @throws CRM_Core_Exception
|
||||
*/
|
||||
function civicrm_api3_mailinglistsync_Mlmmjsync($params) {
|
||||
try {
|
||||
|
||||
// Get queues
|
||||
$qh = QueueHelper::getInstance();
|
||||
$groupQueue = $qh->getGroupQueue();
|
||||
$eventQueue = $qh->getEventQueue();
|
||||
$emailQueue = $qh->getEmailQueue();
|
||||
|
||||
// Create runners
|
||||
$groupRunner = new CRM_Queue_Runner([
|
||||
'title' => ts('ProPeace GroupMailinglist Runner'),
|
||||
'queue' => $groupQueue,
|
||||
'errorMode' => CRM_Queue_Runner::ERROR_CONTINUE,
|
||||
]);
|
||||
$eventRunner = new CRM_Queue_Runner([
|
||||
'title' => ts('ProPeace EventMailinglist Runner'),
|
||||
'queue' => $eventQueue,
|
||||
'errorMode' => CRM_Queue_Runner::ERROR_CONTINUE,
|
||||
]);
|
||||
$emailRunner = new CRM_Queue_Runner([
|
||||
'title' => ts('ProPeace EmailMailinglist Runner'),
|
||||
'queue' => $emailQueue,
|
||||
'errorMode' => CRM_Queue_Runner::ERROR_CONTINUE,
|
||||
]);
|
||||
|
||||
// Run runners
|
||||
$results = [];
|
||||
$continue = TRUE;
|
||||
while($continue) {
|
||||
$result = $groupRunner->runNext(false);
|
||||
if (!$result['is_continue']) {
|
||||
$continue = false;
|
||||
// Check if the mailing list sync is enabled
|
||||
$enabled = (bool) MailingListSettings::get('enable');
|
||||
if (!$enabled) {
|
||||
return civicrm_api3_create_success(
|
||||
['message' => 'Mailing list sync is disabled'], [], 'Mailinglist', 'Mlmmjsync'
|
||||
);
|
||||
}
|
||||
$results['runners'][] = $result;
|
||||
}
|
||||
|
||||
$groups = $qh->getGroups();
|
||||
$events = $qh->getEvents();
|
||||
$emails = $qh->getEmails();
|
||||
$is_error = FALSE;
|
||||
|
||||
// TODO: Sync groups and events just once and invoke syncing
|
||||
// Get queues
|
||||
$qh = QueueHelper::getInstance();
|
||||
$groupQueue = $qh->getGroupQueue();
|
||||
$eventQueue = $qh->getEventQueue();
|
||||
$emailQueue = $qh->getEmailQueue();
|
||||
|
||||
$mailingListsToSync = [];
|
||||
foreach ($groups as $group) {
|
||||
$mailingListsToSync[$group->getId()] = $group;
|
||||
}
|
||||
foreach ($events as $event) {
|
||||
$mailingListsToSync[$event->getId()] = $event;
|
||||
}
|
||||
foreach ($emails as $email) {
|
||||
$emailGroups = $email->getGroups();
|
||||
$emailEvents = $email->getEvents();
|
||||
foreach ($emailGroups as $group) {
|
||||
// Create runners
|
||||
$groupRunner = new CRM_Queue_Runner([
|
||||
'title' => ts('ProPeace GroupMailinglist Runner'),
|
||||
'queue' => $groupQueue,
|
||||
'errorMode' => CRM_Queue_Runner::ERROR_CONTINUE,
|
||||
]);
|
||||
$eventRunner = new CRM_Queue_Runner([
|
||||
'title' => ts('ProPeace EventMailinglist Runner'),
|
||||
'queue' => $eventQueue,
|
||||
'errorMode' => CRM_Queue_Runner::ERROR_CONTINUE,
|
||||
]);
|
||||
$emailRunner = new CRM_Queue_Runner([
|
||||
'title' => ts('ProPeace EmailMailinglist Runner'),
|
||||
'queue' => $emailQueue,
|
||||
'errorMode' => CRM_Queue_Runner::ERROR_CONTINUE,
|
||||
]);
|
||||
|
||||
// Run runners
|
||||
$results = [];
|
||||
foreach ([$groupRunner, $eventRunner, $emailRunner] as $runner) {
|
||||
$continue = TRUE;
|
||||
$count = 0;
|
||||
$errors = [];
|
||||
while ($continue) {
|
||||
$count++;
|
||||
|
||||
$result = $runner->runNext(FALSE);
|
||||
$continue = $result['is_continue'];
|
||||
|
||||
if ($result['is_error']) {
|
||||
$error = $result['exception']->getMessage();
|
||||
// If the error is 'Failed to claim next task' we should stop the runner
|
||||
if ($error === 'Failed to claim next task') {
|
||||
$continue = FALSE;
|
||||
}
|
||||
else {
|
||||
$errors[] = $error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$results['runners'][$runner->title][] = [
|
||||
'task_count' => $count,
|
||||
'errors' => $errors,
|
||||
];
|
||||
|
||||
$is_error = !empty($errors) || $is_error;
|
||||
}
|
||||
|
||||
$groups = $qh->getGroups();
|
||||
$events = $qh->getEvents();
|
||||
$emails = $qh->getEmails();
|
||||
|
||||
// Sync groups and events just once and invoke syncing
|
||||
$mailingListsToSync = [];
|
||||
foreach ($groups as $group) {
|
||||
$mailingListsToSync[$group->getId()] = $group;
|
||||
}
|
||||
foreach ($emailEvents as $event) {
|
||||
foreach ($events as $event) {
|
||||
$mailingListsToSync[$event->getId()] = $event;
|
||||
}
|
||||
foreach ($emails as $email) {
|
||||
$recipient = MailingListRecipient::getContactIdEmail($email);
|
||||
$emailGroups = $recipient->getMailingLists();
|
||||
$emailEvents = $recipient->getEventMailingLists();
|
||||
foreach ($emailGroups as $group) {
|
||||
$mailingListsToSync[$group->getId()] = $group;
|
||||
}
|
||||
foreach ($emailEvents as $event) {
|
||||
$mailingListsToSync[$event->getId()] = $event;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($mailingListsToSync as $mailingList) {
|
||||
$results['mailing_lists'][$mailingList->getEmailAddress()] = $mailingList->sync(); // TODO: re-add failed task to queue
|
||||
}
|
||||
|
||||
if ($is_error) {
|
||||
return civicrm_api3_create_error('One or more errors occurred during the sync process', [
|
||||
'params' => $params,
|
||||
'results' => $results,
|
||||
'entity' => 'Mailinglistsync',
|
||||
'action' => 'Mlmmjsync',
|
||||
]);
|
||||
}
|
||||
return civicrm_api3_create_success($results, [], 'Mailinglist', 'Mlmmjsync');
|
||||
}
|
||||
|
||||
foreach ($mailingListsToSync as $mailingList) {
|
||||
$results['mailing_lists'][] = $mailingList->sync();
|
||||
catch (Exception $e) {
|
||||
return civicrm_api3_create_error($e->getMessage(), [
|
||||
'params' => $params,
|
||||
'entity' => 'Mailinglistsync',
|
||||
'action' => 'Mlmmjsync',
|
||||
]);
|
||||
}
|
||||
|
||||
return civicrm_api3_create_success($results, [], 'Mailinglist', 'Mlmmjsync');
|
||||
|
||||
/*
|
||||
throw new CRM_Core_Exception('Everyone knows that the magicword is "sesame"', 'magicword_incorrect');
|
||||
*/
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue