Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dbal deprecation of passing unknown options to a Column #446

Merged
Merged
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
30 changes: 26 additions & 4 deletions src/EventListener/CreateSchemaListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace SimpleThings\EntityAudit\EventListener;

use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Types;
Expand Down Expand Up @@ -83,10 +84,7 @@ public function postGenerateSchemaTable(GenerateSchemaTableEventArgs $eventArgs)
);

foreach ($entityTable->getColumns() as $column) {
$revisionTable->addColumn($column->getName(), $column->getType()->getName(), array_merge(
$column->toArray(),
['notnull' => false, 'autoincrement' => false]
));
$this->addColumnToTable($column, $revisionTable);
}
$revisionTable->addColumn($this->config->getRevisionFieldName(), $this->config->getRevisionIdFieldType());
$revisionTable->addColumn($this->config->getRevisionTypeFieldName(), Types::STRING, ['length' => 4]);
Expand Down Expand Up @@ -120,6 +118,30 @@ public function postGenerateSchema(GenerateSchemaEventArgs $eventArgs): void
$revisionsTable->setPrimaryKey(['id']);
}

/**
* Copies $column to another table. All its options are copied but notnull and autoincrement which are set to false.
*/
private function addColumnToTable(Column $column, Table $targetTable): void
{
$columnName = $column->getName();
$targetTable->addColumn($columnName, $column->getType()->getName());

$targetColumn = $targetTable->getColumn($columnName);
$targetColumn->setLength($column->getLength());
$targetColumn->setPrecision($column->getPrecision());
$targetColumn->setScale($column->getScale());
$targetColumn->setUnsigned($column->getUnsigned());
$targetColumn->setFixed($column->getFixed());
$targetColumn->setDefault($column->getDefault());
$targetColumn->setColumnDefinition($column->getColumnDefinition());
$targetColumn->setComment($column->getComment());
$targetColumn->setPlatformOptions($column->getPlatformOptions());
$targetColumn->setCustomSchemaOptions($column->getCustomSchemaOptions());

$targetColumn->setNotnull(false);
$targetColumn->setAutoincrement(false);
}

private function createRevisionsTable(Schema $schema): Table
{
$revisionsTableName = $this->config->getRevisionTableName();
Expand Down