civicrm/mailing/url - Emit more $context for redirects
authorTim Otten <totten@civicrm.org>
Wed, 13 May 2020 04:11:04 +0000 (21:11 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 13 May 2020 07:05:49 +0000 (00:05 -0700)
commit78e62e18de7d40523c568dbee66800efe4ce823b
treee8892b1cb66cf6a66ee838a7ee630301d7532a70
parent5c9b70e587b61e984094731d01bda29b502e5f60
civicrm/mailing/url - Emit more $context for redirects

For example, suppose your goal is to recognize any CiviMail links going to `woogle.com` and
append code with the mailing ID (`&src=civimail_123`). Do this:

```php
  if ($context['for'] === 'civicrm/mailing/url' && preg_match('/woogle\.com$/', $url->getHost())) {
    $mailing_id = CRM_Core_DAO::singleValueQuery('
      SELECT mj.mailing_id FROM civicrm_mailing_event_queue meq
      INNER JOIN civicrm_mailing_job mj ON mj.id = meq.job_id
      WHERE meq.id = %1
    ', [
      1 => [$context['queue_id'], 'Int']
    ]);
    $url = $url->withQuery($url->getQuery() . '&src=civimail_' . $mailing_id);
  }
```
CRM/Mailing/Page/Url.php