TruncateTask   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 80.95%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 65
ccs 17
cts 21
cp 0.8095
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 7 2
A getTableList() 0 8 2
A getTables() 0 4 1
A setTables() 0 4 1
A getDb() 0 4 1
A truncateTable() 0 6 2
1
<?php
0 ignored issues
show
Coding Style introduced by
End of line character is invalid; expected "\n" but found "\r\n"
Loading history...
2
namespace Aoe\TruncateJob;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2018 AOE GmbH <[email protected]>
8
 *
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 3 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use TYPO3\CMS\Core\Database\DatabaseConnection;
29
use TYPO3\CMS\Scheduler\Task\AbstractTask;
30
31
/**
32
 * Export Task for scheduler
33
 * @package truncate_job
34
 */
35
class TruncateTask extends AbstractTask
36
{
37
    /**
38
     * @var string
39
     */
40
    private $tables;
41
42
    /**
43
     * truncate tables
44
     */
45 1
    public function execute()
46
    {
47 1
        foreach ($this->getTableList() as $table) {
48 1
            $this->truncateTable($table);
49 1
        }
50 1
        return true;
51
    }
52
53
    /**
54
     * @return array
55
     */
56 1
    public function getTableList()
57
    {
58 1
        $tables = explode(',', $this->tables);
59 1
        if (false === $tables) {
60
            return [];
61
        }
62 1
        return $tables;
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public function getTables()
69
    {
70
        return $this->tables;
71
    }
72
73
    /**
74
     * @param string $tables
75
     */
76 1
    public function setTables($tables)
77
    {
78 1
        $this->tables = $tables;
79 1
    }
80
81
    /**
82
     * @return DatabaseConnection
83
     */
84 1
    public function getDb()
85
    {
86 1
        return $GLOBALS['TYPO3_DB'];
87
    }
88
89
    /**
90
     * @param string $table
91
     * @throws \Exception
92
     */
93 1
    private function truncateTable($table)
94
    {
95 1
        if (false === $this->getDb()->exec_TRUNCATEquery($table)) {
96
            throw new \Exception('Truncate of table ' . $table . ' failed');
97
        }
98 1
    }
99
}
100