From: Jeremy Benoist Date: Sat, 12 Mar 2016 09:45:14 +0000 (+0100) Subject: Fix hazardous bug with Postgres X-Git-Tag: 2.0.0-beta.2~3^2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=b95ffda2a105af4c6f4f86aca025a0bf967bc86a;p=github%2Fwallabag%2Fwallabag.git Fix hazardous bug with Postgres Instead of retrieving a random annotation, sort them to be sure they are all the same no matter the database used --- diff --git a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php index 7f35373f..5f7da70e 100644 --- a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php +++ b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php @@ -101,6 +101,7 @@ class AnnotationRepository extends EntityRepository return $this->createQueryBuilder('a') ->leftJoin('a.user', 'u') ->where('u.username = :username')->setParameter('username', $username) + ->orderBy('a.id', 'DESC') ->setMaxResults(1) ->getQuery() ->getSingleResult(); diff --git a/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php b/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php index 7a877f98..e972c2de 100644 --- a/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php +++ b/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php @@ -81,7 +81,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase $this->assertEquals('Big boss', $content['user']); $this->assertEquals('v1.0', $content['annotator_schema_version']); $this->assertEquals('a modified annotation', $content['text']); - $this->assertEquals('content', $content['quote']); + $this->assertEquals('my quote', $content['quote']); $annotationUpdated = $this->client->getContainer() ->get('doctrine.orm.entity_manager')