Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
UserChangeWaitEmailsEntityDao | |
0.00% |
0 / 26 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
selectExistsToken | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
insertWaitEmails | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
deleteByUserId | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Dao\Entities; |
6 | |
7 | use PeServer\Core\Database\DaoBase; |
8 | use PeServer\Core\Database\DaoTrait; |
9 | use PeServer\Core\Database\IDatabaseContext; |
10 | |
11 | class UserChangeWaitEmailsEntityDao extends DaoBase |
12 | { |
13 | use DaoTrait; |
14 | |
15 | #region function |
16 | |
17 | public function selectExistsToken(string $userId, string $token, int $limitMinutes): bool |
18 | { |
19 | return 0 < $this->context->selectSingleCount( |
20 | <<<SQL |
21 | |
22 | select |
23 | count(*) |
24 | from |
25 | user_change_wait_emails |
26 | where |
27 | user_change_wait_emails.user_id = :user_id |
28 | and |
29 | user_change_wait_emails.token = :token |
30 | and |
31 | (STRFTIME('%s', CURRENT_TIMESTAMP) - STRFTIME('%s', user_change_wait_emails.timestamp)) < :limit_minutes * 60 |
32 | |
33 | SQL, |
34 | [ |
35 | 'user_id' => $userId, |
36 | 'token' => $token, |
37 | 'limit_minutes' => $limitMinutes, |
38 | ] |
39 | ); |
40 | } |
41 | |
42 | public function insertWaitEmails(string $userId, string $email, int $markEmail, string $token): void |
43 | { |
44 | $this->context->insertSingle( |
45 | <<<SQL |
46 | |
47 | insert into |
48 | user_change_wait_emails |
49 | ( |
50 | user_id, |
51 | token, |
52 | timestamp, |
53 | email, |
54 | mark_email |
55 | ) |
56 | values |
57 | ( |
58 | :user_id, |
59 | :token, |
60 | CURRENT_TIMESTAMP, |
61 | :email, |
62 | :mark_email |
63 | ) |
64 | |
65 | SQL, |
66 | [ |
67 | 'user_id' => $userId, |
68 | 'token' => $token, |
69 | 'email' => $email, |
70 | 'mark_email' => $markEmail, |
71 | ] |
72 | ); |
73 | } |
74 | |
75 | public function deleteByUserId(string $userId): bool |
76 | { |
77 | return $this->context->deleteByKeyOrNothing( |
78 | <<<SQL |
79 | |
80 | delete |
81 | from |
82 | user_change_wait_emails |
83 | where |
84 | user_change_wait_emails.user_id = :user_id |
85 | |
86 | SQL, |
87 | [ |
88 | 'user_id' => $userId, |
89 | ] |
90 | ); |
91 | } |
92 | |
93 | #endregion |
94 | } |