Save user agent on open
[MAILPOET-3735]
This commit is contained in:
24
lib/Statistics/UserAgentsRepository.php
Normal file
24
lib/Statistics/UserAgentsRepository.php
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user