]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Ability to reload an entry
authorJeremy Benoist <jeremy.benoist@gmail.com>
Wed, 30 Dec 2015 08:41:17 +0000 (09:41 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Wed, 30 Dec 2015 08:41:17 +0000 (09:41 +0100)
Could be useful when we want to update the content or when the content failed to be fetched.

Fix #1503

src/Wallabag/CoreBundle/Controller/EntryController.php
src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entry.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig
src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php

index 2f3fd6a9348ab6ec26c0ae1b301de95610e3778b..041fe71ca77af8166e7787d1202c157af4af340d 100644 (file)
@@ -266,6 +266,33 @@ class EntryController extends Controller
         );
     }
 
+    /**
+     * Reload an entry.
+     * Refetch content from the website and make it readable again.
+     *
+     * @param Entry $entry
+     *
+     * @Route("/reload/{id}", requirements={"id" = "\d+"}, name="reload_entry")
+     *
+     * @return \Symfony\Component\HttpFoundation\RedirectResponse
+     */
+    public function reloadAction(Entry $entry)
+    {
+        $this->checkUserAction($entry);
+
+        $message = 'Entry reloaded';
+        if (false === $this->updateEntry($entry)) {
+            $message = 'Failed to reload entry';
+        }
+
+        $this->get('session')->getFlashBag()->add(
+            'notice',
+            $message
+        );
+
+        return $this->redirect($this->generateUrl('view', array('id' => $entry->getId())));
+    }
+
     /**
      * Changes read status for an entry.
      *
index b3f4709802e715af651853ab9c7aa4d60a12661a..7b7135e9a734a76e67b7d0e49e59932be2393e63 100644 (file)
@@ -7,6 +7,7 @@
         <ul class="links">
             <li class="topPosF"><a href="#top" title="{% trans %}Back to top{% endtrans %}" class="tool top icon icon-arrow-up-thick"><span>{% trans %}Back to top{% endtrans %}</span></a></li>
             <li><a href="{{ entry.url|e }}" target="_blank" title="{% trans %}original{% endtrans %} : {{ entry.title|e }}" class="tool link icon icon-link"><span>{{ entry.domainName|removeWww }}</span></a></li>
+            <li><a title="{% trans %}Reload content{% endtrans %}" href="{{ path('reload_entry', { 'id': entry.id }) }}"><span>{% trans %}Reload content{% endtrans %}</span></a></li>
             <li><a title="{% trans %}Mark as read{% endtrans %}" class="tool icon icon-check {% if entry.isArchived == 0 %}archive-off{% else %}archive{% endif %}" href="{{ path('archive_entry', { 'id': entry.id }) }}"><span>{% trans %}Toggle mark as read{% endtrans %}</span></a></li>
             <li><a title="{% trans %}Favorite{% endtrans %}" class="tool icon icon-star {% if entry.isStarred == 0 %}fav-off{% else %}fav{% endif %}" href="{{ path('star_entry', { 'id': entry.id }) }}"><span>{% trans %}Toggle favorite{% endtrans %}</span></a></li>
             <li><a title="{% trans %}Delete{% endtrans %}" class="tool delete icon icon-trash" href="{{ path('delete_entry', { 'id': entry.id }) }}"><span>{% trans %}Delete{% endtrans %}</span></a></li>
index fd84d984edb970d82b206c7f83d94ac633be1397..8140f360679e46c4353b031f7c9fe970ee78512f 100644 (file)
             <div class="collapsible-body"></div>
         </li>
 
+        <li class="bold hide-on-med-and-down">
+            <a class="waves-effect collapsible-header" title="{% trans %}Reload content{% endtrans %}" href="{{ path('reload_entry', { 'id': entry.id }) }}" id="reload">
+                <i class="mdi-action-autorenew small"></i>
+                <span>{% trans %}Reload content{% endtrans %}</span>
+            </a>
+            <div class="collapsible-body"></div>
+        </li>
+
         <li class="bold hide-on-med-and-down">
             <a class="waves-effect collapsible-header" title="{% trans %}Mark as read{% endtrans %}" href="{{ path('archive_entry', { 'id': entry.id }) }}" id="markAsRead">
                 <i class="{% if entry.isArchived == 0 %}mdi-action-done{% else %}mdi-content-redo{% endif %} small"></i>
index 9f585d85d722ecf13c89a5d6a287cccd9c0acbca..96f402b0973758cef2fe059bee46e2899d62381e 100644 (file)
@@ -180,6 +180,38 @@ class EntryControllerTest extends WallabagCoreTestCase
         $this->assertContains($content->getTitle(), $client->getResponse()->getContent());
     }
 
+    /**
+     * @depends testPostNewOk
+     *
+     * This test will require an internet connection.
+     */
+    public function testReload()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $content = $client->getContainer()
+            ->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findOneByUrl($this->url);
+
+        // empty content
+        $content->setContent('');
+        $client->getContainer()->get('doctrine.orm.entity_manager')->persist($content);
+        $client->getContainer()->get('doctrine.orm.entity_manager')->flush();
+
+        $client->request('GET', '/reload/'.$content->getId());
+
+        $this->assertEquals(302, $client->getResponse()->getStatusCode());
+
+        $content = $client->getContainer()
+            ->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findOneByUrl($this->url);
+
+        $this->assertNotEmpty($content->getContent());
+    }
+
     public function testEdit()
     {
         $this->logInAs('admin');