Commit 995c1630 authored by Romain Thouvenin's avatar Romain Thouvenin
Browse files

API function to consume tracked URLs from Traxy

parent c9c48dde
<?php
use CRM_Traxivi_ExtensionUtil as E;
function _civicrm_api3_traxy_Trackurl_spec(&$spec) {
$spec['message']['api.required'] = 1;
}
/**
* Rabbitizen consumer to record a tracked URL coming from Traxy
*/
function civicrm_api3_traxy_Trackurl($params) {
$job = CRM_Utils_Type::escape(CRM_Mailing_BAO_MailingJob::getTableName(), 'MysqlColumnNameOrAlias');
$eq = CRM_Utils_Type::escape(CRM_Mailing_Event_BAO_Queue::getTableName(), 'MysqlColumnNameOrAlias');
$turl = CRM_Utils_Type::escape(CRM_Mailing_BAO_TrackableURL::getTableName(), 'MysqlColumnNameOrAlias');
$json_msg = json_decode($params['message']);
$queue_id = $json_msg->params->qid;
$url_id = $json_msg->params->u;
$search = CRM_Core_DAO::executeQuery(
"SELECT $turl.url as url
FROM $turl
INNER JOIN $job ON $turl.mailing_id = $job.mailing_id
INNER JOIN $eq ON $job.id = $eq.job_id
WHERE $eq.id = %1 AND $turl.id = %2",
[
1 => [$queue_id, 'Integer'],
2 => [$url_id, 'Integer'],
]
);
if (!$search->fetch()) {
return civicrm_api3_create_error("The url / queue pair ($url_id, $queue_id) does not exist", ['retry_later' => FALSE]);
}
$open = new CRM_Mailing_Event_BAO_TrackableURLOpen();
$open->event_queue_id = $queue_id;
$open->trackable_url_id = $url_id;
$open->time_stamp = CRM_Utils_Date::processDate($json_msg->timestamp);
$open->save();
return civicrm_api3_create_success();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment