From: Tim Otten Date: Wed, 13 May 2020 04:11:04 +0000 (-0700) Subject: civicrm/mailing/url - Emit more $context for redirects X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=78e62e18de7d40523c568dbee66800efe4ce823b;p=civicrm-core.git 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); } ``` --- diff --git a/CRM/Mailing/Page/Url.php b/CRM/Mailing/Page/Url.php index 40daca3de6..ece6a55990 100644 --- a/CRM/Mailing/Page/Url.php +++ b/CRM/Mailing/Page/Url.php @@ -58,7 +58,11 @@ class CRM_Mailing_Page_Url extends CRM_Core_Page { $url .= '#' . $pieces['fragment']; } } - CRM_Utils_System::redirect($url); + CRM_Utils_System::redirect($url, [ + 'for' => 'civicrm/mailing/url', + 'queue_id' => $queue_id, + 'url_id' => $url_id, + ]); } /**