1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Extension "sf_event_mgt" for TYPO3 CMS. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the |
9
|
|
|
* LICENSE.txt file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace DERHANSEN\SfEventMgt\Service; |
13
|
|
|
|
14
|
|
|
use DateTime; |
15
|
|
|
use TYPO3\CMS\Core\Database\Connection; |
16
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
17
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* MaintenanceService |
21
|
|
|
*/ |
22
|
|
|
class MaintenanceService |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Handles expired registration |
26
|
|
|
*/ |
27
|
|
|
public function handleExpiredRegistrations(bool $delete = false): void |
28
|
|
|
{ |
29
|
|
|
$eventCacheService = GeneralUtility::makeInstance(EventCacheService::class); |
30
|
|
|
$registrationUids = $this->getExpiredRegistrations(); |
31
|
|
|
foreach ($registrationUids as $registration) { |
32
|
|
|
$this->updateRegistration($registration['uid'], $delete); |
33
|
|
|
$eventCacheService->flushEventCache($registration['event'], $registration['pid']); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Processes a GDPR cleaup by removing all registrations of expired events. Returns the amount of registrations |
39
|
|
|
* removed. |
40
|
|
|
*/ |
41
|
|
|
public function processGdprCleanup(int $days, bool $softDelete, bool $ignoreEventRestriction): int |
42
|
|
|
{ |
43
|
|
|
if (!$ignoreEventRestriction) { |
44
|
|
|
$registrations = $this->getGdprCleanupRegistrations($days); |
45
|
|
|
} else { |
46
|
|
|
$registrations = $this->getAllRegistrations(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
foreach ($registrations as $registration) { |
50
|
|
|
if (!$softDelete) { |
51
|
|
|
$this->deleteRegistration($registration['uid']); |
52
|
|
|
$this->deleteRegistrationFieldValues($registration['uid']); |
53
|
|
|
} else { |
54
|
|
|
$this->updateRegistration($registration['uid'], true); |
55
|
|
|
$this->flagRegistrationFieldValuesAsDeleted($registration['uid']); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return count($registrations); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Updates the given registration |
64
|
|
|
*/ |
65
|
|
|
protected function updateRegistration(int $registrationUid, bool $delete = false): void |
66
|
|
|
{ |
67
|
|
|
$connection = GeneralUtility::makeInstance(ConnectionPool::class) |
68
|
|
|
->getConnectionForTable('tx_sfeventmgt_domain_model_registration'); |
69
|
|
|
|
70
|
|
|
$field = $delete === true ? 'deleted' : 'hidden'; |
71
|
|
|
$updateFields = []; |
72
|
|
|
$updateFields[$field] = 1; |
73
|
|
|
|
74
|
|
|
$connection->update( |
75
|
|
|
'tx_sfeventmgt_domain_model_registration', |
76
|
|
|
$updateFields, |
77
|
|
|
['uid' => $registrationUid] |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Flags all registration field values for the given registration UID as deleted |
83
|
|
|
*/ |
84
|
|
|
protected function flagRegistrationFieldValuesAsDeleted(int $registrationUid): void |
85
|
|
|
{ |
86
|
|
|
$connection = GeneralUtility::makeInstance(ConnectionPool::class) |
87
|
|
|
->getConnectionForTable('tx_sfeventmgt_domain_model_registration_fieldvalue'); |
88
|
|
|
|
89
|
|
|
$connection->update( |
90
|
|
|
'tx_sfeventmgt_domain_model_registration_fieldvalue', |
91
|
|
|
['deleted' => 1], |
92
|
|
|
['registration' => $registrationUid] |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Deletes the registration with the given uid |
98
|
|
|
*/ |
99
|
|
|
protected function deleteRegistration(int $registrationUid): void |
100
|
|
|
{ |
101
|
|
|
$connection = GeneralUtility::makeInstance(ConnectionPool::class) |
102
|
|
|
->getConnectionForTable('tx_sfeventmgt_domain_model_registration'); |
103
|
|
|
|
104
|
|
|
$connection->delete( |
105
|
|
|
'tx_sfeventmgt_domain_model_registration', |
106
|
|
|
['uid' => $registrationUid] |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Deletes all registration field values for the given registrationUid |
112
|
|
|
*/ |
113
|
|
|
protected function deleteRegistrationFieldValues(int $registrationUid): void |
114
|
|
|
{ |
115
|
|
|
$connection = GeneralUtility::makeInstance(ConnectionPool::class) |
116
|
|
|
->getConnectionForTable('tx_sfeventmgt_domain_model_registration_fieldvalue'); |
117
|
|
|
|
118
|
|
|
$connection->delete( |
119
|
|
|
'tx_sfeventmgt_domain_model_registration_fieldvalue', |
120
|
|
|
['registration' => $registrationUid] |
121
|
|
|
); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Returns an array of registration uids, which are considered as expired |
126
|
|
|
*/ |
127
|
|
|
protected function getExpiredRegistrations(): array |
128
|
|
|
{ |
129
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
130
|
|
|
->getQueryBuilderForTable('tx_sfeventmgt_domain_model_registration'); |
131
|
|
|
|
132
|
|
|
return $queryBuilder |
133
|
|
|
->select('uid', 'pid', 'event') |
134
|
|
|
->from('tx_sfeventmgt_domain_model_registration') |
135
|
|
|
->where( |
136
|
|
|
$queryBuilder->expr()->lte( |
137
|
|
|
'confirmation_until', |
138
|
|
|
$queryBuilder->createNamedParameter(time(), Connection::PARAM_INT) |
139
|
|
|
), |
140
|
|
|
$queryBuilder->expr()->eq( |
141
|
|
|
'confirmed', |
142
|
|
|
$queryBuilder->createNamedParameter(0, Connection::PARAM_INT) |
143
|
|
|
) |
144
|
|
|
) |
145
|
|
|
->executeQuery() |
146
|
|
|
->fetchAllAssociative(); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Returns all registrations, where the related event has expired based on the given amount of days |
151
|
|
|
*/ |
152
|
|
|
protected function getGdprCleanupRegistrations(int $days): array |
153
|
|
|
{ |
154
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
155
|
|
|
->getQueryBuilderForTable('tx_sfeventmgt_domain_model_registration'); |
156
|
|
|
$queryBuilder->getRestrictions()->removeAll(); |
157
|
|
|
$maxEndDate = (new DateTime())->modify('-' . $days . ' days'); |
158
|
|
|
|
159
|
|
|
return $queryBuilder |
160
|
|
|
->select('tx_sfeventmgt_domain_model_registration.uid') |
161
|
|
|
->from('tx_sfeventmgt_domain_model_registration') |
162
|
|
|
->join( |
163
|
|
|
'tx_sfeventmgt_domain_model_registration', |
164
|
|
|
'tx_sfeventmgt_domain_model_event', |
165
|
|
|
'e', |
166
|
|
|
$queryBuilder->expr()->eq( |
167
|
|
|
'e.uid', |
168
|
|
|
$queryBuilder->quoteIdentifier('tx_sfeventmgt_domain_model_registration.event') |
169
|
|
|
) |
170
|
|
|
)->where( |
171
|
|
|
$queryBuilder->expr()->lte( |
172
|
|
|
'e.enddate', |
173
|
|
|
$queryBuilder->createNamedParameter($maxEndDate->getTimestamp(), Connection::PARAM_INT) |
174
|
|
|
), |
175
|
|
|
$queryBuilder->expr()->gt( |
176
|
|
|
'e.enddate', |
177
|
|
|
$queryBuilder->createNamedParameter(0, Connection::PARAM_INT) |
178
|
|
|
) |
179
|
|
|
)->executeQuery() |
180
|
|
|
->fetchAllAssociative(); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Returns all registrations including hidden and deleted |
185
|
|
|
*/ |
186
|
|
|
protected function getAllRegistrations(): array |
187
|
|
|
{ |
188
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
189
|
|
|
->getQueryBuilderForTable('tx_sfeventmgt_domain_model_registration'); |
190
|
|
|
$queryBuilder->getRestrictions()->removeAll(); |
191
|
|
|
|
192
|
|
|
return $queryBuilder |
193
|
|
|
->select('uid') |
194
|
|
|
->from('tx_sfeventmgt_domain_model_registration') |
195
|
|
|
->executeQuery() |
196
|
|
|
->fetchAllAssociative(); |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|