|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Domain\Security\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use App\Infrastructure\Factory\QueryFactory; |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
// Class cannot be readonly as it's mocked (doubled) in tests |
|
8
|
|
|
class EmailLogFinderRepository |
|
9
|
|
|
{ |
|
10
|
24 |
|
public function __construct( |
|
11
|
|
|
private readonly QueryFactory $queryFactory |
|
12
|
|
|
) { |
|
13
|
24 |
|
} |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Retrieves request summary from the given ip address. |
|
17
|
|
|
* |
|
18
|
|
|
* @param string $email |
|
19
|
|
|
* @param int $seconds |
|
20
|
|
|
* Throws PersistenceRecordNotFoundException if entry not found |
|
21
|
|
|
* @param int|null $userId |
|
22
|
|
|
* |
|
23
|
|
|
* @return int |
|
24
|
|
|
*/ |
|
25
|
10 |
|
public function getLoggedEmailCountInTimespan(string $email, int $seconds, ?int $userId): int |
|
26
|
|
|
{ |
|
27
|
10 |
|
$query = $this->queryFactory->selectQuery(); |
|
28
|
10 |
|
$query->select( |
|
29
|
10 |
|
[ |
|
30
|
10 |
|
'email_amount' => $query->func()->count('id'), |
|
31
|
10 |
|
] |
|
32
|
10 |
|
)->from('email_log')->where( |
|
33
|
10 |
|
[ |
|
34
|
|
|
// Return all between now and x number of minutes |
|
35
|
10 |
|
'created_at >' => $query->newExpr('DATE_SUB(NOW(), INTERVAL :sec SECOND)'), |
|
36
|
10 |
|
] |
|
37
|
10 |
|
)->where( // Where to_email is $email or user_id is $userId if it's set |
|
38
|
10 |
|
$userId ? ['OR' => ['to_email' => $email], 'user_id' => $userId] : ['to_email' => $email] |
|
39
|
10 |
|
)->bind(':sec', $seconds, 'integer'); |
|
40
|
|
|
|
|
41
|
|
|
// Only fetch and not fetchAll as result will be one row with the counts |
|
42
|
10 |
|
$result = $query->execute()->fetch('assoc'); |
|
43
|
|
|
|
|
44
|
10 |
|
return (int)$result['email_amount']; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Searches the latest email request concerning a specific email address. |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $email |
|
51
|
|
|
* |
|
52
|
|
|
* @return string|bool datetime of last email request or false |
|
53
|
|
|
*/ |
|
54
|
3 |
|
public function findLatestEmailRequest(string $email): bool|string |
|
55
|
|
|
{ |
|
56
|
3 |
|
$query = $this->queryFactory->selectQuery(); |
|
57
|
3 |
|
$query->select('created_at')->from('email_log')->where( |
|
58
|
3 |
|
[ |
|
59
|
3 |
|
'to_email' => $email, |
|
60
|
3 |
|
] |
|
61
|
3 |
|
)->orderByDesc('created_at')->limit(1); |
|
62
|
|
|
|
|
63
|
3 |
|
return $query->execute()->fetch('assoc')['created_at'] ?: false; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Gives sent email amount globally in the last given amount of days. |
|
68
|
|
|
* |
|
69
|
|
|
* @param int $days |
|
70
|
|
|
* |
|
71
|
|
|
* @return int sent email amount |
|
72
|
|
|
*/ |
|
73
|
7 |
|
public function getGlobalSentEmailAmount(int $days): int |
|
74
|
|
|
{ |
|
75
|
7 |
|
$query = $this->queryFactory->selectQuery(); |
|
76
|
7 |
|
$query->select( |
|
77
|
7 |
|
[ |
|
78
|
7 |
|
'sent_email_amount' => $query->func()->count('id'), |
|
79
|
7 |
|
] |
|
80
|
7 |
|
)->from('email_log')->where( |
|
81
|
7 |
|
[ |
|
82
|
7 |
|
'created_at >' => $query->newExpr('DATE_SUB(NOW(), INTERVAL :days DAY)'), |
|
83
|
7 |
|
] |
|
84
|
7 |
|
)->bind(':days', $days, 'integer'); |
|
85
|
|
|
|
|
86
|
7 |
|
return (int)($query->execute()->fetch('assoc')['sent_email_amount'] ?? 0); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths