From 35a56bacd7dafd12afcfbbd0f2cf52c36b2c7d13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jakes=CC=8C?= Date: Tue, 30 Jul 2019 17:00:37 +0200 Subject: [PATCH] Avoid double table prefixing when cache not pregenerated in dev environments [MAILPOET-2235] --- lib/Doctrine/TablePrefixMetadataFactory.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/TablePrefixMetadataFactory.php b/lib/Doctrine/TablePrefixMetadataFactory.php index 5792b33efc..f38707d31f 100644 --- a/lib/Doctrine/TablePrefixMetadataFactory.php +++ b/lib/Doctrine/TablePrefixMetadataFactory.php @@ -26,7 +26,14 @@ class TablePrefixMetadataFactory extends ClassMetadataFactory { function getMetadataFor($className) { $classMetadata = parent::getMetadataFor($className); - if ($classMetadata instanceof ClassMetadata && !isset($this->prefixed_map[$classMetadata->getName()])) { + if (isset($this->prefixed_map[$classMetadata->getName()])) { + return $classMetadata; + } + + // prefix tables only after they are saved to cache so the prefix does not get included in cache + // (getMetadataFor can call itself recursively but it saves to cache only after the recursive calls) + $is_cached = $this->getCacheDriver()->contains($classMetadata->getName() . $this->cacheSalt); + if ($classMetadata instanceof ClassMetadata && $is_cached) { $this->addPrefix($classMetadata); $this->prefixed_map[$classMetadata->getName()] = true; }