This commit refactors the code that handles exporting e-mails opens and clicks when generating the personal data file to use Doctrine instead of Paris. I opted to do this in this task as opens and clicks code share some functionality, and I didn't want to add more code that relies on Paris, as we are eventually going to remove it. [MAILPOET-3738]
38 lines
1.0 KiB
PHP
38 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace MailPoet\Models;
|
|
|
|
use DateTimeInterface;
|
|
|
|
/**
|
|
* @property int $newsletterId
|
|
* @property int $subscriberId
|
|
* @property int $queueId
|
|
* @property int $linkId
|
|
* @property int $count
|
|
*/
|
|
class StatisticsClicks extends Model {
|
|
public static $_table = MP_STATISTICS_CLICKS_TABLE; // phpcs:ignore PSR2.Classes.PropertyDeclaration
|
|
|
|
public static function findLatestPerNewsletterBySubscriber(Subscriber $subscriber, DateTimeInterface $from, DateTimeInterface $to) {
|
|
// subquery to find latest click IDs for each newsletter
|
|
$table = self::$_table;
|
|
$latestClickIdsPerNewsletterQuery = "
|
|
SELECT MAX(id)
|
|
FROM $table
|
|
WHERE subscriber_id = :subscriber_id
|
|
AND updated_at > :from
|
|
AND updated_at < :to
|
|
GROUP BY newsletter_id
|
|
";
|
|
|
|
return static::tableAlias('clicks')
|
|
->whereRaw("clicks.id IN ($latestClickIdsPerNewsletterQuery)", [
|
|
'subscriber_id' => $subscriber->id,
|
|
'from' => $from->format('Y-m-d H:i:s'),
|
|
'to' => $to->format('Y-m-d H:i:s'),
|
|
])
|
|
->findMany();
|
|
}
|
|
}
|