1
|
|
|
<?php
|
|
|
|
|
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
|
|
|
|