Passed
Push — main ( 3301a9...d2d929 )
by Felix
15:59 queued 13:13
created

UpdateRefIndexTask   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 84
ccs 18
cts 24
cp 0.75
rs 10
c 0
b 0
f 0
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setSelectedTables() 0 3 1
A isUpdateAllTables() 0 3 1
A getRefIndex() 0 7 2
A getSelectedTables() 0 3 1
A execute() 0 14 3
A setUpdateAllTables() 0 3 1
1
<?php
2
3
namespace Aoe\UpdateRefindex\Scheduler;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2018 AOE GmbH <[email protected]>
9
 *
10
 *  All rights reserved
11
 *
12
 *  This script is part of the TYPO3 project. The TYPO3 project is
13
 *  free software; you can redistribute it and/or modify
14
 *  it under the terms of the GNU General Public License as published by
15
 *  the Free Software Foundation; either version 2 of the License, or
16
 *  (at your option) any later version.
17
 *
18
 *  The GNU General Public License can be found at
19
 *  http://www.gnu.org/copyleft/gpl.html.
20
 *
21
 *  This script is distributed in the hope that it will be useful,
22
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 *  GNU General Public License for more details.
25
 *
26
 *  This copyright notice MUST APPEAR in all copies of the script!
27
 ***************************************************************/
28
29
use Aoe\UpdateRefindex\Typo3\RefIndex;
30
use TYPO3\CMS\Core\Utility\GeneralUtility;
31
use TYPO3\CMS\Scheduler\Task\AbstractTask;
32
33
/**
34
 * scheduler-task to update refindex of TYPO3
35
 *
36
 * @package update_refindex
37
 * @subpackage Scheduler
38
 */
39
class UpdateRefIndexTask extends AbstractTask
40
{
41
    /**
42
     * Boolean flag indicating if all existing tables should be processed
43
     *
44
     * @var boolean
45
     */
46
    public $updateAllTables = false;
47
48
    /**
49
     * Comma separated list of tables
50
     *
51
     * @var string
52
     */
53
    public $updateRefindexSelectedTables;
54
55
    /**
56
     * @var RefIndex
57
     */
58
    private $refIndex;
59
60
    /**
61
     * execute the task
62
     *
63
     * @return boolean
64
     */
65 2
    public function execute()
66
    {
67 2
        $shellExitCode = true;
68
        try {
69 2
            $selectedTables = $this->isUpdateAllTables() ? $this->getRefIndex()
70 2
                ->getExistingTables() : $this->getSelectedTables();
71 2
            $this->getRefIndex()
72 2
                ->setSelectedTables($selectedTables)
73 2
                ->update();
74
        } catch (\Exception $e) {
75
            $shellExitCode = false;
76
        }
77
78 2
        return $shellExitCode;
79
    }
80
81
    /**
82
     * @return boolean
83
     */
84 2
    public function isUpdateAllTables()
85
    {
86 2
        return $this->updateAllTables;
87
    }
88
89
    /**
90
     * @param boolean $updateAllTables
91
     */
92 1
    public function setUpdateAllTables($updateAllTables)
93
    {
94 1
        $this->updateAllTables = $updateAllTables;
95 1
    }
96
97
    /**
98
     * @return array
99
     */
100 1
    public function getSelectedTables()
101
    {
102 1
        return explode(',', $this->updateRefindexSelectedTables);
103
    }
104
105
    /**
106
     * @param array $selectedTables
107
     */
108 1
    public function setSelectedTables(array $selectedTables)
109
    {
110 1
        $this->updateRefindexSelectedTables = implode(',', $selectedTables);
111 1
    }
112
113
    /**
114
     * @return RefIndex
115
     */
116
    protected function getRefIndex()
117
    {
118
        if ($this->refIndex === null) {
119
            $this->refIndex = GeneralUtility::makeInstance(RefIndex::class);
120
        }
121
122
        return $this->refIndex;
123
    }
124
}
125