1
|
|
|
<?php |
2
|
|
|
namespace Aoe\AoeDbSequenzer\Service; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2017 AOE GmbH ([email protected]) |
8
|
|
|
* All rights reserved |
9
|
|
|
* |
10
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
11
|
|
|
* free software; you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU General Public License as published by |
13
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
14
|
|
|
* (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* The GNU General Public License can be found at |
17
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
18
|
|
|
* |
19
|
|
|
* This script is distributed in the hope that it will be useful, |
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22
|
|
|
* GNU General Public License for more details. |
23
|
|
|
* |
24
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
25
|
|
|
***************************************************************/ |
26
|
|
|
|
27
|
|
|
use Aoe\AoeDbSequenzer\Sequenzer; |
28
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
29
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @package Aoe\AoeDbSequenzer |
33
|
|
|
*/ |
34
|
|
|
class Typo3Service implements SingletonInterface |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @var Sequenzer |
38
|
|
|
*/ |
39
|
|
|
private $sequenzer; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var array |
43
|
|
|
*/ |
44
|
|
|
private $conf; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* array of configured tables that should call the sequenzer |
48
|
|
|
* |
49
|
|
|
* @var array |
50
|
|
|
*/ |
51
|
|
|
private $supportedTables; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param Sequenzer $sequenzer |
55
|
|
|
*/ |
56
|
3 |
|
public function __construct(Sequenzer $sequenzer) |
57
|
|
|
{ |
58
|
3 |
|
$this->conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['aoe_dbsequenzer']); |
59
|
|
|
|
60
|
3 |
|
$this->sequenzer = $sequenzer; |
61
|
3 |
|
$this->sequenzer->setDefaultOffset(intval($this->conf['offset'])); |
62
|
3 |
|
$this->sequenzer->setDefaultStart(intval($this->conf['system'])); |
63
|
|
|
|
64
|
3 |
|
$explodedValues = explode(',', $this->conf['tables']); |
65
|
3 |
|
$this->supportedTables = array_map('trim', $explodedValues); |
66
|
3 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Modify a TYPO3 insert array (key -> value) , and adds the uid that should be forced during INSERT |
70
|
|
|
* |
71
|
|
|
* @param string $tableName |
72
|
|
|
* @param array $fields_values |
73
|
|
|
* |
74
|
|
|
* @return array |
75
|
|
|
*/ |
76
|
2 |
|
public function modifyInsertFields($tableName, array $fields_values): array |
77
|
|
|
{ |
78
|
2 |
|
if (false === $this->needsSequenzer($tableName)) { |
79
|
1 |
|
return $fields_values; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
// How to test this when no exception is thrown ? |
83
|
1 |
|
if (isset($fields_values['uid'])) { |
84
|
|
|
$e = new \Exception('', 1512378232); |
85
|
|
|
GeneralUtility::devLog( |
|
|
|
|
86
|
|
|
'UID ' . $fields_values['uid'] . ' is already set for table "' . $tableName . '"', |
87
|
|
|
'aoe_dbsequenzer', |
88
|
|
|
2, |
89
|
|
|
$e->getTraceAsString() |
90
|
|
|
); |
91
|
|
|
} else { |
92
|
1 |
|
$fields_values['uid'] = $this->sequenzer->getNextIdForTable($tableName); |
93
|
|
|
} |
94
|
|
|
|
95
|
1 |
|
return $fields_values; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* If a table is configured to use the sequenzer |
100
|
|
|
* |
101
|
|
|
* @param string $tableName |
102
|
|
|
* @return boolean |
103
|
|
|
*/ |
104
|
2 |
|
public function needsSequenzer($tableName) |
105
|
|
|
{ |
106
|
2 |
|
return in_array($tableName, $this->supportedTables); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.