AbstractIdGenerator.php
9 months ago
AssignedGenerator.php
9 months ago
BigIntegerIdentityGenerator.php
9 months ago
IdentityGenerator.php
9 months ago
SequenceGenerator.php
9 months ago
TableGenerator.php
9 months ago
UuidGenerator.php
9 months ago
index.php
9 months ago
UuidGenerator.php
31 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\ORM\Id; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use MailPoetVendor\Doctrine\DBAL\Connections\PrimaryReadReplicaConnection; |
| 6 | use MailPoetVendor\Doctrine\DBAL\Platforms\AbstractPlatform; |
| 7 | use MailPoetVendor\Doctrine\Deprecations\Deprecation; |
| 8 | use MailPoetVendor\Doctrine\ORM\EntityManagerInterface; |
| 9 | use MailPoetVendor\Doctrine\ORM\Exception\NotSupported; |
| 10 | use function method_exists; |
| 11 | use function sprintf; |
| 12 | class UuidGenerator extends AbstractIdGenerator |
| 13 | { |
| 14 | public function __construct() |
| 15 | { |
| 16 | Deprecation::trigger('doctrine/orm', 'https://github.com/doctrine/orm/issues/7312', '%s is deprecated with no replacement, use an application-side generator instead', self::class); |
| 17 | if (!method_exists(AbstractPlatform::class, 'getGuidExpression')) { |
| 18 | throw NotSupported::createForDbal3(sprintf('Using the database to generate a UUID through %s', self::class)); |
| 19 | } |
| 20 | } |
| 21 | public function generateId(EntityManagerInterface $em, $entity) |
| 22 | { |
| 23 | $connection = $em->getConnection(); |
| 24 | $sql = 'SELECT ' . $connection->getDatabasePlatform()->getGuidExpression(); |
| 25 | if ($connection instanceof PrimaryReadReplicaConnection) { |
| 26 | $connection->ensureConnectedToPrimary(); |
| 27 | } |
| 28 | return $connection->executeQuery($sql)->fetchOne(); |
| 29 | } |
| 30 | } |
| 31 |