|
9 | 9 | use Doctrine\DBAL\Schema\AbstractAsset; |
10 | 10 | use Doctrine\DBAL\Schema\AbstractSchemaManager; |
11 | 11 | use Doctrine\DBAL\Schema\ComparatorConfig; |
| 12 | +use Doctrine\DBAL\Schema\DefaultExpression; |
| 13 | +use Doctrine\DBAL\Schema\DefaultExpression\CurrentDate; |
| 14 | +use Doctrine\DBAL\Schema\DefaultExpression\CurrentTime; |
| 15 | +use Doctrine\DBAL\Schema\DefaultExpression\CurrentTimestamp; |
12 | 16 | use Doctrine\DBAL\Schema\ForeignKeyConstraintEditor; |
13 | 17 | use Doctrine\DBAL\Schema\Index; |
14 | 18 | use Doctrine\DBAL\Schema\Index\IndexedColumn; |
|
18 | 22 | use Doctrine\DBAL\Schema\PrimaryKeyConstraint; |
19 | 23 | use Doctrine\DBAL\Schema\Schema; |
20 | 24 | use Doctrine\DBAL\Schema\Table; |
| 25 | +use Doctrine\DBAL\Types\Types; |
21 | 26 | use Doctrine\ORM\EntityManagerInterface; |
22 | 27 | use Doctrine\ORM\Mapping\AssociationMapping; |
23 | 28 | use Doctrine\ORM\Mapping\ClassMetadata; |
|
46 | 51 | use function current; |
47 | 52 | use function implode; |
48 | 53 | use function in_array; |
| 54 | +use function interface_exists; |
49 | 55 | use function is_numeric; |
50 | 56 | use function method_exists; |
51 | 57 | use function preg_match; |
@@ -489,6 +495,37 @@ private function gatherColumn( |
489 | 495 | // the 'default' option can be overwritten here |
490 | 496 | $options = $this->gatherColumnOptions($mapping) + $options; |
491 | 497 |
|
| 498 | + if (isset($options['default']) && interface_exists(DefaultExpression::class)) { |
| 499 | + if ( |
| 500 | + in_array($mapping->type, [ |
| 501 | + Types::DATETIME_MUTABLE, |
| 502 | + Types::DATETIME_IMMUTABLE, |
| 503 | + Types::DATETIMETZ_MUTABLE, |
| 504 | + Types::DATETIMETZ_IMMUTABLE, |
| 505 | + ], true) |
| 506 | + && $options['default'] === $this->platform->getCurrentTimestampSQL() |
| 507 | + ) { |
| 508 | + /** @phpstan-ignore class.notFound (if DefaultExpression exists, CurrentTimestamp exists as well) */ |
| 509 | + $options['default'] = new CurrentTimestamp(); |
| 510 | + } |
| 511 | + |
| 512 | + if ( |
| 513 | + in_array($mapping->type, [Types::TIME_MUTABLE, Types::TIME_IMMUTABLE], true) |
| 514 | + && $options['default'] === $this->platform->getCurrentTimeSQL() |
| 515 | + ) { |
| 516 | + /** @phpstan-ignore class.notFound (if DefaultExpression exists, CurrentTime exists as well) */ |
| 517 | + $options['default'] = new CurrentTime(); |
| 518 | + } |
| 519 | + |
| 520 | + if ( |
| 521 | + in_array($mapping->type, [Types::DATE_MUTABLE, Types::DATE_IMMUTABLE], true) |
| 522 | + && $options['default'] === $this->platform->getCurrentDateSQL() |
| 523 | + ) { |
| 524 | + /** @phpstan-ignore class.notFound (if DefaultExpression exists, CurrentDate exists as well) */ |
| 525 | + $options['default'] = new CurrentDate(); |
| 526 | + } |
| 527 | + } |
| 528 | + |
492 | 529 | if ($class->isIdGeneratorIdentity() && $class->getIdentifierFieldNames() === [$mapping->fieldName]) { |
493 | 530 | $options['autoincrement'] = true; |
494 | 531 | } |
|
0 commit comments