*/ class IpAddressRepository extends CommonRepository { /** * Count how many unique IP addresses is there. */ public function countIpAddresses(): int { $q = $this->createQueryBuilder('i'); $q->select('COUNT(DISTINCT i.id) as unique'); $results = $q->getQuery()->getSingleResult(); if (!isset($results['unique'])) { return 0; } return (int) $results['unique']; } /** * Get IP addresses that are not being used in any other table. * * @return array> * * @throws DBALException */ public function getUnusedIpAddressesIds(int $limit): array { $prefix = MAUTIC_TABLE_PREFIX; $sql = << $limit]; $types = ['limit' => \PDO::PARAM_INT]; return $this->_em->getConnection()->executeQuery($sql, $params, $types)->fetchFirstColumn(); } /** * @param array> $ids * * @throws DBALException */ public function deleteUnusedIpAddresses(array $ids): int { $prefix = MAUTIC_TABLE_PREFIX; $ids = implode(',', $ids); $deleteSql = <<_em->getConnection()->executeStatement($deleteSql); } /** * @throws DBALException */ public function anonymizeAllIpAddress(): int { $table_name = $this->getTableName(); $sql = "UPDATE {$table_name} SET ip_address = '*.*.*.*', ip_details = 'N;' WHERE ip_address != '*.*.*.*'"; $conn = $this->getEntityManager()->getConnection(); return $conn->executeQuery($sql)->rowCount(); } }