You are here

protected function CampaignMonitorSubscriptionManager::unsubscribeProcess in Campaign Monitor 8.2

Unsubscribes a member from a CampaignMonitor list.

See also

CampaignMonitor_Lists::unsubscribe()

1 call to CampaignMonitorSubscriptionManager::unsubscribeProcess()
CampaignMonitorSubscriptionManager::userUnsubscribe in src/CampaignMonitorSubscriptionManager.php
Unsubscribes a member from a CampaignMonitor list.

File

src/CampaignMonitorSubscriptionManager.php, line 598

Class

CampaignMonitorSubscriptionManager
Manager for Campaignmonitor subscriptions.

Namespace

Drupal\campaignmonitor

Code

protected function unsubscribeProcess($list_id, $email, $delete, $goodbye, $notify) {
  $lists = $this->campaignMonitorManager
    ->getLists();
  try {
    if ($this->campaignMonitorManager
      ->unsubscribe($list_id, $email)) {
      $this->messenger
        ->addStatus($this
        ->t('You are now unsubscribed from the "@list" list.', [
        '@list' => html_entity_decode($lists[$list_id]['name']),
      ]));
      $this->moduleHandler
        ->invokeAll('campaignmonitor_unsubscribe', [
        $list_id,
        $email,
      ]);

      // Clear user cache:
      $this->campaignMonitorManager
        ->removeSubscriberFromCache($list_id, $email);
      return TRUE;
    }
    return FALSE;
  } catch (Exception $e) {
    $this
      ->logger('campaignmonitor')
      ->error('An error occurred unsubscribing {email} from list {list}. "{message}"', [
      'email' => $email,
      'list' => $list_id,
      'message' => $e
        ->getMessage(),
    ]);
  }
  return FALSE;
}