diff options
author | Nicolas Lœuillet <nicolas@loeuillet.org> | 2016-10-21 15:12:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-21 15:12:29 +0200 |
commit | 49dee2d2de63af36248e92ce740da2692358280e (patch) | |
tree | 01649e5e6fcfeadeb61cc56408a03658be85a69a | |
parent | 7180aaed45dce62e40620a9e4b202526ebd6a3bb (diff) | |
parent | f6798f69c3f3d6f4f8295f8168785ade6f1f125a (diff) | |
download | wallabag-49dee2d2de63af36248e92ce740da2692358280e.tar.gz wallabag-49dee2d2de63af36248e92ce740da2692358280e.tar.zst wallabag-49dee2d2de63af36248e92ce740da2692358280e.zip |
Merge pull request #2482 from wallabag/avoid-bad-refresh
If reload content failed, don’t update it
6 files changed, 53 insertions, 2 deletions
diff --git a/app/config/config.yml b/app/config/config.yml index 5127c8cf..a56cbdd9 100644 --- a/app/config/config.yml +++ b/app/config/config.yml | |||
@@ -50,6 +50,7 @@ wallabag_core: | |||
50 | rss_limit: 50 | 50 | rss_limit: 50 |
51 | reading_speed: 1 | 51 | reading_speed: 1 |
52 | cache_lifetime: 10 | 52 | cache_lifetime: 10 |
53 | fetching_error_message: "wallabag can't retrieve contents for this article. Please report this issue to us." | ||
53 | 54 | ||
54 | wallabag_user: | 55 | wallabag_user: |
55 | registration_enabled: "%fosuser_registration%" | 56 | registration_enabled: "%fosuser_registration%" |
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 3b28e635..97bb3d12 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -330,6 +330,15 @@ class EntryController extends Controller | |||
330 | 330 | ||
331 | $this->updateEntry($entry, 'entry_reloaded'); | 331 | $this->updateEntry($entry, 'entry_reloaded'); |
332 | 332 | ||
333 | // if refreshing entry failed, don't save it | ||
334 | if ($this->getParameter('wallabag_core.fetching_error_message') === $entry->getContent()) { | ||
335 | $bag = $this->get('session')->getFlashBag(); | ||
336 | $bag->clear(); | ||
337 | $bag->add('notice', 'flashes.entry.notice.entry_reloaded_failed'); | ||
338 | |||
339 | return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()])); | ||
340 | } | ||
341 | |||
333 | $em = $this->getDoctrine()->getManager(); | 342 | $em = $this->getDoctrine()->getManager(); |
334 | $em->persist($entry); | 343 | $em->persist($entry); |
335 | $em->flush(); | 344 | $em->flush(); |
diff --git a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php index d8141eea..3a3da024 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php | |||
@@ -39,6 +39,8 @@ class Configuration implements ConfigurationInterface | |||
39 | ->integerNode('cache_lifetime') | 39 | ->integerNode('cache_lifetime') |
40 | ->defaultValue(10) | 40 | ->defaultValue(10) |
41 | ->end() | 41 | ->end() |
42 | ->scalarNode('fetching_error_message') | ||
43 | ->end() | ||
42 | ->end() | 44 | ->end() |
43 | ; | 45 | ; |
44 | 46 | ||
diff --git a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php index 0cbde908..b4992d54 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php | |||
@@ -23,6 +23,7 @@ class WallabagCoreExtension extends Extension | |||
23 | $container->setParameter('wallabag_core.version', $config['version']); | 23 | $container->setParameter('wallabag_core.version', $config['version']); |
24 | $container->setParameter('wallabag_core.paypal_url', $config['paypal_url']); | 24 | $container->setParameter('wallabag_core.paypal_url', $config['paypal_url']); |
25 | $container->setParameter('wallabag_core.cache_lifetime', $config['cache_lifetime']); | 25 | $container->setParameter('wallabag_core.cache_lifetime', $config['cache_lifetime']); |
26 | $container->setParameter('wallabag_core.fetching_error_message', $config['fetching_error_message']); | ||
26 | 27 | ||
27 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | 28 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
28 | $loader->load('services.yml'); | 29 | $loader->load('services.yml'); |
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index a4b727f4..614488a6 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml | |||
@@ -40,7 +40,7 @@ services: | |||
40 | class: Graby\Graby | 40 | class: Graby\Graby |
41 | arguments: | 41 | arguments: |
42 | - | 42 | - |
43 | error_message: "wallabag can't retrieve contents for this article. Please report this issue to us." | 43 | error_message: '%wallabag_core.fetching_error_message%' |
44 | http_client: | 44 | http_client: |
45 | user_agents: | 45 | user_agents: |
46 | 'lifehacker.com': 'PHP/5.2' | 46 | 'lifehacker.com': 'PHP/5.2' |
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 9b03a519..05113650 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | |||
@@ -359,11 +359,49 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
359 | 359 | ||
360 | $content = $em | 360 | $content = $em |
361 | ->getRepository('WallabagCoreBundle:Entry') | 361 | ->getRepository('WallabagCoreBundle:Entry') |
362 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 362 | ->find($content->getId()); |
363 | 363 | ||
364 | $this->assertNotEmpty($content->getContent()); | 364 | $this->assertNotEmpty($content->getContent()); |
365 | } | 365 | } |
366 | 366 | ||
367 | /** | ||
368 | * @depends testPostNewOk | ||
369 | */ | ||
370 | public function testReloadWithFetchingFailed() | ||
371 | { | ||
372 | $this->logInAs('admin'); | ||
373 | $client = $this->getClient(); | ||
374 | |||
375 | $em = $client->getContainer() | ||
376 | ->get('doctrine.orm.entity_manager'); | ||
377 | |||
378 | $content = $em | ||
379 | ->getRepository('WallabagCoreBundle:Entry') | ||
380 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
381 | |||
382 | // put a known failed url | ||
383 | $content->setUrl('http://0.0.0.0/failed.html'); | ||
384 | $em->persist($content); | ||
385 | $em->flush(); | ||
386 | |||
387 | $client->request('GET', '/reload/'.$content->getId()); | ||
388 | |||
389 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
390 | |||
391 | // force EntityManager to clear previous entity | ||
392 | // otherwise, retrieve the same entity will retrieve change from the previous request :0 | ||
393 | $em->clear(); | ||
394 | $newContent = $em | ||
395 | ->getRepository('WallabagCoreBundle:Entry') | ||
396 | ->find($content->getId()); | ||
397 | |||
398 | $newContent->setUrl($this->url); | ||
399 | $em->persist($newContent); | ||
400 | $em->flush(); | ||
401 | |||
402 | $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); | ||
403 | } | ||
404 | |||
367 | public function testEdit() | 405 | public function testEdit() |
368 | { | 406 | { |
369 | $this->logInAs('admin'); | 407 | $this->logInAs('admin'); |