1 | <?php |
||
18 | class QueryBuilder extends CoreQueryBuilder |
||
19 | { |
||
20 | /** |
||
21 | * @var Typo3Service |
||
22 | */ |
||
23 | private $typo3Service; |
||
24 | |||
25 | /** |
||
26 | * Sets a new value for a column in a bulk update query. |
||
27 | * |
||
28 | * @param string $key The column to set. |
||
29 | * @param string $value The value, expression, placeholder, etc. |
||
30 | * @param bool $createNamedParameter Automatically create a named parameter for the value |
||
31 | * |
||
32 | * @return QueryBuilder This QueryBuilder instance. |
||
33 | */ |
||
34 | public function set(string $key, $value, bool $createNamedParameter = true): CoreQueryBuilder |
||
35 | { |
||
36 | if ('uid' === $key && $this->shouldTableBeSequenced()) { |
||
37 | throw new \InvalidArgumentException('no uid allowed in update statement!', 1564122229); |
||
38 | } |
||
39 | |||
40 | parent::set($key, $value, $createNamedParameter); |
||
41 | |||
42 | return $this; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Specifies values for an insert query indexed by column names. |
||
47 | * Replaces any previous values, if any. |
||
48 | * |
||
49 | * @param array $values The values to specify for the insert query indexed by column names. |
||
50 | * @param bool $createNamedParameters Automatically create named parameters for all values |
||
51 | * |
||
52 | * @return QueryBuilder This QueryBuilder instance. |
||
53 | */ |
||
54 | public function values(array $values, bool $createNamedParameters = true): CoreQueryBuilder |
||
55 | { |
||
56 | parent::values( |
||
57 | $this->getTypo3Service()->modifyInsertFields($this->sanitizeTableName($this->concreteQueryBuilder->getQueryPart('from')['table']), $values), |
||
58 | $createNamedParameters |
||
59 | ); |
||
60 | |||
61 | return $this; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * create instance of Typo3Service by lazy-loading |
||
66 | * |
||
67 | * Why we do this? |
||
68 | * Because some unittests backup the variable $GLOBALS (and so, also the variable $GLOBALS['TYPO3_DB']), which means, that this |
||
69 | * object/class will be serialized/unserialized, so the instance of Typo3Service will be null after unserialization! |
||
70 | * |
||
71 | * @return Typo3Service |
||
72 | */ |
||
73 | protected function getTypo3Service() |
||
81 | |||
82 | /** |
||
83 | * Determines the defined table name without quotation marks (`). |
||
84 | * |
||
85 | * @param string $tableName |
||
86 | * @return string |
||
87 | */ |
||
88 | protected function sanitizeTableName(string $tableName): string |
||
97 | |||
98 | /** |
||
99 | * @return bool |
||
100 | */ |
||
101 | protected function shouldTableBeSequenced(): bool |
||
105 | } |
||
106 |