Skip to content

Commit

Permalink
Merge pull request #3142 from matesko/master
Browse files Browse the repository at this point in the history
Multiple EntityManagers prefixes
  • Loading branch information
bobdenotter authored Mar 25, 2022
2 parents e69cdd9 + 9ee7a6a commit 923277e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/Doctrine/TablePrefix.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public function __construct($tablePrefix, ManagerRegistry $managerRegistry)

public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void
{
if ($tablePrefix = $this->getTablePrefix()) {
$entityManager = $eventArgs->getEntityManager();
if ($tablePrefix = $this->getTablePrefix($entityManager)) {
$classMetadata = $eventArgs->getClassMetadata();

if (! $classMetadata->isInheritanceTypeSingleTable()
Expand Down
14 changes: 5 additions & 9 deletions src/Doctrine/TablePrefixTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ trait TablePrefixTrait
protected function setTablePrefix(ObjectManager $manager, string $prefix)
{
$key = spl_object_hash($manager);
$this->tablePrefixes[$key] = Str::ensureEndsWith($prefix, '_');
$this->tablePrefixes[$key] = empty($prefix) ? '' : Str::ensureEndsWith($prefix, '_');

return $this;
}
Expand All @@ -46,14 +46,10 @@ protected function setTablePrefixes($tablePrefixes, ManagerRegistry $managerRegi
return $this;
}

/**
* Since we introduced `symfony/proxy-manager-bridge`, the keys in the tableprefix
* no longer match what the manager tells us it should be. For example, the
* given key was `0000000005ee10ad0000000043b453e3`, but in our reference
* table we had `0000000005ee10e90000000043b453e3`. We just return the first one, now
*/
protected function getTablePrefix(): string
protected function getTablePrefix(ObjectManager $manager): string
{
return current($this->tablePrefixes);
$key = spl_object_hash($manager);

return $this->tablePrefixes[$key] ?? '';
}
}
3 changes: 2 additions & 1 deletion src/Doctrine/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class Version
/** @var string */
private $tablePrefix;

public function __construct(Connection $connection, string $tablePrefix = 'bolt')
public function __construct(Connection $connection, $tablePrefix = 'bolt')
{
$this->connection = $connection;
$tablePrefix = is_array($tablePrefix) ? $tablePrefix['default'] : $tablePrefix;
$this->tablePrefix = Str::ensureEndsWith($tablePrefix, '_');
}

Expand Down

0 comments on commit 923277e

Please sign in to comment.