Created migration which parses existing IP addresses, generating hashes and droping already used IPs

This commit is contained in:
Alejandro Celaya
2018-09-13 23:50:09 +02:00
parent 7808f6d182
commit a01031303f
7 changed files with 169 additions and 24 deletions

View File

@@ -35,6 +35,7 @@ class Visit extends AbstractEntity implements \JsonSerializable
private $remoteAddr;
/**
* @var string
* @ORM\Column(type="string", length=256, name="remote_addr_hash", nullable=true)
*/
private $remoteAddrHash;
/**
@@ -108,8 +109,9 @@ class Visit extends AbstractEntity implements \JsonSerializable
private function obfuscateAddress(?string $address): ?string
{
if ($address === null) {
return null;
// Localhost addresses do not need to be obfuscated
if ($address === null || $address === IpAddress::LOCALHOST) {
return $address;
}
try {
@@ -124,6 +126,12 @@ class Visit extends AbstractEntity implements \JsonSerializable
return $address ? \hash('sha256', $address) : null;
}
public function resetObfuscatedAddr(): self
{
$this->remoteAddr = null;
return $this;
}
public function getUserAgent(): string
{
return $this->userAgent;