Mailing - Rename trackable URL entities for consistency and add APIv4
authorColeman Watts <coleman@civicrm.org>
Thu, 6 Apr 2023 18:52:08 +0000 (14:52 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 6 Apr 2023 19:09:02 +0000 (15:09 -0400)
28 files changed:
CRM/Activity/Form/ActivityView.php
CRM/Core/DAO/AllCoreTables.data.php
CRM/Mailing/BAO/Mailing.php
CRM/Mailing/BAO/MailingTrackableURL.php [new file with mode: 0644]
CRM/Mailing/BAO/TrackableURL.php
CRM/Mailing/DAO/MailingTrackableURL.php [new file with mode: 0644]
CRM/Mailing/DAO/TrackableURL.php
CRM/Mailing/Event/BAO/MailingEventTrackableURLOpen.php [moved from CRM/Mailing/Event/BAO/MailingEventClickThrough.php with 96% similarity]
CRM/Mailing/Event/BAO/TrackableURLOpen.php
CRM/Mailing/Event/DAO/MailingEventTrackableURLOpen.php [moved from CRM/Mailing/Event/DAO/MailingEventClickThrough.php with 86% similarity]
CRM/Mailing/Event/DAO/TrackableURLOpen.php
CRM/Mailing/Page/Url.php
CRM/Mailing/Selector/Event.php
CRM/Report/Form/Mailing/Clicks.php
Civi/Api4/MailingEventTrackableURLOpen.php [new file with mode: 0644]
Civi/Api4/MailingTrackableURL.php [new file with mode: 0644]
api/v3/Mailing.php
api/v3/MailingAB.php
ext/flexmailer/src/ClickTracker/HtmlClickTracker.php
ext/flexmailer/src/ClickTracker/TextClickTracker.php
ext/flexmailer/tests/phpunit/Civi/FlexMailer/ClickTrackerTest.php
extern/url.php
tests/phpunit/CRM/Mailing/BAO/QueryTest.php
tests/phpunit/api/v3/MailingTest.php
xml/schema/Mailing/Event/MailingEventTrackableURLOpen.xml [moved from xml/schema/Mailing/Event/MailingEventClickThrough.xml with 83% similarity]
xml/schema/Mailing/Event/files.xml
xml/schema/Mailing/MailingTrackableURL.xml [moved from xml/schema/Mailing/TrackableURL.xml with 88% similarity]
xml/schema/Mailing/files.xml

index 310840b3669b855fb5a5642058b245b672c0eb84..6ff714c92b8f1a9413d84212774e74b95329f364 100644 (file)
@@ -73,7 +73,7 @@ class CRM_Activity_Form_ActivityView extends CRM_Core_Form {
         $this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, $cid);
       $this->assign('openreport', $full_open_report);
 
-      $click_thru_report = CRM_Mailing_Event_BAO_MailingEventClickThrough::getRows($this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, NULL, $cid);
+      $click_thru_report = CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::getRows($this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, NULL, $cid);
       $this->assign('clickreport', $click_thru_report);
     }
 
index e043d1c0cbdff5e836b7382bf91c8d7a0f9f6178..9251e2b752a2e837e6b99a34090da0aa39d9b859 100644 (file)
@@ -592,9 +592,9 @@ return [
     'class' => 'CRM_Mailing_DAO_MailingGroup',
     'table' => 'civicrm_mailing_group',
   ],
