Skip to content

Commit 5ddf996

Browse files
committed
wip|fix: Missing method in @internal class SchemaInformation
Relates: #20
1 parent da8329f commit 5ddf996

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

Classes/PhpDataSet.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
namespace Codappix\Typo3PhpDatasets;
2525

26+
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
2627
use RuntimeException;
2728
use TYPO3\CMS\Core\Database\ConnectionPool;
2829
use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -39,15 +40,33 @@ public function import(array $dataSet): void
3940
$tableDetails = $connection->getSchemaManager()->listTableDetails($tableName);
4041
} elseif (method_exists($connection, 'getSchemaInformation')) {
4142
// >= 13
42-
$tableDetails = $connection->getSchemaInformation()->introspectTable($tableName);
43+
$tableDetails = $connection->getSchemaInformation()->getTableInfo($tableName);
4344
} else {
4445
throw new RuntimeException('Could not check the schema for table: ' . $tableName, 1707144020);
4546
}
4647

4748
foreach ($records as $record) {
4849
$types = [];
4950
foreach (array_keys($record) as $columnName) {
50-
$types[] = $tableDetails->getColumn((string)$columnName)->getType()->getBindingType();
51+
if (method_exists($tableDetails, 'getColumn')) {
52+
// <= 12
53+
try {
54+
$column = $tableDetails->getColumn((string)$columnName);
55+
} catch (ColumnDoesNotExist $exception) {
56+
throw new RuntimeException('Column "' . $columnName . '" does not exist in table: ' . $tableName, 1760699318);
57+
}
58+
} else if (method_exists($tableDetails, 'getColumnInfo')) {
59+
// >= 13
60+
$column = $tableDetails->getColumnInfo((string)$columnName);
61+
62+
if ($column === null) {
63+
throw new RuntimeException('Column "' . $columnName . '" does not exist in table: ' . $tableName, 1760699318);
64+
}
65+
} else {
66+
throw new RuntimeException('Could not get info for column "' . $columnName . '" of table: ' . $tableName, 1760697878);
67+
}
68+
69+
$types[] = $column->getType()->getBindingType();
5170
}
5271

5372
$connection->insert($tableName, $record, $types);

Tests/Functional/ImportTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function failsIfSqlError(): void
8282
$this->expectExceptionMessageMatches(
8383
'#Error for PHP data-set "' . __DIR__ . '/Fixtures/WithBrokenSql.php":'
8484
. PHP_EOL
85-
. 'There is no column with name .*none_existing_column.* on table .*pages.*\.#'
85+
. 'Column "none_existing_column" does not exist in table: pages#'
8686
);
8787
$this->importPHPDataSet(__DIR__ . '/Fixtures/WithBrokenSql.php');
8888
}

0 commit comments

Comments
 (0)