include email_id in group membership

This commit is contained in:
Marc Koch 2025-03-31 17:58:01 +02:00
parent 8dab2377f5
commit 5a424771fd
Signed by: marc.koch
GPG key ID: 12406554CFB028B9
5 changed files with 86 additions and 13 deletions

View file

@ -172,16 +172,20 @@ class GroupMailingList extends BaseMailingList {
* Add a contact to this mailing lists related group.
*
* @param int $contactId
* @param ?int $contactEmailId
*
* @return void
* @throws \Civi\Mailinglistsync\Exceptions\MailinglistException
*/
protected function addContactToGroup(int $contactId): void {
protected function addContactToGroup(int $contactId, int $contactEmailId = NULL): void {
try {
\Civi\Api4\GroupContact::create()
$query = \Civi\Api4\GroupContact::create()
->addValue('contact_id', $contactId)
->addValue('group_id', $this->group['id'])
->execute();
->addValue('group_id', $this->group['id']);
if ($contactEmailId) {
$query->addValue('email_id', $contactEmailId);
}
$query->execute();
}
catch (\Exception $e) {
if ($e->getMessage() === 'DB Error: already exists') {