Skip to content

Commit

Permalink
Merge pull request #30626 from bsilvern/#5331C-tracking-url
Browse files Browse the repository at this point in the history
dev/core#5331 Fix tracking URL not modified
  • Loading branch information
mlutfy authored Feb 24, 2025
2 parents 5f0d490 + 1031ab5 commit fffe7b8
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions CRM/Mailing/BAO/MailingTrackableURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,34 @@ private static function getBasicTrackerURL($url, $mailing_id, $queue_id) {

$hrefExists = FALSE;

$tracker = new CRM_Mailing_BAO_MailingTrackableURL();
if (preg_match('/^href/i', $url)) {
$url = preg_replace('/^href[ ]*=[ ]*[\'"](.*?)[\'"]$/i', '$1', $url);
$hrefExists = TRUE;
}

$tracker->url = $url;
$tracker->mailing_id = $mailing_id;

if (!$tracker->find(TRUE)) {
$turl = CRM_Utils_Type::escape(CRM_Mailing_BAO_MailingTrackableURL::getTableName(), 'MysqlColumnNameOrAlias');

// search for an existing identical url using the BINARY operator to avoid
// matching an entry which differs only by case or by trailing whitespace
$search = CRM_Core_DAO::executeQuery(
"SELECT `url`, `id` FROM $turl
WHERE BINARY $turl.`url` = %1 AND $turl.`mailing_id` = %2",
[
1 => [$url, 'String'],
2 => [$mailing_id, 'Integer'],
]
);

if (!$search->fetch()) {
$tracker = new CRM_Mailing_BAO_MailingTrackableURL();
$tracker->url = $url;
$tracker->mailing_id = $mailing_id;
$tracker->save();
$id = $tracker->id;
}
else {
$id = $search->id;
}
$id = $tracker->id;

$redirect = CRM_Utils_System::externUrl('extern/url', "u=$id");
$urlCache[$mailing_id . $url] = $redirect;
Expand Down

0 comments on commit fffe7b8

Please sign in to comment.