From 996e47bf610c5b3ea22ea429b8c9a338db20fe0a Mon Sep 17 00:00:00 2001 From: Eric GELOEN Date: Fri, 6 Jul 2012 17:49:03 +0200 Subject: [PATCH 1/3] Replaced a shallow-copy with a deep-copy to avoid side effects. --- lib/Doctrine/ORM/Tools/Pagination/Paginator.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php index e9e3a4d92..202602015 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php +++ b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php @@ -208,7 +208,11 @@ class Paginator implements \Countable, \IteratorAggregate { /* @var $cloneQuery Query */ $cloneQuery = clone $query; - $cloneQuery->setParameters($query->getParameters()); + + foreach ($query->getParameters() as $parameter) { + $cloneQuery->setParameter($parameter->getName(), $parameter->getValue(), $parameter->getType()); + } + foreach ($query->getHints() as $name => $value) { $cloneQuery->setHint($name, $value); } From 8c24e528adffaf0987be270b2931b526dd08d577 Mon Sep 17 00:00:00 2001 From: Eric GELOEN Date: Sat, 7 Jul 2012 11:33:58 +0200 Subject: [PATCH 2/3] Clone directly the ArrayCollection instead of looping --- lib/Doctrine/ORM/Tools/Pagination/Paginator.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php index 202602015..bb1514ea0 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php +++ b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php @@ -209,9 +209,7 @@ class Paginator implements \Countable, \IteratorAggregate /* @var $cloneQuery Query */ $cloneQuery = clone $query; - foreach ($query->getParameters() as $parameter) { - $cloneQuery->setParameter($parameter->getName(), $parameter->getValue(), $parameter->getType()); - } + $cloneQuery->setParameters(clone $query->getParameters()); foreach ($query->getHints() as $name => $value) { $cloneQuery->setHint($name, $value); From 3bdf86922c62335199170974b6c275d11e7dda58 Mon Sep 17 00:00:00 2001 From: Eric GELOEN Date: Sat, 7 Jul 2012 17:27:32 +0200 Subject: [PATCH 3/3] Add clone query test --- .../Doctrine/Tests/ORM/Functional/PaginationTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php b/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php index 28e18f0de..0a2845582 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php @@ -128,6 +128,17 @@ class PaginationTest extends \Doctrine\Tests\OrmFunctionalTestCase count($paginator); } + public function testCloneQuery() + { + $dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u"; + $query = $this->_em->createQuery($dql); + + $paginator = new Paginator($query); + $paginator->getIterator(); + + $this->assertTrue($query->getParameters()->isEmpty()); + } + public function populate() { for ($i = 0; $i < 3; $i++) {