-  'CRM_Mailing_DAO_TrackableURL' => [
-    'name' => 'TrackableURL',
-    'class' => 'CRM_Mailing_DAO_TrackableURL',
+  'CRM_Mailing_DAO_MailingTrackableURL' => [
+    'name' => 'MailingTrackableURL',
+    'class' => 'CRM_Mailing_DAO_MailingTrackableURL',
     'table' => 'civicrm_mailing_trackable_url',
   ],
   'CRM_Mailing_DAO_MailingJob' => [
@@ -642,9 +642,9 @@ return [
     'class' => 'CRM_Mailing_Event_DAO_MailingEventReply',
     'table' => 'civicrm_mailing_event_reply',
   ],
-  'CRM_Mailing_Event_DAO_MailingEventClickThrough' => [
-    'name' => 'MailingEventClickThrough',
-    'class' => 'CRM_Mailing_Event_DAO_MailingEventClickThrough',
+  'CRM_Mailing_Event_DAO_MailingEventTrackableURLOpen' => [
+    'name' => 'MailingEventTrackableURLOpen',
+    'class' => 'CRM_Mailing_Event_DAO_MailingEventTrackableURLOpen',
     'table' => 'civicrm_mailing_event_trackable_url_open',
   ],
   'CRM_Mailing_Event_DAO_MailingEventUnsubscribe' => [
index 2ca7e67f9c0747634b7955a203f93b813d750bde..5967419e093ec3ba627f9b8364d2d47d7f9dd7c5 100644 (file)
@@ -1366,7 +1366,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
       if ($this->url_tracking && !empty($this->id)) {
         // ensure that Google CSS and any .css files are not tracked.
         if (!(strpos($token, 'css?family') || strpos($token, '.css'))) {
-          $data = CRM_Mailing_BAO_TrackableURL::getTrackerURL($token, $this->id, $event_queue_id);
+          $data = CRM_Mailing_BAO_MailingTrackableURL::getTrackerURL($token, $this->id, $event_queue_id);
           if (!empty($html)) {
             $data = htmlentities($data, ENT_NOQUOTES);
           }
@@ -1754,8 +1754,8 @@ ORDER BY   civicrm_email.is_bulkmail DESC
       'unsubscribe' => CRM_Mailing_Event_BAO_MailingEventUnsubscribe::getTableName(),
       'bounce' => CRM_Mailing_Event_BAO_MailingEventBounce::getTableName(),
       'forward' => CRM_Mailing_Event_BAO_MailingEventForward::getTableName(),
-      'url' => CRM_Mailing_BAO_TrackableURL::getTableName(),
-      'urlopen' => CRM_Mailing_Event_BAO_MailingEventClickThrough::getTableName(),
+      'url' => CRM_Mailing_BAO_MailingTrackableURL::getTableName(),
+      'urlopen' => CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::getTableName(),
       'component' => CRM_Mailing_BAO_MailingComponent::getTableName(),
       'spool' => CRM_Mailing_BAO_Spool::getTableName(),
     ];
@@ -2821,7 +2821,7 @@ ORDER BY civicrm_mailing.name";
     //CRM-12814
     if (!empty($mailings)) {
       $openCounts = CRM_Mailing_Event_BAO_MailingEventOpened::getMailingContactCount(array_keys($mailings), $params['contact_id']);
-      $clickCounts = CRM_Mailing_Event_BAO_MailingEventClickThrough::getMailingContactCount(array_keys($mailings), $params['contact_id']);
+      $clickCounts = CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::getMailingContactCount(array_keys($mailings), $params['contact_id']);
     }
 
     // format params and add links
diff --git a/CRM/Mailing/BAO/MailingTrackableURL.php b/CRM/Mailing/BAO/MailingTrackableURL.php
new file mode 100644 (file)
index 0000000..2ebf1fa
--- /dev/null
@@ -0,0 +1,170 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved.                        |
+ |                                                                    |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
+ */
+class CRM_Mailing_BAO_MailingTrackableURL extends CRM_Mailing_DAO_MailingTrackableURL {
+
+  /**
+   * Given a url, mailing id and queue event id, find or construct a
+   * trackable url and redirect url.
+   *
+   * @param string $url
+   *   The target url to track.
+   * @param int $mailing_id
+   *   The id of the mailing.
+   * @param int $queue_id
+   *   The queue event id (contact clicking through).
+   *
+   * @return string
+   *   The redirect/tracking url
+   */
+  public static function getTrackerURL($url, $mailing_id, $queue_id) {
+    if (strpos($url, '{') !== FALSE) {
+      return self::getTrackerURLForUrlWithTokens($url, $mailing_id, $queue_id);
+    }
+    else {
+      return self::getBasicTrackerURL($url, $mailing_id, $queue_id);
+    }
+  }
+
+  private static function getBasicTrackerURL($url, $mailing_id, $queue_id) {
+    static $urlCache = [];
+
+    if (array_key_exists($mailing_id . $url, $urlCache)) {
+      return $urlCache[$mailing_id . $url] . "&qid=$queue_id";
+    }
+
+    // hack for basic CRM-1014 and CRM-1151 and CRM-3492 compliance:
+    // let's not replace possible image URLs, CiviMail URLs or internal anchor URLs
+    if (preg_match('/\.(png|jpg|jpeg|gif|css)[\'"]?$/i', $url)
+      or substr_count($url, 'civicrm/extern/')
+      or substr_count($url, 'civicrm/mailing/')
+      or ($url[0] === '#')
+    ) {
+      // let's not cache these, so they don't get &qid= appended to them
+      return $url;
+    }
+    else {
+
+      $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)) {
+        $tracker->save();
+      }
+      $id = $tracker->id;
+
+      $redirect = CRM_Utils_System::externUrl('extern/url', "u=$id");
+      $urlCache[$mailing_id . $url] = $redirect;
+    }
+
+    // This looks silly - calling the hook twice. This smells like an accident. Restoring old cache-based lookup.
+    // $returnUrl = CRM_Utils_System::externUrl('extern/url', "u=$id&qid=$queue_id");
+    $returnUrl = "{$urlCache[$mailing_id . $url]}&qid={$queue_id}";
+
+    if ($hrefExists) {
+      $returnUrl = "href='{$returnUrl}' rel='nofollow'";
+    }
+
+    return $returnUrl;
+  }
+
+  /**
+   * Create a trackable URL for a URL with tokens.
+   *
+   * @param string $url
+   * @param int $mailing_id
+   * @param int|string $queue_id
+   *
+   * @return string
+   */
+  private static function getTrackerURLForUrlWithTokens($url, $mailing_id, $queue_id) {
+
+    // Parse the URL.
+    // (not using parse_url because it's messy to reassemble)
+    if (!preg_match('/^([^?#]+)([?][^#]*)?(#.*)?$/', $url, $parsed)) {
+      // Failed to parse it, give up and don't track it.
+      return $url;
+    }
+
+    // If we have a token in the URL + path section, we can't tokenise.
+    if (strpos($parsed[1], '{') !== FALSE) {
+      return $url;
+    }
+
+    $trackable_url = $parsed[1];
+
+    // Process the query parameters, if there are any.
+    $tokenised_params = [];
+    $static_params = [];
+    if (!empty($parsed[2])) {
+      $query_key_value_pairs = explode('&', substr($parsed[2], 1));
+
+      // Separate the tokenised from the static parts.
+      foreach ($query_key_value_pairs as $_) {
+        if (strpos($_, '{') === FALSE) {
+          $static_params[] = $_;
+        }
+        else {
+          $tokenised_params[] = $_;
+        }
+      }
+      // Add the static params to the trackable part.
+      if ($static_params) {
+        $trackable_url .= '?' . implode('&', $static_params);
+      }
+    }
+
+    // Get trackable URL.
+    $data = self::getBasicTrackerURL($trackable_url, $mailing_id, $queue_id);
+
+    // Append the tokenised bits and the fragment.
+    if ($tokenised_params) {
+      // We know the URL will already have the '?'
+      $data .= '&' . implode('&', $tokenised_params);
+    }
+    if (!empty($parsed[3])) {
+      $data .= $parsed[3];
+    }
+    return $data;
+  }
+
+  /**
+   * @param $url
+   * @param $mailing_id
+   *
+   * @return int
+   *   Url id of the given url and mail
+   */
+  public static function getTrackerURLId($url, $mailing_id) {
+    $tracker = new CRM_Mailing_BAO_MailingTrackableURL();
+    $tracker->url = $url;
+    $tracker->mailing_id = $mailing_id;
+    if ($tracker->find(TRUE)) {
+      return $tracker->id;
+    }
+
+    return NULL;
+  }
+
+}
index f857f6eb9cdca08269b69c8a4fa0f9a54f552c4a..583ae4269a6d16063c69c9e4c3fdb4263fa2be64 100644 (file)
@@ -1,170 +1,7 @@
 <?php
-/*
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC. All rights reserved.                        |
- |                                                                    |
- | This work is published under the GNU AGPLv3 license with some      |
- | permitted exceptions and without any warranty. For full license    |
- | and copyright information, see https://civicrm.org/licensing       |
- +--------------------------------------------------------------------+
- */
 
 /**
- *
- * @package CRM
- * @copyright CiviCRM LLC https://civicrm.org/licensing
+ * Class was renamed in 5.62
+ * @deprecated
  */
-class CRM_Mailing_BAO_TrackableURL extends CRM_Mailing_DAO_TrackableURL {
-
-  /**
-   * Given a url, mailing id and queue event id, find or construct a
-   * trackable url and redirect url.
-   *
-   * @param string $url
-   *   The target url to track.
-   * @param int $mailing_id
-   *   The id of the mailing.
-   * @param int $queue_id
-   *   The queue event id (contact clicking through).
-   *
-   * @return string
-   *   The redirect/tracking url
-   */
-  public static function getTrackerURL($url, $mailing_id, $queue_id) {
-    if (strpos($url, '{') !== FALSE) {
-      return self::getTrackerURLForUrlWithTokens($url, $mailing_id, $queue_id);
-    }
-    else {
-      return self::getBasicTrackerURL($url, $mailing_id, $queue_id);
-    }
-  }
-
-  private static function getBasicTrackerURL($url, $mailing_id, $queue_id) {
-    static $urlCache = [];
-
-    if (array_key_exists($mailing_id . $url, $urlCache)) {
-      return $urlCache[$mailing_id . $url] . "&qid=$queue_id";
-    }
-
-    // hack for basic CRM-1014 and CRM-1151 and CRM-3492 compliance:
-    // let's not replace possible image URLs, CiviMail URLs or internal anchor URLs
-    if (preg_match('/\.(png|jpg|jpeg|gif|css)[\'"]?$/i', $url)
-      or substr_count($url, 'civicrm/extern/')
-      or substr_count($url, 'civicrm/mailing/')
-      or ($url[0] === '#')
-    ) {
-      // let's not cache these, so they don't get &qid= appended to them
-      return $url;
-    }
-    else {
-
-      $hrefExists = FALSE;
-
-      $tracker = new CRM_Mailing_BAO_TrackableURL();
-      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)) {
-        $tracker->save();
-      }
-      $id = $tracker->id;
-
-      $redirect = CRM_Utils_System::externUrl('extern/url', "u=$id");
-      $urlCache[$mailing_id . $url] = $redirect;
-    }
-
-    // This looks silly - calling the hook twice. This smells like an accident. Restoring old cache-based lookup.
-    // $returnUrl = CRM_Utils_System::externUrl('extern/url', "u=$id&qid=$queue_id");
-    $returnUrl = "{$urlCache[$mailing_id . $url]}&qid={$queue_id}";
-
-    if ($hrefExists) {
-      $returnUrl = "href='{$returnUrl}' rel='nofollow'";
-    }
-
-    return $returnUrl;
-  }
-
-  /**
-   * Create a trackable URL for a URL with tokens.
-   *
-   * @param string $url
-   * @param int $mailing_id
-   * @param int|string $queue_id
-   *
-   * @return string
-   */
-  private static function getTrackerURLForUrlWithTokens($url, $mailing_id, $queue_id) {
-
-    // Parse the URL.
-    // (not using parse_url because it's messy to reassemble)
-    if (!preg_match('/^([^?#]+)([?][^#]*)?(#.*)?$/', $url, $parsed)) {
-      // Failed to parse it, give up and don't track it.
-      return $url;
-    }
-
-    // If we have a token in the URL + path section, we can't tokenise.
-    if (strpos($parsed[1], '{') !== FALSE) {
-      return $url;
-    }
-
-    $trackable_url = $parsed[1];
-
-    // Process the query parameters, if there are any.
-    $tokenised_params = [];
-    $static_params = [];
-    if (!empty($parsed[2])) {
-      $query_key_value_pairs = explode('&', substr($parsed[2], 1));
-
-      // Separate the tokenised from the static parts.
-      foreach ($query_key_value_pairs as $_) {
-        if (strpos($_, '{') === FALSE) {
-          $static_params[] = $_;
-        }
-        else {
-          $tokenised_params[] = $_;
-        }
-      }
-      // Add the static params to the trackable part.
-      if ($static_params) {
-        $trackable_url .= '?' . implode('&', $static_params);
-      }
-    }
-
-    // Get trackable URL.
-    $data = self::getBasicTrackerURL($trackable_url, $mailing_id, $queue_id);
-
-    // Append the tokenised bits and the fragment.
-    if ($tokenised_params) {
-      // We know the URL will already have the '?'
-      $data .= '&' . implode('&', $tokenised_params);
-    }
-    if (!empty($parsed[3])) {
-      $data .= $parsed[3];
-    }
-    return $data;
-  }
-
-  /**
-   * @param $url
-   * @param $mailing_id
-   *
-   * @return int
-   *   Url id of the given url and mail
-   */
-  public static function getTrackerURLId($url, $mailing_id) {
-    $tracker = new CRM_Mailing_BAO_TrackableURL();
-    $tracker->url = $url;
-    $tracker->mailing_id = $mailing_id;
-    if ($tracker->find(TRUE)) {
-      return $tracker->id;
-    }
-
-    return NULL;
-  }
-
-}
+class_alias('CRM_Mailing_BAO_MailingTrackableURL', 'CRM_Mailing_BAO_TrackableURL');
diff --git a/CRM/Mailing/DAO/MailingTrackableURL.php b/CRM/Mailing/DAO/MailingTrackableURL.php
new file mode 100644 (file)
index 0000000..599cda1
--- /dev/null
@@ -0,0 +1,238 @@
+<?php
+
+/**
+ * @package CRM
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
+ *
+ * Generated from xml/schema/CRM/Mailing/MailingTrackableURL.xml
+ * DO NOT EDIT.  Generated by CRM_Core_CodeGen
+ * (GenCodeChecksum:5da2465e098de06d8a90975560c1cd91)
+ */
+
+/**
+ * Database access object for the MailingTrackableURL entity.
+ */
+class CRM_Mailing_DAO_MailingTrackableURL extends CRM_Core_DAO {
+  const EXT = 'civicrm';
+  const TABLE_ADDED = '';
+  const COMPONENT = 'CiviMail';
+
+  /**
+   * Static instance to hold the table name.
+   *
+   * @var string
+   */
+  public static $_tableName = 'civicrm_mailing_trackable_url';
+
+  /**
+   * Should CiviCRM log any modifications to this table in the civicrm_log table.
+   *
+   * @var bool
+   */
+  public static $_log = FALSE;
+
+  /**
+   * @var int|string|null
+   *   (SQL type: int unsigned)
+   *   Note that values will be retrieved from the database as a string.
+   */
+  public $id;
+
+  /**
+   * The URL to be tracked.
+   *
+   * @var string
+   *   (SQL type: text)
+   *   Note that values will be retrieved from the database as a string.
+   */
+  public $url;
+
+  /**
+   * FK to the mailing
+   *
+   * @var int|string
+   *   (SQL type: int unsigned)
+   *   Note that values will be retrieved from the database as a string.
+   */
+  public $mailing_id;
+
+  /**
+   * Class constructor.
+   */
+  public function __construct() {
+    $this->__table = 'civicrm_mailing_trackable_url';
+    parent::__construct();
+  }
+
+  /**
+   * Returns localized title of this entity.
+   *
+   * @param bool $plural
+   *   Whether to return the plural version of the title.
+   */
+  public static function getEntityTitle($plural = FALSE) {
+    return $plural ? ts('Mailing Links') : ts('Mailing Link');
+  }
+
+  /**
+   * Returns foreign keys and entity references.
+   *
+   * @return array
+   *   [CRM_Core_Reference_Interface]
+   */
+  public static function getReferenceColumns() {
+    if (!isset(Civi::$statics[__CLASS__]['links'])) {
+      Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
+      Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'mailing_id', 'civicrm_mailing', 'id');
+      CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
+    }
+    return Civi::$statics[__CLASS__]['links'];
+  }
+
+  /**
+   * Returns all the column names of this table
+   *
+   * @return array
+   */
+  public static function &fields() {
+    if (!isset(Civi::$statics[__CLASS__]['fields'])) {
+      Civi::$statics[__CLASS__]['fields'] = [
+        'id' => [
+          'name' => 'id',
+          'type' => CRM_Utils_Type::T_INT,
+          'title' => ts('Trackable URL ID'),
+          'required' => TRUE,
+          'usage' => [
+            'import' => FALSE,
+            'export' => FALSE,
+            'duplicate_matching' => FALSE,
+            'token' => FALSE,
+          ],
+          'where' => 'civicrm_mailing_trackable_url.id',
+          'table_name' => 'civicrm_mailing_trackable_url',
+          'entity' => 'MailingTrackableURL',
+          'bao' => 'CRM_Mailing_BAO_MailingTrackableURL',
+          'localizable' => 0,
+          'html' => [
+            'type' => 'Number',
+          ],
+          'readonly' => TRUE,
+          'add' => NULL,
+        ],
+        'url' => [
+          'name' => 'url',
+          'type' => CRM_Utils_Type::T_TEXT,
+          'title' => ts('Url'),
+          'description' => ts('The URL to be tracked.'),
+          'required' => TRUE,
+          'usage' => [
+            'import' => FALSE,
+            'export' => FALSE,
+            'duplicate_matching' => FALSE,
+            'token' => FALSE,
+          ],
+          'where' => 'civicrm_mailing_trackable_url.url',
+          'table_name' => 'civicrm_mailing_trackable_url',
+          'entity' => 'MailingTrackableURL',
+          'bao' => 'CRM_Mailing_BAO_MailingTrackableURL',
+          'localizable' => 0,
+          'add' => NULL,
+        ],
+        'mailing_id' => [
+          'name' => 'mailing_id',
+          'type' => CRM_Utils_Type::T_INT,
+          'title' => ts('Mailing ID'),
+          'description' => ts('FK to the mailing'),
+          'required' => TRUE,
+          'usage' => [
+            'import' => FALSE,
+            'export' => FALSE,
+            'duplicate_matching' => FALSE,
+            'token' => FALSE,
+          ],
+          'where' => 'civicrm_mailing_trackable_url.mailing_id',
+          'table_name' => 'civicrm_mailing_trackable_url',
+          'entity' => 'MailingTrackableURL',
+          'bao' => 'CRM_Mailing_BAO_MailingTrackableURL',
+          'localizable' => 0,
+          'FKClassName' => 'CRM_Mailing_DAO_Mailing',
+          'html' => [
+            'type' => 'EntityRef',
+            'label' => ts("Mailing"),
+          ],
+          'add' => NULL,
+        ],
+      ];
+      CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
+    }
+    return Civi::$statics[__CLASS__]['fields'];
+  }
+
+  /**
+   * Return a mapping from field-name to the corresponding key (as used in fields()).
+   *
+   * @return array
+   *   Array(string $name => string $uniqueName).
+   */
+  public static function &fieldKeys() {
+    if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
+      Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
+    }
+    return Civi::$statics[__CLASS__]['fieldKeys'];
+  }
+
+  /**
+   * Returns the names of this table
+   *
+   * @return string
+   */
+  public static function getTableName() {
+    return self::$_tableName;
+  }
+
+  /**
+   * Returns if this table needs to be logged
+   *
+   * @return bool
+   */
+  public function getLog() {
+    return self::$_log;
+  }
+
+  /**
+   * Returns the list of fields that can be imported
+   *
+   * @param bool $prefix
+   *
+   * @return array
+   */
+  public static function &import($prefix = FALSE) {
+    $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'mailing_trackable_url', $prefix, []);
+    return $r;
+  }
+
+  /**
+   * Returns the list of fields that can be exported
+   *
+   * @param bool $prefix
+   *
+   * @return array
+   */
+  public static function &export($prefix = FALSE) {
+    $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'mailing_trackable_url', $prefix, []);
+    return $r;
+  }
+
+  /**
+   * Returns the list of indices
+   *
+   * @param bool $localize
+   *
+   * @return array
+   */
+  public static function indices($localize = TRUE) {
+    $indices = [];
+    return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
+  }
+
+}
index bd67cc8182870480fd0892e6f3920ce79af351aa..442cfb89bfd67c2db7c6430b006e3db826c549a0 100644 (file)
@@ -1,237 +1,7 @@
 <?php
 
 /**
- * @package CRM
- * @copyright CiviCRM LLC https://civicrm.org/licensing
- *
- * Generated from xml/schema/CRM/Mailing/TrackableURL.xml
- * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:f43da49ddd6befd1cebeb8044c43618b)
+ * Class was renamed in 5.62
+ * @deprecated
  */
