From 859565b7f7cc81d52526ef55cb1e78e9dfebd1e3 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Fri, 27 Apr 2018 08:02:34 +0200 Subject: [PATCH] Clean up withReadPreference handling --- lib/Doctrine/MongoDB/Query/Query.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/Doctrine/MongoDB/Query/Query.php b/lib/Doctrine/MongoDB/Query/Query.php index b6edf4a4..7bfd30a1 100644 --- a/lib/Doctrine/MongoDB/Query/Query.php +++ b/lib/Doctrine/MongoDB/Query/Query.php @@ -481,17 +481,10 @@ private function withReadPreference($object, \Closure $closure) $object->setReadPreference($this->query['readPreference'], $this->query['readPreferenceTags']); try { - $result = $closure(); - } catch (\Exception $e) { - } - - $prevTags = ! empty($prevReadPref['tagsets']) ? $prevReadPref['tagsets'] : null; - $object->setReadPreference($prevReadPref['type'], $prevTags); - - if (isset($e)) { - throw $e; + return $closure(); + } finally { + $prevTags = ! empty($prevReadPref['tagsets']) ? $prevReadPref['tagsets'] : []; + $object->setReadPreference($prevReadPref['type'], $prevTags); } - - return $result; } }