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\Utility\GeneralUtility; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @package Aoe\AoeDbSequenzer |
32
|
|
|
*/ |
33
|
|
|
class Typo3Service |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @var Sequenzer |
37
|
|
|
*/ |
38
|
|
|
private $sequenzer; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
private $conf; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* array of configured tables that should call the sequenzer |
47
|
|
|
* |
48
|
|
|
* @var array |
49
|
|
|
*/ |
50
|
|
|
private $supportedTables; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param Sequenzer $sequenzer |
54
|
|
|
*/ |
55
|
|
|
public function __construct(Sequenzer $sequenzer) |
56
|
|
|
{ |
57
|
|
|
$this->conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['aoe_dbsequenzer']); |
58
|
|
|
|
59
|
|
|
$this->sequenzer = $sequenzer; |
60
|
|
|
$this->sequenzer->setDefaultOffset(intval($this->conf['offset'])); |
61
|
|
|
$this->sequenzer->setDefaultStart(intval($this->conf['system'])); |
62
|
|
|
|
63
|
|
|
$explodedValues = explode(',', $this->conf['tables']); |
64
|
|
|
$this->supportedTables = array_map('trim', $explodedValues); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* sets the db link |
69
|
|
|
* |
70
|
|
|
* @param \mysqli|NULL $link |
71
|
|
|
*/ |
72
|
|
|
public function setDbLink($link) |
73
|
|
|
{ |
74
|
|
|
$this->sequenzer->setDbLink($link); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Modify a TYPO3 insert array (key -> value) , and adds the uid that should be forced during INSERT |
79
|
|
|
* |
80
|
|
|
* @param string $tableName |
81
|
|
|
* @param array $fields_values |
82
|
|
|
* @return array |
83
|
|
|
*/ |
84
|
|
|
public function modifyInsertFields($tableName, array $fields_values) |
85
|
|
|
{ |
86
|
|
|
if (false === $this->needsSequenzer($tableName)) { |
87
|
|
|
return $fields_values; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if (isset($fields_values['uid'])) { |
91
|
|
|
$e = new \Exception('', 1512378232); |
92
|
|
|
GeneralUtility::devLog( |
93
|
|
|
'UID ' . $fields_values['uid'] . ' is already set for table "' . $tableName . '"', |
94
|
|
|
'aoe_dbsequenzer', |
95
|
|
|
2, |
96
|
|
|
$e->getTraceAsString() |
97
|
|
|
); |
98
|
|
|
} else { |
99
|
|
|
$fields_values['uid'] = $this->sequenzer->getNextIdForTable($tableName); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $fields_values; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* If a table is configured to use the sequenzer |
107
|
|
|
* |
108
|
|
|
* @param string $tableName |
109
|
|
|
* @return boolean |
110
|
|
|
*/ |
111
|
|
|
public function needsSequenzer($tableName) |
112
|
|
|
{ |
113
|
|
|
if (in_array($tableName, $this->supportedTables)) { |
114
|
|
|
return true; |
115
|
|
|
} |
116
|
|
|
return false; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.