Ability to reload an entry

Could be useful when we want to update the content or when the content failed to be fetched.

Fix #1503
This commit is contained in:
Jeremy Benoist 2015-12-30 09:41:17 +01:00
parent e6a228c43b
commit 831b02aaf2
4 changed files with 68 additions and 0 deletions

View 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.
*

View 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>

View file

@ -51,6 +51,14 @@
<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>

View 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');