Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions Classes/PhpDataSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace Codappix\Typo3PhpDatasets;

use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use RuntimeException;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -39,15 +40,33 @@
$tableDetails = $connection->getSchemaManager()->listTableDetails($tableName);
} elseif (method_exists($connection, 'getSchemaInformation')) {
// >= 13
$tableDetails = $connection->getSchemaInformation()->introspectTable($tableName);
$tableDetails = $connection->getSchemaInformation()->getTableInfo($tableName);

Check failure on line 43 in Classes/PhpDataSet.php

View workflow job for this annotation

GitHub Actions / code-quality (8.1, ^12.4)

Call to an undefined method TYPO3\CMS\Core\Database\Schema\SchemaInformation::getTableInfo().

Check failure on line 43 in Classes/PhpDataSet.php

View workflow job for this annotation

GitHub Actions / code-quality (8.4, ^12.4)

Call to an undefined method TYPO3\CMS\Core\Database\Schema\SchemaInformation::getTableInfo().

Check failure on line 43 in Classes/PhpDataSet.php

View workflow job for this annotation

GitHub Actions / code-quality (8.2, ^12.4)

Call to an undefined method TYPO3\CMS\Core\Database\Schema\SchemaInformation::getTableInfo().
} else {
throw new RuntimeException('Could not check the schema for table: ' . $tableName, 1707144020);
}

foreach ($records as $record) {
$types = [];
foreach (array_keys($record) as $columnName) {
$types[] = $tableDetails->getColumn((string)$columnName)->getType()->getBindingType();
if (method_exists($tableDetails, 'getColumn') && is_object($tableDetails)) {
// <= 12
try {
$types[] = $tableDetails->getColumn((string)$columnName)->getType()->getBindingType();
} catch (ColumnDoesNotExist $exception) {

Check failure on line 55 in Classes/PhpDataSet.php

View workflow job for this annotation

GitHub Actions / code-quality (8.0, ^11.5)

Caught class Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist not found.

Check failure on line 55 in Classes/PhpDataSet.php

View workflow job for this annotation

GitHub Actions / code-quality (7.4, ^11.5)

Caught class Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist not found.

Check failure on line 55 in Classes/PhpDataSet.php

View workflow job for this annotation

GitHub Actions / code-quality (8.2, ^11.5)

Caught class Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist not found.
throw new RuntimeException('Column "' . $columnName . '" does not exist in table: ' . $tableName, 1760699318);
}
} elseif (method_exists($tableDetails, 'getColumnInfo') && is_object($tableDetails)) {
// >= 13
$column = $tableDetails->getColumnInfo((string)$columnName);

if ($column === null) {
throw new RuntimeException('Column "' . $columnName . '" does not exist in table: ' . $tableName, 1760699318);
}

$types[] = $column->getType()->getBindingType();
} else {
throw new RuntimeException('Could not get info for column "' . $columnName . '" of table: ' . $tableName, 1760697878);
}
}

$connection->insert($tableName, $record, $types);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/ImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function failsIfSqlError(): void
$this->expectExceptionMessageMatches(
'#Error for PHP data-set "' . __DIR__ . '/Fixtures/WithBrokenSql.php":'
. PHP_EOL
. 'There is no column with name .*none_existing_column.* on table .*pages.*\.#'
. 'Column "none_existing_column" does not exist in table: pages#'
);
$this->importPHPDataSet(__DIR__ . '/Fixtures/WithBrokenSql.php');
}
Expand Down
Loading