From: Maxime LECLERCQ Date: Fri, 19 Feb 2016 13:22:27 +0000 (+0100) Subject: Fix #1551 - Redirect to the last page when current page is out of range X-Git-Tag: 2.0.0-beta.1~24^2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=671a2b887f3215366e8acc05fcfa4e57264d3e69;p=github%2Fwallabag%2Fwallabag.git Fix #1551 - Redirect to the last page when current page is out of range --- diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index ea77d138..0fae3a0f 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -3,6 +3,7 @@ namespace Wallabag\CoreBundle\Controller; use Pagerfanta\Adapter\DoctrineORMAdapter; +use Pagerfanta\Exception\OutOfRangeCurrentPageException; use Pagerfanta\Pagerfanta; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; @@ -252,7 +253,13 @@ class EntryController extends Controller $entries = new Pagerfanta($pagerAdapter); $entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage()); - $entries->setCurrentPage($page); + try { + $entries->setCurrentPage($page); + } catch (OutOfRangeCurrentPageException $e) { + if ($page > 1) { + return $this->redirect($this->generateUrl($type, array('page' => $entries->getNbPages())), 302); + } + } return $this->render( 'WallabagCoreBundle:Entry:entries.html.twig', diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 32d6a575..5512d6e1 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php @@ -216,6 +216,17 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertEquals(200, $client->getResponse()->getStatusCode()); } + public function testRangeException() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->request('GET', '/all/list/900'); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); + } + /** * @depends testPostNewOk */