|
1
|
|
|
<?php |
|
2
|
|
|
namespace DERHANSEN\SfEventMgt\Service; |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* This file is part of the Extension "sf_event_mgt" for TYPO3 CMS. |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please read the |
|
8
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
|
12
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* MaintenanceService |
|
16
|
|
|
* |
|
17
|
|
|
* @author Torben Hansen <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
class MaintenanceService |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Handles expired registration |
|
23
|
|
|
* |
|
24
|
|
|
* @param bool $delete |
|
25
|
|
|
* @return void |
|
26
|
|
|
*/ |
|
27
|
|
|
public function handleExpiredRegistrations(bool $delete = false) |
|
28
|
|
|
{ |
|
29
|
|
|
$eventCacheService = GeneralUtility::makeInstance(EventCacheService::class); |
|
30
|
|
|
$registrationUids = $this->getExpiredRegistrations(); |
|
31
|
|
|
foreach ($registrationUids as $registration) { |
|
32
|
|
|
$this->updateRegistration((int)$registration['uid'], $delete); |
|
33
|
|
|
$eventCacheService->flushEventCache((int)$registration['event'], (int)$registration['pid']); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Updates the given registration |
|
39
|
|
|
* |
|
40
|
|
|
* @param int $registrationUid |
|
41
|
|
|
* @param bool $delete |
|
42
|
|
|
* |
|
43
|
|
|
* @return void |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function updateRegistration(int $registrationUid, bool $delete = false) |
|
46
|
|
|
{ |
|
47
|
|
|
$connection = GeneralUtility::makeInstance(ConnectionPool::class) |
|
48
|
|
|
->getConnectionForTable('tx_sfeventmgt_domain_model_registration'); |
|
49
|
|
|
|
|
50
|
|
|
$field = $delete === true ? 'deleted' : 'hidden'; |
|
51
|
|
|
$updateFields = []; |
|
52
|
|
|
$updateFields[$field] = 1; |
|
53
|
|
|
|
|
54
|
|
|
$connection->update( |
|
55
|
|
|
'tx_sfeventmgt_domain_model_registration', |
|
56
|
|
|
$updateFields, |
|
57
|
|
|
['uid' => $registrationUid] |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Returns an array of registration uids, which are considered as expired |
|
63
|
|
|
* |
|
64
|
|
|
* @return array |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function getExpiredRegistrations() |
|
67
|
|
|
{ |
|
68
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
69
|
|
|
->getQueryBuilderForTable('tx_sfeventmgt_domain_model_registration'); |
|
70
|
|
|
|
|
71
|
|
|
$result = $queryBuilder |
|
72
|
|
|
->select('uid') |
|
73
|
|
|
->from('tx_sfeventmgt_domain_model_registration') |
|
74
|
|
|
->where( |
|
75
|
|
|
$queryBuilder->expr()->lte( |
|
76
|
|
|
'confirmation_until', |
|
77
|
|
|
$queryBuilder->createNamedParameter(time(), \PDO::PARAM_INT) |
|
78
|
|
|
), |
|
79
|
|
|
$queryBuilder->expr()->eq( |
|
80
|
|
|
'confirmed', |
|
81
|
|
|
$queryBuilder->createNamedParameter(0, \PDO::PARAM_INT) |
|
82
|
|
|
) |
|
83
|
|
|
) |
|
84
|
|
|
->execute() |
|
85
|
|
|
->fetchAll(); |
|
86
|
|
|
|
|
87
|
|
|
return $result; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|