<?php declare(strict_types = 1); namespace MailPoet\Statistics; if (!defined('ABSPATH')) exit; use MailPoet\Doctrine\Repository; use MailPoet\Entities\UserAgentEntity; /** * @extends Repository<UserAgentEntity> */ class UserAgentsRepository extends Repository { protected function getEntityClassName() { return UserAgentEntity::class; } public function findOrCreate(string $userAgent): UserAgentEntity { $hash = (string)crc32($userAgent); $userAgentEntity = $this->findOneBy(['hash' => $hash]); return $userAgentEntity ?? $this->create($userAgent); } public function create(string $userAgent): UserAgentEntity { $userAgentEntity = new UserAgentEntity($userAgent); $this->entityManager->getConnection()->executeStatement( 'INSERT INTO ' . $this->getTableName() . ' (user_agent, hash) VALUES (:user_agent, :hash) ON DUPLICATE KEY UPDATE id = id', [ 'user_agent' => $userAgentEntity->getUserAgent(), 'hash' => $userAgentEntity->getHash(), ] ); /** @var UserAgentEntity $userAgentEntity */ $userAgentEntity = $this->findOneBy(['hash' => $userAgentEntity->getHash()]); return $userAgentEntity; } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
Track | Folder | 0755 |
|
|
GATracking.php | File | 3.75 KB | 0644 |
|
StatisticsBouncesRepository.php | File | 390 B | 0644 |
|
StatisticsClicksRepository.php | File | 3.77 KB | 0644 |
|
StatisticsFormsRepository.php | File | 1.16 KB | 0644 |
|
StatisticsNewslettersRepository.php | File | 2.05 KB | 0644 |
|
StatisticsOpensRepository.php | File | 4.23 KB | 0644 |
|
StatisticsUnsubscribesRepository.php | File | 1.37 KB | 0644 |
|
StatisticsWooCommercePurchasesRepository.php | File | 5.27 KB | 0644 |
|
UserAgentsRepository.php | File | 1.16 KB | 0644 |
|
index.php | File | 6 B | 0644 |
|