-
-/**
- * Database access object for the TrackableURL entity.
- */
-class CRM_Mailing_DAO_TrackableURL extends CRM_Core_DAO {
-  const EXT = 'civicrm';
-  const TABLE_ADDED = '';
-  const COMPONENT = 'CiviMail';
-
-  /**
-   * Static instance to hold the table name.
-   *
-   * @var string
-   */
-  public static $_tableName = 'civicrm_mailing_trackable_url';
-
-  /**
-   * Should CiviCRM log any modifications to this table in the civicrm_log table.
-   *
-   * @var bool
-   */
-  public static $_log = FALSE;
-
-  /**
-   * @var int|string|null
-   *   (SQL type: int unsigned)
-   *   Note that values will be retrieved from the database as a string.
-   */
-  public $id;
-
-  /**
-   * The URL to be tracked.
-   *
-   * @var string
-   *   (SQL type: text)
-   *   Note that values will be retrieved from the database as a string.
-   */
-  public $url;
-
-  /**
-   * FK to the mailing
-   *
-   * @var int|string
-   *   (SQL type: int unsigned)
-   *   Note that values will be retrieved from the database as a string.
-   */
-  public $mailing_id;
-
-  /**
-   * Class constructor.
-   */
-  public function __construct() {
-    $this->__table = 'civicrm_mailing_trackable_url';
-    parent::__construct();
-  }
-
-  /**
-   * Returns localized title of this entity.
-   *
-   * @param bool $plural
-   *   Whether to return the plural version of the title.
-   */
-  public static function getEntityTitle($plural = FALSE) {
-    return $plural ? ts('Trackable URLs') : ts('Trackable URL');
-  }
-
-  /**
-   * Returns foreign keys and entity references.
-   *
-   * @return array
-   *   [CRM_Core_Reference_Interface]
-   */
-  public static function getReferenceColumns() {
-    if (!isset(Civi::$statics[__CLASS__]['links'])) {
-      Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
-      Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'mailing_id', 'civicrm_mailing', 'id');
-      CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
-    }
-    return Civi::$statics[__CLASS__]['links'];
-  }
-
-  /**
-   * Returns all the column names of this table
-   *
-   * @return array
-   */
-  public static function &fields() {
-    if (!isset(Civi::$statics[__CLASS__]['fields'])) {
-      Civi::$statics[__CLASS__]['fields'] = [
-        'id' => [
-          'name' => 'id',
-          'type' => CRM_Utils_Type::T_INT,
-          'title' => ts('Trackable URL ID'),
-          'required' => TRUE,
-          'usage' => [
-            'import' => FALSE,
-            'export' => FALSE,
-            'duplicate_matching' => FALSE,
-            'token' => FALSE,
-          ],
-          'where' => 'civicrm_mailing_trackable_url.id',
-          'table_name' => 'civicrm_mailing_trackable_url',
-          'entity' => 'TrackableURL',
-          'bao' => 'CRM_Mailing_BAO_TrackableURL',
-          'localizable' => 0,
-          'html' => [
-            'type' => 'Number',
-          ],
-          'readonly' => TRUE,
-          'add' => NULL,
-        ],
-        'url' => [
-          'name' => 'url',
-          'type' => CRM_Utils_Type::T_TEXT,
-          'title' => ts('Url'),
-          'description' => ts('The URL to be tracked.'),
-          'required' => TRUE,
-          'usage' => [
-            'import' => FALSE,
-            'export' => FALSE,
-            'duplicate_matching' => FALSE,
-            'token' => FALSE,
-          ],
-          'where' => 'civicrm_mailing_trackable_url.url',
-          'table_name' => 'civicrm_mailing_trackable_url',
-          'entity' => 'TrackableURL',
-          'bao' => 'CRM_Mailing_BAO_TrackableURL',
-          'localizable' => 0,
-          'add' => NULL,
-        ],
-        'mailing_id' => [
-          'name' => 'mailing_id',
-          'type' => CRM_Utils_Type::T_INT,
-          'title' => ts('Mailing ID'),
-          'description' => ts('FK to the mailing'),
-          'required' => TRUE,
-          'usage' => [
-            'import' => FALSE,
-            'export' => FALSE,
-            'duplicate_matching' => FALSE,
-            'token' => FALSE,
-          ],
-          'where' => 'civicrm_mailing_trackable_url.mailing_id',
-          'table_name' => 'civicrm_mailing_trackable_url',
-          'entity' => 'TrackableURL',
-          'bao' => 'CRM_Mailing_BAO_TrackableURL',
-          'localizable' => 0,
-          'FKClassName' => 'CRM_Mailing_DAO_Mailing',
-          'html' => [
-            'label' => ts("Mailing"),
-          ],
-          'add' => NULL,
-        ],
-      ];
-      CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
-    }
-    return Civi::$statics[__CLASS__]['fields'];
-  }
-
-  /**
-   * Return a mapping from field-name to the corresponding key (as used in fields()).
-   *
-   * @return array
-   *   Array(string $name => string $uniqueName).
-   */
-  public static function &fieldKeys() {
-    if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
-      Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
-    }
-    return Civi::$statics[__CLASS__]['fieldKeys'];
-  }
-
-  /**
-   * Returns the names of this table
-   *
-   * @return string
-   */
-  public static function getTableName() {
-    return self::$_tableName;
-  }
-
-  /**
-   * Returns if this table needs to be logged
-   *
-   * @return bool
-   */
-  public function getLog() {
-    return self::$_log;
-  }
-
-  /**
-   * Returns the list of fields that can be imported
-   *
-   * @param bool $prefix
-   *
-   * @return array
-   */
-  public static function &import($prefix = FALSE) {
-    $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'mailing_trackable_url', $prefix, []);
-    return $r;
-  }
-
-  /**
-   * Returns the list of fields that can be exported
-   *
-   * @param bool $prefix
-   *
-   * @return array
-   */
-  public static function &export($prefix = FALSE) {
-    $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'mailing_trackable_url', $prefix, []);
-    return $r;
-  }
-
-  /**
-   * Returns the list of indices
-   *
-   * @param bool $localize
-   *
-   * @return array
-   */
-  public static function indices($localize = TRUE) {
-    $indices = [];
-    return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
-  }
-
-}
+class_alias('CRM_Mailing_DAO_MailingTrackableURL', 'CRM_Mailing_DAO_TrackableURL');
similarity index 96%
rename from CRM/Mailing/Event/BAO/MailingEventClickThrough.php
rename to CRM/Mailing/Event/BAO/MailingEventTrackableURLOpen.php
index 744276ee7852f686be4383664956182f81d4e01b..b77a59a88993ff1aca05df67009b2a8ae2be9cbd 100644 (file)
@@ -14,7 +14,7 @@
  * @package CRM
  * @copyright CiviCRM LLC https://civicrm.org/licensing
  */
