TYPO3 CMS  TYPO3_8-7
TcaPreparation.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
21 
28 {
29 
43  public function prepare(array $tca): array
44  {
45  $tca = $this->prepareQuotingOfTableNamesAndColumnNames($tca);
46  return $tca;
47  }
48 
55  protected function prepareQuotingOfTableNamesAndColumnNames(array $tca): array
56  {
57  $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
58 
59  $newTca = $tca;
60  $configToPrepareQuoting = [
61  'foreign_table_where',
62  'MM_table_where',
63  'search' => 'andWhere'
64  ];
65  foreach ($tca as $table => $tableDefinition) {
66  if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
67  continue;
68  }
69 
70  foreach ($tableDefinition['columns'] as $columnName => $columnConfig) {
71  foreach ($configToPrepareQuoting as $level => $value) {
72  if (is_string($level)) {
73  $sqlQueryPartToPrepareQuotingIn = $columnConfig['config'][$level][$value] ?? '';
74  } else {
75  $sqlQueryPartToPrepareQuotingIn = $columnConfig['config'][$value] ?? '';
76  }
77  if (mb_strpos($sqlQueryPartToPrepareQuotingIn, '{#') !== false) {
79  $connectionPool->getConnectionForTable($table),
80  $sqlQueryPartToPrepareQuotingIn
81  );
82  if (is_string($level)) {
83  $newTca[$table]['columns'][$columnName]['config'][$level][$value] = $quoted;
84  } else {
85  $newTca[$table]['columns'][$columnName]['config'][$value] = $quoted;
86  }
87  }
88  }
89  }
90  }
91 
92  return $newTca;
93  }
94 }
static makeInstance($className,... $constructorArguments)
static quoteDatabaseIdentifiers(Connection $connection, string $sql)