Completed
Push — development ( 25c3bd...46781f )
by Torben
06:55
created

MaintenanceService::getExpiredRegistrations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
        $registrationUids = $this->getExpiredRegistrations();
30
        foreach ($registrationUids as $registration) {
31
            $this->updateRegistration((int)$registration['uid'], $delete);
32
        }
33
    }
34
35
    /**
36
     * Updates the given registration
37
     *
38
     * @param int $registrationUid
39
     * @param bool $delete
40
     *
41
     * @return void
42
     */
43
    protected function updateRegistration(int $registrationUid, bool $delete = false)
44
    {
45
        $connection = GeneralUtility::makeInstance(ConnectionPool::class)
46
            ->getConnectionForTable('tx_sfeventmgt_domain_model_registration');
47
48
        $field = $delete === true ? 'deleted' : 'hidden';
49
        $updateFields = [];
50
        $updateFields[$field] = 1;
51
52
        $connection->update(
53
            'tx_sfeventmgt_domain_model_registration',
54
            $updateFields,
55
            ['uid' => $registrationUid]
56
        );
57
    }
58
59
    /**
60
     * Returns an array of registration uids, which are considered as expired
61
     *
62
     * @return array
63
     */
64
    protected function getExpiredRegistrations()
65
    {
66
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
67
            ->getQueryBuilderForTable('tx_sfeventmgt_domain_model_registration');
68
69
        $result = $queryBuilder
70
            ->select('uid')
71
            ->from('tx_sfeventmgt_domain_model_registration')
72
            ->where(
73
                $queryBuilder->expr()->lte(
74
                    'confirmation_until',
75
                    $queryBuilder->createNamedParameter(time(), \PDO::PARAM_INT)
76
                ),
77
                $queryBuilder->expr()->eq(
78
                    'confirmed',
79
                    $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
80
                )
81
            )
82
            ->execute()
83
            ->fetchAll();
84
85
        return $result;
86
    }
87
}
88