-class CRM_Mailing_Event_BAO_MailingEventClickThrough extends CRM_Mailing_Event_DAO_MailingEventClickThrough {
+class CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen extends CRM_Mailing_Event_DAO_MailingEventTrackableURLOpen {
 
   /**
    * Track a click-through and return the URL to redirect.
@@ -34,7 +34,7 @@ class CRM_Mailing_Event_BAO_MailingEventClickThrough extends CRM_Mailing_Event_D
     // prevents foreign key violations.
     $job = CRM_Utils_Type::escape(CRM_Mailing_BAO_MailingJob::getTableName(), 'MysqlColumnNameOrAlias');
     $eq = CRM_Utils_Type::escape(CRM_Mailing_Event_BAO_MailingEventQueue::getTableName(), 'MysqlColumnNameOrAlias');
-    $turl = CRM_Utils_Type::escape(CRM_Mailing_BAO_TrackableURL::getTableName(), 'MysqlColumnNameOrAlias');
+    $turl = CRM_Utils_Type::escape(CRM_Mailing_BAO_MailingTrackableURL::getTableName(), 'MysqlColumnNameOrAlias');
 
     if (!$queue_id) {
       $search = CRM_Core_DAO::executeQuery(
@@ -84,7 +84,7 @@ class CRM_Mailing_Event_BAO_MailingEventClickThrough extends CRM_Mailing_Event_D
       return $search->url;
     }
 
-    $open = new CRM_Mailing_Event_BAO_MailingEventClickThrough();
+    $open = new CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen();
     $open->event_queue_id = $queue_id;
     $open->trackable_url_id = $url_id;
     $open->time_stamp = date('YmdHis');
@@ -272,7 +272,7 @@ class CRM_Mailing_Event_BAO_MailingEventClickThrough extends CRM_Mailing_Event_D
     $dao = new CRM_Core_DAO();
 
     $click = self::getTableName();
-    $url = CRM_Mailing_BAO_TrackableURL::getTableName();
+    $url = CRM_Mailing_BAO_MailingTrackableURL::getTableName();
     $queue = CRM_Mailing_Event_BAO_MailingEventQueue::getTableName();
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     $job = CRM_Mailing_BAO_MailingJob::getTableName();
index 49c982971f7204233fb86edbc61fe379fe0fa235..2e8e70e3a100128f2aa3ad0d448c850bf471e7a1 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 /**
- * BAO class was renamed in 5.57
+ * BAO class was renamed in 5.62
+ * @deprecated
  */
-class_alias('CRM_Mailing_Event_BAO_MailingEventClickThrough', 'CRM_Mailing_Event_BAO_TrackableURLOpen');
+class_alias('CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen', 'CRM_Mailing_Event_BAO_TrackableURLOpen');
similarity index 86%
rename from CRM/Mailing/Event/DAO/MailingEventClickThrough.php
rename to CRM/Mailing/Event/DAO/MailingEventTrackableURLOpen.php
index 7bcd641d581e6843fa16d38b5cf2a0d7b1f2a44f..ac216ce11e96c5f2d64d44a1209c2cba4a5ced86 100644 (file)
@@ -4,15 +4,15 @@
  * @package CRM
  * @copyright CiviCRM LLC https://civicrm.org/licensing
  *
- * Generated from xml/schema/CRM/Mailing/Event/MailingEventClickThrough.xml
+ * Generated from xml/schema/CRM/Mailing/Event/MailingEventTrackableURLOpen.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:11c64e5e8108784fe8e844616abc997e)
+ * (GenCodeChecksum:6b5080d5367785fa44add485df62cba5)
  */
 
 /**
- * Database access object for the MailingEventClickThrough entity.
+ * Database access object for the MailingEventTrackableURLOpen entity.
  */
-class CRM_Mailing_Event_DAO_MailingEventClickThrough extends CRM_Core_DAO {
+class CRM_Mailing_Event_DAO_MailingEventTrackableURLOpen extends CRM_Core_DAO {
   const EXT = 'civicrm';
   const TABLE_ADDED = '';
   const COMPONENT = 'CiviMail';
@@ -80,7 +80,7 @@ class CRM_Mailing_Event_DAO_MailingEventClickThrough extends CRM_Core_DAO {
    *   Whether to return the plural version of the title.
    */
   public static function getEntityTitle($plural = FALSE) {
-    return $plural ? ts('Mailing Event Click Throughs') : ts('Mailing Event Click Through');
+    return $plural ? ts('Mailing Link Clickthroughs') : ts('Mailing Link Clickthrough');
   }
 
   /**
@@ -120,8 +120,8 @@ class CRM_Mailing_Event_DAO_MailingEventClickThrough extends CRM_Core_DAO {
           ],
           'where' => 'civicrm_mailing_event_trackable_url_open.id',
           'table_name' => 'civicrm_mailing_event_trackable_url_open',
-          'entity' => 'MailingEventClickThrough',
-          'bao' => 'CRM_Mailing_Event_BAO_MailingEventClickThrough',
+          'entity' => 'MailingEventTrackableURLOpen',
+          'bao' => 'CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen',
           'localizable' => 0,
           'html' => [
             'type' => 'Number',
@@ -144,11 +144,12 @@ class CRM_Mailing_Event_DAO_MailingEventClickThrough extends CRM_Core_DAO {
           ],
           'where' => 'civicrm_mailing_event_trackable_url_open.event_queue_id',
           'table_name' => 'civicrm_mailing_event_trackable_url_open',
-          'entity' => 'MailingEventClickThrough',
-          'bao' => 'CRM_Mailing_Event_BAO_MailingEventClickThrough',
+          'entity' => 'MailingEventTrackableURLOpen',
+          'bao' => 'CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen',
           'localizable' => 0,
           'FKClassName' => 'CRM_Mailing_Event_DAO_MailingEventQueue',
           'html' => [
+            'type' => 'EntityRef',
             'label' => ts("Recipient"),
           ],
           'add' => NULL,
@@ -167,12 +168,13 @@ class CRM_Mailing_Event_DAO_MailingEventClickThrough extends CRM_Core_DAO {
           ],
           'where' => 'civicrm_mailing_event_trackable_url_open.trackable_url_id',
           'table_name' => 'civicrm_mailing_event_trackable_url_open',
-          'entity' => 'MailingEventClickThrough',
-          'bao' => 'CRM_Mailing_Event_BAO_MailingEventClickThrough',
+          'entity' => 'MailingEventTrackableURLOpen',
+          'bao' => 'CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen',
           'localizable' => 0,
-          'FKClassName' => 'CRM_Mailing_DAO_TrackableURL',
+          'FKClassName' => 'CRM_Mailing_DAO_MailingTrackableURL',
           'html' => [
-            'label' => ts("Trackable Url"),
+            'type' => 'EntityRef',
+            'label' => ts("Mailing Link"),
           ],
           'add' => NULL,
         ],
@@ -191,9 +193,13 @@ class CRM_Mailing_Event_DAO_MailingEventClickThrough extends CRM_Core_DAO {
           'where' => 'civicrm_mailing_event_trackable_url_open.time_stamp',
           'default' => 'CURRENT_TIMESTAMP',
           'table_name' => 'civicrm_mailing_event_trackable_url_open',
-          'entity' => 'MailingEventClickThrough',
-          'bao' => 'CRM_Mailing_Event_BAO_MailingEventClickThrough',
+          'entity' => 'MailingEventTrackableURLOpen',
+          'bao' => 'CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen',
           'localizable' => 0,
+          'html' => [
+            'type' => 'Date',
+            'label' => ts("Opened Date"),
+          ],
           'add' => NULL,
         ],
       ];
index 0ae51d882e6961ebeb96885481ca51ee09365c2e..4dc33c7be911d975a8c346e7e541473f9bd388f8 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * DAO class was renamed in 5.57
+ * DAO class was renamed in 5.62
  * @deprecated
  */
-class_alias('CRM_Mailing_Event_DAO_MailingEventClickThrough', 'CRM_Mailing_Event_DAO_TrackableURLOpen');
+class_alias('CRM_Mailing_Event_DAO_MailingEventTrackableURLOpen', 'CRM_Mailing_Event_DAO_TrackableURLOpen');
index 5324018ad55fbb0ecf9cbf644f329c2847007c05..a65ee0d9ec4407e98b541ce56b885bfb15e2b277 100644 (file)
@@ -32,7 +32,7 @@ class CRM_Mailing_Page_Url extends CRM_Core_Page {
   public function run() {
     $queue_id = CRM_Utils_Request::retrieveValue('qid', 'Integer');
     $url_id = CRM_Utils_Request::retrieveValue('u', 'Integer', NULL, TRUE);
-    $url = trim(CRM_Mailing_Event_BAO_MailingEventClickThrough::track($queue_id, $url_id));
+    $url = trim(CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::track($queue_id, $url_id));
     $query_string = $this->extractPassthroughParameters();
 
     if (strlen($query_string) > 0) {
index 0ef9775140ac5d0338f493d321832579ec1a8c19..355ba92d7b5ff8e9d2f18e49a487ae65bc391b37 100644 (file)
@@ -217,7 +217,7 @@ class CRM_Mailing_Selector_Event extends CRM_Core_Selector_Base implements CRM_C
           break;
 
         case 'click':
-          $dateSort = CRM_Mailing_Event_BAO_MailingEventClickThrough::getTableName() . '.time_stamp';
+          $dateSort = CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::getTableName() . '.time_stamp';
           $this->_columnHeaders = array_merge($this->_columnHeaders, [
             [
               'name' => ts('URL'),
@@ -315,7 +315,7 @@ class CRM_Mailing_Selector_Event extends CRM_Core_Selector_Base implements CRM_C
         return $result;
 
       case 'click':
-        $event = new CRM_Mailing_Event_BAO_MailingEventClickThrough();
+        $event = new CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen();
         $result = $event->getTotalCount($this->_mailing_id,
           $this->_job_id,
           $this->_is_distinct,
@@ -403,7 +403,7 @@ class CRM_Mailing_Selector_Event extends CRM_Core_Selector_Base implements CRM_C
         return $rows;
 
       case 'click':
-        $rows = CRM_Mailing_Event_BAO_MailingEventClickThrough::getRows(
+        $rows = CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::getRows(
           $this->_mailing_id, $this->_job_id,
           $this->_is_distinct, $this->_url_id,
           $offset, $rowCount, $sort
index c7aebb173f282b24333e0c258b21c7726e26e8d0..1be8d2ad3f19657b8909cc0b3d30ea187e800877 100644 (file)
@@ -148,7 +148,7 @@ class CRM_Report_Form_Mailing_Clicks extends CRM_Report_Form {
     ];
 
     $this->_columns['civicrm_mailing_trackable_url'] = [
-      'dao' => 'CRM_Mailing_DAO_TrackableURL',
+      'dao' => 'CRM_Mailing_DAO_MailingTrackableURL',
       'fields' => [
         'url' => [
           'title' => ts('Click through URL'),
@@ -171,7 +171,7 @@ class CRM_Report_Form_Mailing_Clicks extends CRM_Report_Form {
     ];
 
     $this->_columns['civicrm_mailing_event_trackable_url_open'] = [
-      'dao' => 'CRM_Mailing_Event_DAO_MailingEventClickThrough',
+      'dao' => 'CRM_Mailing_Event_DAO_MailingEventTrackableURLOpen',
       'fields' => [
         'time_stamp' => [
           'title' => ts('Click Date'),
diff --git a/Civi/Api4/MailingEventTrackableURLOpen.php b/Civi/Api4/MailingEventTrackableURLOpen.php
new file mode 100644 (file)
index 0000000..126caa7
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved.                        |
+ |                                                                    |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
+ +--------------------------------------------------------------------+
+ */
+namespace Civi\Api4;
+
+/**
+ * Tracks clickthrough events when users open links in mailings.
+ *
+ * @see \Civi\Api4\MailingTrackableURL
+ * @since 5.62
+ * @package Civi\Api4
+ */
+class MailingEventTrackableURLOpen extends Generic\DAOEntity {
+  use \Civi\Api4\Generic\Traits\ReadOnlyEntity;
+
+}
diff --git a/Civi/Api4/MailingTrackableURL.php b/Civi/Api4/MailingTrackableURL.php
new file mode 100644 (file)
index 0000000..6f7e5d2
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved.                        |
+ |                                                                    |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
+ +--------------------------------------------------------------------+
+ */
+namespace Civi\Api4;
+
+/**
+ * Links in mailings which can be tracked when users click on them.
+ *
+ * @see \Civi\Api4\MailingEventTrackableURLOpen
+ * @since 5.62
+ * @package Civi\Api4
+ */
+class MailingTrackableURL extends Generic\DAOEntity {
+
+}
index 3a04791f6c80a9ee05d8a47f47efe251f28c539a..73f4172aee826796733da0aecdb360a02c629d0f 100644 (file)
@@ -471,7 +471,7 @@ function _civicrm_api3_mailing_event_forward_spec(&$params) {
  */
 function civicrm_api3_mailing_event_click($params) {
   civicrm_api3_verify_mandatory($params,
-    'CRM_Mailing_Event_DAO_MailingEventClickThrough',
+    'CRM_Mailing_Event_DAO_MailingEventTrackableURLOpen',
     ['event_queue_id', 'url_id'],
     FALSE
   );
@@ -479,7 +479,7 @@ function civicrm_api3_mailing_event_click($params) {
   $url_id = $params['url_id'];
   $queue = $params['event_queue_id'];
 
-  $url = CRM_Mailing_Event_BAO_MailingEventClickThrough::track($queue, $url_id);
+  $url = CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::track($queue, $url_id);
 
   $values             = [];
   $values['url']      = $url;
@@ -756,7 +756,7 @@ function civicrm_api3_mailing_stats($params) {
 
       case 'Unique Clicks':
         $stats[$params['mailing_id']] += [
-          $detail => CRM_Mailing_Event_BAO_MailingEventClickThrough::getTotalCount($params['mailing_id'], $params['job_id'], (bool) $params['is_distinct'], NULL, $params['date']),
+          $detail => CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::getTotalCount($params['mailing_id'], $params['job_id'], (bool) $params['is_distinct'], NULL, $params['date']),
         ];
         break;
 
index f238b3c75a24a649398ad2297249cce5210ea2c6..160e9b462551f6786541958f451daa456f921f3b 100644 (file)
@@ -289,7 +289,7 @@ function civicrm_api3_mailing_a_b_graph_stats($params) {
         break;
 
       case 'total unique clicks':
-        $result = CRM_Mailing_Event_BAO_MailingEventClickThrough::getRows($mailingAB['mailing_id_a'], NULL, TRUE, 0, 1, "civicrm_mailing_event_trackable_url_open.time_stamp ASC");
+        $result = CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::getRows($mailingAB['mailing_id_a'], NULL, TRUE, 0, 1, "civicrm_mailing_event_trackable_url_open.time_stamp ASC");
         $startDate = CRM_Utils_Date::processDate($result[0]['date']);
         $targetDate = CRM_Utils_Date::processDate($params['target_date']);
         $dateDuration = round(abs(strtotime($targetDate) - strtotime($startDate)) / $params['split_count']);
@@ -297,7 +297,7 @@ function civicrm_api3_mailing_a_b_graph_stats($params) {
         $toDate = date('YmdHis', $toDate);
         $graphStats[$name] = [
           $params['split_count_select'] => [
-            'count' => CRM_Mailing_Event_BAO_MailingEventClickThrough::getTotalCount($params['mailing_id'], NULL, FALSE, NULL, $toDate),
+            'count' => CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::getTotalCount($params['mailing_id'], NULL, FALSE, NULL, $toDate),
             'time' => CRM_Utils_Date::customFormat($toDate),
           ],
         ];
@@ -308,8 +308,8 @@ function civicrm_api3_mailing_a_b_graph_stats($params) {
           throw new CRM_Core_Exception("Provide url to get stats result for total clicks on a particular link");
         }
         // FIXME: doesn't make sense to get url_id mailing_id_(a|b) while getting start date in mailing_id_a
-        $url_id = CRM_Mailing_BAO_TrackableURL::getTrackerURLId($mailingAB[$column], $params['target_url']);
-        $result = CRM_Mailing_Event_BAO_MailingEventClickThrough::getRows($mailingAB['mailing_id_a'], NULL, FALSE, $url_id, 0, 1, "civicrm_mailing_event_trackable_url_open.time_stamp ASC");
+        $url_id = CRM_Mailing_BAO_MailingTrackableURL::getTrackerURLId($mailingAB[$column], $params['target_url']);
+        $result = CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::getRows($mailingAB['mailing_id_a'], NULL, FALSE, $url_id, 0, 1, "civicrm_mailing_event_trackable_url_open.time_stamp ASC");
         $startDate = CRM_Utils_Date::processDate($result[0]['date']);
         $targetDate = CRM_Utils_Date::processDate($params['target_date']);
         $dateDuration = round(abs(strtotime($targetDate) - strtotime($startDate)) / $params['split_count']);
@@ -317,7 +317,7 @@ function civicrm_api3_mailing_a_b_graph_stats($params) {
         $toDate = CRM_Utils_Date::processDate($toDate);
         $graphStats[$name] = [
           $params['split_count_select'] => [
-            'count' => CRM_Mailing_Event_BAO_MailingEventClickThrough::getTotalCount($params['mailing_id'], NULL, FALSE, $url_id, $toDate),
+            'count' => CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::getTotalCount($params['mailing_id'], NULL, FALSE, $url_id, $toDate),
             'time' => CRM_Utils_Date::customFormat($toDate),
           ],
         ];
index 9dd3759b37b2cde401410d541d65bd00115f6861..822ccbd19f76ff49f367a1a12e2c8243cb99a139 100644 (file)
@@ -15,7 +15,7 @@ class HtmlClickTracker implements ClickTrackerInterface {
   public function filterContent($msg, $mailing_id, $queue_id) {
     return self::replaceHrefUrls($msg,
       function ($url) use ($mailing_id, $queue_id) {
-        $data = \CRM_Mailing_BAO_TrackableURL::getTrackerURL(
+        $data = \CRM_Mailing_BAO_MailingTrackableURL::getTrackerURL(
           html_entity_decode($url), $mailing_id, $queue_id);
         $data = htmlentities($data, ENT_NOQUOTES);
         return $data;
index 1fdea53e8b5a0f0edfa7a14822c2eb3ff4f4d9e3..e3c12f3d591c405909401d719e43e85c4a2fa6cf 100644 (file)
@@ -15,7 +15,7 @@ class TextClickTracker implements ClickTrackerInterface {
   public function filterContent($msg, $mailing_id, $queue_id) {
     return self::replaceTextUrls($msg,
       function ($url) use ($mailing_id, $queue_id) {
-        return \CRM_Mailing_BAO_TrackableURL::getTrackerURL($url, $mailing_id,
+        return \CRM_Mailing_BAO_MailingTrackableURL::getTrackerURL($url, $mailing_id,
           $queue_id);
       }
     );
index 5ba9c960e8810a77ffe467ea4f941c2170998db0..4bf926f3bb35c5c3903d2f9849de14548366ecde 100644 (file)
@@ -29,15 +29,15 @@ class ClickTrackerTest extends \PHPUnit\Framework\TestCase implements HeadlessIn
     // Mock the getTrackerURL call; we don't need to test creating a row in a table.
     // If you want this to work without runkit, then either (a) make the dummy rows or (b) switch this to a hook/event that is runtime-configurable.
     require_once 'CRM/Mailing/BAO/TrackableURL.php';
-    \runkit7_method_rename('\CRM_Mailing_BAO_TrackableURL', 'getBasicTrackerURL', 'orig_getBasicTrackerURL');
-    \runkit7_method_add('\CRM_Mailing_BAO_TrackableURL', 'getBasicTrackerURL', '$a, $b, $c', 'return \'http://example.com/extern?u=1&qid=1\';', RUNKIT7_ACC_STATIC | RUNKIT7_ACC_PRIVATE);
+    \runkit7_method_rename('\CRM_Mailing_BAO_MailingTrackableURL', 'getBasicTrackerURL', 'orig_getBasicTrackerURL');
+    \runkit7_method_add('\CRM_Mailing_BAO_MailingTrackableURL', 'getBasicTrackerURL', '$a, $b, $c', 'return \'http://example.com/extern?u=1&qid=1\';', RUNKIT7_ACC_STATIC | RUNKIT7_ACC_PRIVATE);
     parent::setUp();
   }
 
   public function tearDown(): void {
     // Reset the class.
-    \runkit7_method_remove('\CRM_Mailing_BAO_TrackableURL', 'getBasicTrackerURL');
-    \runkit7_method_rename('\CRM_Mailing_BAO_TrackableURL', 'orig_getBasicTrackerURL', 'getBasicTrackerURL');
+    \runkit7_method_remove('\CRM_Mailing_BAO_MailingTrackableURL', 'getBasicTrackerURL');
+    \runkit7_method_rename('\CRM_Mailing_BAO_MailingTrackableURL', 'orig_getBasicTrackerURL', 'getBasicTrackerURL');
     parent::tearDown();
   }
 
index e9955097cb5e83abc8eeabab14b3b975b4af36df..27e1c299b70bbece8ee56765810c15b4f03565d7 100644 (file)
@@ -18,7 +18,7 @@ if (!$url_id) {
 }
 
 require_once 'CRM/Mailing/Event/BAO/TrackableURLOpen.php';
-$url = CRM_Mailing_Event_BAO_MailingEventClickThrough::track($queue_id, $url_id);
+$url = CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::track($queue_id, $url_id);
 
 // CRM-7103
 // Looking for additional query variables and append them when redirecting.
index 4cca21fea72b9daa230bdf3567c54b45028bcf2b..125f4de936e5f0eb5169e6457884fd19f2b00b13 100644 (file)
@@ -85,9 +85,9 @@ class CRM_Mailing_BAO_QueryTest extends CiviUnitTestCase {
     // ensure that total unique clicked mail count is same while
     //   fetching rows and row count for mailing_id = 14 and
     //   trackable_url_id 12
-    $totalDistinctTrackableUrlCount = CRM_Mailing_Event_BAO_MailingEventClickThrough::getTotalCount(14, NULL, TRUE, 13);
-    $totalTrackableUrlCount = CRM_Mailing_Event_BAO_MailingEventClickThrough::getTotalCount(14, NULL, FALSE, 13);
-    $totalTrackableUrlMail = CRM_Mailing_Event_BAO_MailingEventClickThrough::getRows(14, NULL, TRUE, 13);
+    $totalDistinctTrackableUrlCount = CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::getTotalCount(14, NULL, TRUE, 13);
+    $totalTrackableUrlCount = CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::getTotalCount(14, NULL, FALSE, 13);
+    $totalTrackableUrlMail = CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::getRows(14, NULL, TRUE, 13);
 
     $this->assertEquals(3, $totalDistinctTrackableUrlCount, "Accurately display distinct count of unique trackable URLs");
     $this->assertEquals(4, $totalTrackableUrlCount, "Accurately display count of unique trackable URLs");
index b39fd4274612638309a4fba79e7f160206ce7cdc..effacdf1c622e33c19441ec43e17a2cc6ad0405e 100644 (file)
@@ -1020,13 +1020,13 @@ SELECT event_queue_id, time_stamp FROM {$temporaryTableName}";
     $dao = CRM_Core_DAO::executeQuery($sql);
     $this->assertTrue($dao->fetch());
 
-    $url = CRM_Mailing_Event_BAO_MailingEventClickThrough::track($dao->queue_id, $dao->url_id);
+    $url = CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::track($dao->queue_id, $dao->url_id);
     $this->assertStringContainsString('https://civicrm.org', $url);
 
     // Now delete the event queue hashes and see if the tracking still works.
     CRM_Core_DAO::executeQuery('DELETE FROM civicrm_mailing_event_queue');
 
-    $url = CRM_Mailing_Event_BAO_MailingEventClickThrough::track($dao->queue_id, $dao->url_id);
+    $url = CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::track($dao->queue_id, $dao->url_id);
     $this->assertStringContainsString('https://civicrm.org', $url);
 
     // Ensure that Google CSS link is not tracked.
@@ -1056,13 +1056,13 @@ SELECT event_queue_id, time_stamp FROM {$temporaryTableName}";
     $dao = CRM_Core_DAO::executeQuery($sql);
     $this->assertTrue($dao->fetch());
 
-    $url = CRM_Mailing_Event_BAO_MailingEventClickThrough::track($dao->queue_id, $dao->url_id);
+    $url = CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::track($dao->queue_id, $dao->url_id);
     $this->assertStringContainsString($unicodeURL, $url);
 
     // Now delete the event queue hashes and see if the tracking still works.
     CRM_Core_DAO::executeQuery('DELETE FROM civicrm_mailing_event_queue');
 
-    $url = CRM_Mailing_Event_BAO_MailingEventClickThrough::track($dao->queue_id, $dao->url_id);
+    $url = CRM_Mailing_Event_BAO_MailingEventTrackableURLOpen::track($dao->queue_id, $dao->url_id);
     $this->assertStringContainsString($unicodeURL, $url);
   }
 
similarity index 83%
rename from xml/schema/Mailing/Event/MailingEventClickThrough.xml
rename to xml/schema/Mailing/Event/MailingEventTrackableURLOpen.xml
index 448c4da1b0670423f7800771ea2149b8c61e59c2..bc97ee81d5ea3d9bdcd913831d5ed17e8cea6435 100644 (file)
@@ -2,8 +2,10 @@
 
 <table>
   <base>CRM/Mailing/Event</base>
-  <class>MailingEventClickThrough</class>
+  <class>MailingEventTrackableURLOpen</class>
   <name>civicrm_mailing_event_trackable_url_open</name>
+  <title>Mailing Link Clickthrough</title>
+  <titlePlural>Mailing Link Clickthroughs</titlePlural>
   <comment>Tracks when a TrackableURL is clicked by a recipient.</comment>
   <archive>true</archive>
   <component>CiviMail</component>
@@ -29,6 +31,7 @@
     <comment>FK to EventQueue</comment>
     <html>
       <label>Recipient</label>
+      <type>EntityRef</type>
     </html>
   </field>
   <foreignKey>
@@ -44,7 +47,8 @@
     <required>true</required>
     <comment>FK to TrackableURL</comment>
     <html>
-      <label>Trackable Url</label>
+      <label>Mailing Link</label>
+      <type>EntityRef</type>
     </html>
   </field>
   <foreignKey>
     <type>timestamp</type>
     <default>CURRENT_TIMESTAMP</default>
     <required>true</required>
+    <html>
+      <label>Opened Date</label>
+      <type>Date</type>
+    </html>
     <comment>When this trackable URL open occurred.</comment>
   </field>
 </table>
index eac25940e03cb59cd486b4cf0fa9d3fe465c3ce3..0a359a9080ef01fd1113161c8960781518c82d38 100644 (file)
@@ -10,7 +10,7 @@
 <xi:include href="MailingEventReply.xml"            parse="xml" />
 <xi:include href="MailingEventSubscribe.xml"        parse="xml" />
 <xi:include href="MailingEventConfirm.xml"          parse="xml" />
-<xi:include href="MailingEventClickThrough.xml" parse="xml" />
+<xi:include href="MailingEventTrackableURLOpen.xml" parse="xml" />
 <xi:include href="MailingEventUnsubscribe.xml"      parse="xml" />
 
 </tables>
similarity index 88%
rename from xml/schema/Mailing/TrackableURL.xml
rename to xml/schema/Mailing/MailingTrackableURL.xml
index a22a6bc1c1b870fa27941009b7e589a1f61b90ca..337e8adbbf8ce037ce68768f9155d0239d5f5d8d 100644 (file)
@@ -2,8 +2,10 @@
 
 <table>
   <base>CRM/Mailing</base>
-  <class>TrackableURL</class>
+  <class>MailingTrackableURL</class>
   <name>civicrm_mailing_trackable_url</name>
+  <title>Mailing Link</title>
+  <titlePlural>Mailing Links</titlePlural>
   <comment>Stores URLs for which we should track click-throughs from mailings</comment>
   <archive>true</archive>
   <component>CiviMail</component>
@@ -34,6 +36,7 @@
     <required>true</required>
     <html>
       <label>Mailing</label>
+      <type>EntityRef</type>
     </html>
     <comment>FK to the mailing</comment>
   </field>
index 00c885a810626ecc0036e07f7f7e1d9174f756d3..73217f3a75805a1ffb171447df69fd2f9b5ad0ff 100644 (file)
@@ -6,7 +6,7 @@
 <xi:include href="Mailing.xml"       parse="xml" />
 <xi:include href="MailingAB.xml"     parse="xml" />
 <xi:include href="MailingGroup.xml"  parse="xml" />
-<xi:include href="TrackableURL.xml"  parse="xml" />
+<xi:include href="MailingTrackableURL.xml"  parse="xml" />
 <xi:include href="MailingJob.xml"    parse="xml" />
 <xi:include href="MailingRecipients.xml"    parse="xml" />
 <xi:include href="BounceType.xml"    parse="xml" />