Use Doctrine for the opens and clicks exporters
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]
This commit is contained in:
@@ -2,29 +2,29 @@
|
||||
|
||||
namespace MailPoet\Subscribers\ImportExport\PersonalDataExporters;
|
||||
|
||||
use MailPoet\Models\StatisticsClicks;
|
||||
use MailPoet\Statistics\StatisticsClicksRepository;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class NewsletterClicksExporter extends NewsletterStatsBaseExporter {
|
||||
protected $statsClass = StatisticsClicks::class;
|
||||
protected $statsClassName = StatisticsClicksRepository::class;
|
||||
|
||||
protected function getEmailStats(array $row) {
|
||||
$newsletterData = [];
|
||||
$newsletterData[] = [
|
||||
'name' => WPFunctions::get()->__('Email subject', 'mailpoet'),
|
||||
'value' => $row['newsletter_rendered_subject'],
|
||||
'value' => $row['newsletterRenderedSubject'],
|
||||
];
|
||||
$newsletterData[] = [
|
||||
'name' => WPFunctions::get()->__('Timestamp of the click event', 'mailpoet'),
|
||||
'value' => $row['created_at'],
|
||||
'value' => $row['createdAt']->format("Y-m-d H:i:s"),
|
||||
];
|
||||
$newsletterData[] = [
|
||||
'name' => WPFunctions::get()->__('URL', 'mailpoet'),
|
||||
'value' => $row['url'],
|
||||
];
|
||||
|
||||
if (!is_null($row['user_agent'])) {
|
||||
$userAgent = $row['user_agent'];
|
||||
if (!is_null($row['userAgent'])) {
|
||||
$userAgent = $row['userAgent'];
|
||||
} else {
|
||||
$userAgent = WPFunctions::get()->__('Unknown', 'mailpoet');
|
||||
}
|
||||
|
@@ -2,25 +2,25 @@
|
||||
|
||||
namespace MailPoet\Subscribers\ImportExport\PersonalDataExporters;
|
||||
|
||||
use MailPoet\Models\StatisticsOpens;
|
||||
use MailPoet\Statistics\StatisticsOpensRepository;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class NewsletterOpensExporter extends NewsletterStatsBaseExporter {
|
||||
protected $statsClass = StatisticsOpens::class;
|
||||
protected $statsClassName = StatisticsOpensRepository::class;
|
||||
|
||||
protected function getEmailStats(array $row): array {
|
||||
$newsletterData = [];
|
||||
$newsletterData[] = [
|
||||
'name' => WPFunctions::get()->__('Email subject', 'mailpoet'),
|
||||
'value' => $row['newsletter_rendered_subject'],
|
||||
'value' => $row['newsletterRenderedSubject'],
|
||||
];
|
||||
$newsletterData[] = [
|
||||
'name' => WPFunctions::get()->__('Timestamp of the open event', 'mailpoet'),
|
||||
'value' => $row['created_at'],
|
||||
'value' => $row['createdAt']->format("Y-m-d H:i:s"),
|
||||
];
|
||||
|
||||
if (!is_null($row['user_agent'])) {
|
||||
$userAgent = $row['user_agent'];
|
||||
if (!is_null($row['userAgent'])) {
|
||||
$userAgent = $row['userAgent'];
|
||||
} else {
|
||||
$userAgent = WPFunctions::get()->__('Unknown', 'mailpoet');
|
||||
}
|
||||
|
@@ -2,33 +2,45 @@
|
||||
|
||||
namespace MailPoet\Subscribers\ImportExport\PersonalDataExporters;
|
||||
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Entities\SubscriberEntity;
|
||||
use MailPoet\Subscribers\SubscribersRepository;
|
||||
|
||||
abstract class NewsletterStatsBaseExporter {
|
||||
|
||||
const LIMIT = 100;
|
||||
|
||||
protected $statsClass;
|
||||
protected $statsClassName;
|
||||
|
||||
protected $subscriberRepository;
|
||||
|
||||
public function __construct(SubscribersRepository $subscribersRepository) {
|
||||
$this->subscriberRepository = $subscribersRepository;
|
||||
}
|
||||
|
||||
public function export($email, $page = 1): array {
|
||||
$data = [];
|
||||
$subscriber = $this->subscriberRepository->findOneBy(['email' => trim($email)]);
|
||||
|
||||
if ($subscriber instanceof SubscriberEntity) {
|
||||
$data = $this->getSubscriberData($subscriber, $page);
|
||||
}
|
||||
|
||||
public function export($email, $page = 1) {
|
||||
$data = $this->getSubscriberData(Subscriber::findOne(trim($email)), $page);
|
||||
return [
|
||||
'data' => $data,
|
||||
'done' => count($data) < self::LIMIT,
|
||||
];
|
||||
}
|
||||
|
||||
private function getSubscriberData($subscriber, $page) {
|
||||
if (!$subscriber) {
|
||||
return [];
|
||||
}
|
||||
|
||||
private function getSubscriberData(SubscriberEntity $subscriber, $page): array {
|
||||
$result = [];
|
||||
|
||||
$statistics = $this->statsClass::getAllForSubscriber($subscriber)
|
||||
->limit(self::LIMIT)
|
||||
->offset(self::LIMIT * ($page - 1))
|
||||
->findArray();
|
||||
$statsClass = ContainerWrapper::getInstance()->get($this->statsClassName);
|
||||
$statistics = $statsClass->getAllForSubscriber($subscriber)
|
||||
->setMaxResults(self::LIMIT)
|
||||
->setFirstResult(self::LIMIT * ($page - 1))
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
||||
foreach ($statistics as $row) {
|
||||
$result[] = $this->getEmailStats($row);
|
||||
|
Reference in New Issue
Block a user