Restore old behavior for OutOfRangeCurrentPageException

This commit is contained in:
Nicolas Lœuillet 2016-04-12 16:40:18 +02:00
parent 76cd8dbb05
commit 1880da7420
No known key found for this signature in database
GPG key ID: 5656BE27E1E34D0A
2 changed files with 10 additions and 2 deletions

View file

@ -3,6 +3,7 @@
namespace Wallabag\CoreBundle\Controller; namespace Wallabag\CoreBundle\Controller;
use Pagerfanta\Adapter\DoctrineORMAdapter; use Pagerfanta\Adapter\DoctrineORMAdapter;
use Pagerfanta\Exception\OutOfRangeCurrentPageException;
use Pagerfanta\Pagerfanta; use Pagerfanta\Pagerfanta;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
@ -252,7 +253,13 @@ class EntryController extends Controller
$entries = new Pagerfanta($pagerAdapter); $entries = new Pagerfanta($pagerAdapter);
$entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage()); $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( return $this->render(
'WallabagCoreBundle:Entry:entries.html.twig', 'WallabagCoreBundle:Entry:entries.html.twig',

View file

@ -225,7 +225,8 @@ class EntryControllerTest extends WallabagCoreTestCase
$client->request('GET', '/all/list/900'); $client->request('GET', '/all/list/900');
$this->assertEquals(404, $client->getResponse()->getStatusCode()); $this->assertEquals(302, $client->getResponse()->getStatusCode());
$this->assertEquals('/all/list', $client->getResponse()->getTargetUrl());
} }
/** /**