Save user agent on open

[MAILPOET-3735]
This commit is contained in:
Pavel Dohnal
2021-08-17 12:53:06 +02:00
committed by Veljko V
parent 4f37cde9f9
commit a84471b65c
6 changed files with 84 additions and 12 deletions

View File

@ -0,0 +1,24 @@
<?php
namespace MailPoet\Statistics;
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]);
if ($userAgentEntity) return $userAgentEntity;
$userAgentEntity = new UserAgentEntity($userAgent);
$this->persist($userAgentEntity);
return $userAgentEntity;
}
}