Handle failing to fetch blog posts. Fixes #1878

This commit is contained in:
James Brooks
2016-06-03 14:00:23 +01:00
parent 715eb02844
commit c8b602d349
3 changed files with 17 additions and 8 deletions

View File

@@ -67,9 +67,11 @@ class DashboardController extends Controller
$components = Component::orderBy('order')->get();
$incidents = $this->getIncidents();
$subscribers = $this->getSubscribers();
$feed = $this->feed->entries();
$entries = array_slice($feed->channel->item, 0, 5);
$entries = null;
if ($feed = $this->feed->entries()) {
$entries = array_slice($feed->channel->item, 0, 5);
}
return View::make('dashboard.index')
->withPageTitle(trans('dashboard.dashboard'))

View File

@@ -12,6 +12,7 @@
namespace CachetHQ\Cachet\Integrations;
use GuzzleHttp\Client;
use Exception;
use Illuminate\Contracts\Cache\Repository;
/**
@@ -63,12 +64,16 @@ class Feed
*/
public function entries()
{
return $this->cache->remember('feeds', 2880, function () {
$xml = simplexml_load_string((new Client())->get($this->url, [
'headers' => ['Accept' => 'application/rss+xml', 'User-Agent' => defined('CACHET_VERSION') ? 'cachet/'.constant('CACHET_VERSION') : 'cachet'],
])->getBody()->getContents(), null, LIBXML_NOCDATA);
return $this->cache->remember('feeds', 720, function () {
try {
$xml = simplexml_load_string((new Client())->get($this->url, [
'headers' => ['Accept' => 'application/rss+xml', 'User-Agent' => defined('CACHET_VERSION') ? 'cachet/'.constant('CACHET_VERSION') : 'cachet'],
])->getBody()->getContents(), null, LIBXML_NOCDATA);
return json_decode(json_encode($xml));
return json_decode(json_encode($xml));
} catch (Exception $e) {
// Do nothing, this isn't critical.
}
});
}
}

View File

@@ -85,6 +85,7 @@
</div>
</div>
@if($entries)
<div class="col-sm-12 col-lg-6">
<div class="stats-widget">
<div class='stats-top'>
@@ -94,12 +95,13 @@
<div class='stats-body'>
<div class="list-group">
@foreach($entries as $entry)
<a class="list-group-item" href="{{ $entry->link }}" target="_blank">{{ $entry->title }}, <small>{{ $entry->pubDate }}</small></a>
<a class="list-group-item" href="{{ $entry->link }}" target="_blank">{{ $entry->title }}, <small>{{ $entry->pubDate }}</small> <span class="badge"><i class="ion-android-open"></i></span></a>
@endforeach
</div>
</div>
</div>
</div>
@endif
</div>
</div>
@if(Session::get('setup.done'))