Action MailingEventSubscribe will fail silently if the Mailing Group is not a "Public" group
Action MailingEventSubscribe will fail silently if the Mailing Group is not a "Public" group. The CiviCRM APIv3 call, civicrm_api3('MailingEventSubscribe', 'create'... will simply return "Subscription failed" when a Mailing Group is selected that is NOT Public. This is the executed in a try catch which has... // Do nothing - causing the silent failure, which took a LONG time to track down.
What I would really like to see is a user interface improvement to reduce the groups that can be selected to just those Public Groups, but there doesn't seem to be a way to do that currently in this Extension.
However, I can see that there is a way to at least perform a validation on the group selected and raise an error if a non-Public group was selected. Unfortunately, I cannot see anywhere in the UI where the error message is shown to the user. Possibly another improvement!
protected function doAction(ParameterBagInterface $parameters, ParameterBagInterface $output) {
// Get default group ID from configuration.
if ($this->configuration->getParameter('group_id')) {
$subscribe_params['group_id'] = $this->configuration->getParameter('group_id');
}
// Overwrite with group ID from parameters if given.
if ($parameters->doesParameterExists('group_id')) {
$subscribe_params['group_id'] = $parameters->getParameter('group_id');
}
$subscribe_params['email'] = $parameters->getParameter('email');
if ($parameters->doesParameterExists('contact_id')) {
$subscribe_params['contact_id'] = $parameters->getParameter('contact_id');
}
try {
$result = civicrm_api3('MailingEventSubscribe', 'Create', $subscribe_params);
$output->setParameter('id', $result['id']);
} catch (\Exception $e) {
// Do nothing.
}
}
}
Agileware Ref: CIVICRM-1857