From abf83361e89154856d53104941bb75672cb2aace Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 3 Jun 2016 17:07:36 +0100 Subject: [PATCH 1/2] Fixed the integrations --- .../Dashboard/DashboardController.php | 2 +- app/Integrations/Credits.php | 24 +++++++++++++++---- app/Integrations/Feed.php | 19 +++++++++++---- app/Integrations/Releases.php | 7 ++++++ 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/Dashboard/DashboardController.php b/app/Http/Controllers/Dashboard/DashboardController.php index ca3fdb52..1f7292c2 100644 --- a/app/Http/Controllers/Dashboard/DashboardController.php +++ b/app/Http/Controllers/Dashboard/DashboardController.php @@ -69,7 +69,7 @@ class DashboardController extends Controller $subscribers = $this->getSubscribers(); $entries = null; - if ($feed = $this->feed->entries()) { + if ($feed = $this->feed->latest()) { $entries = array_slice($feed->channel->item, 0, 5); } diff --git a/app/Integrations/Credits.php b/app/Integrations/Credits.php index 3056af07..2050fc1f 100644 --- a/app/Integrations/Credits.php +++ b/app/Integrations/Credits.php @@ -11,6 +11,7 @@ namespace CachetHQ\Cachet\Integrations; +use Exception; use GuzzleHttp\Client; use Illuminate\Contracts\Cache\Repository; @@ -23,6 +24,13 @@ class Credits */ const URL = 'https://cachethq.io/credits'; + /** + * The failed status indicator. + * + * @var int + */ + const FAILED = 1; + /** * The cache repository instance. * @@ -54,14 +62,20 @@ class Credits /** * Returns the latest credits. * - * @return array + * @return array|null */ public function latest() { - return $this->cache->remember('credits', 2880, function () { - return json_decode((new Client())->get($this->url, [ - 'headers' => ['Accept' => 'application/json', 'User-Agent' => defined('CACHET_VERSION') ? 'cachet/'.constant('CACHET_VERSION') : 'cachet'], - ])->getBody(), true); + $result = $this->cache->remember('credits', 2880, function () { + try { + return json_decode((new Client())->get($this->url, [ + 'headers' => ['Accept' => 'application/json', 'User-Agent' => defined('CACHET_VERSION') ? 'cachet/'.constant('CACHET_VERSION') : 'cachet'], + ])->getBody(), true); + catch (Exception $e) { + return self::FAILED; + } }); + + return $result === self::FAILED ? null : $result; } } diff --git a/app/Integrations/Feed.php b/app/Integrations/Feed.php index ee09ddd1..033839b2 100644 --- a/app/Integrations/Feed.php +++ b/app/Integrations/Feed.php @@ -29,6 +29,13 @@ class Feed */ const URL = 'https://blog.alt-three.com/tag/cachet/rss'; + /** + * The failed status indicator. + * + * @var int + */ + const FAILED = 1; + /** * The cache repository instance. * @@ -58,13 +65,13 @@ class Feed } /** - * Returns the entries. + * Returns the latest entries. * - * @return array + * @return array|null */ - public function entries() + public function latest() { - return $this->cache->remember('feeds', 720, function () { + $result = $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'], @@ -72,8 +79,10 @@ class Feed return json_decode(json_encode($xml)); } catch (Exception $e) { - // Do nothing, this isn't critical. + return self::FAILED; } }); + + return $result === self::FAILED ? null : $result; } } diff --git a/app/Integrations/Releases.php b/app/Integrations/Releases.php index 1c0ff64f..65cb67b7 100644 --- a/app/Integrations/Releases.php +++ b/app/Integrations/Releases.php @@ -23,6 +23,13 @@ class Releases */ const URL = 'https://api.github.com/repos/cachethq/cachet/releases/latest'; + /** + * The failed status indicator. + * + * @var int + */ + const FAILED = 1; + /** * The cache repository instance. * From 31861f020f3a8ac3f3c76ebc4fa7f13539bb9a09 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 3 Jun 2016 17:10:24 +0100 Subject: [PATCH 2/2] Fixed typo --- app/Integrations/Credits.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Integrations/Credits.php b/app/Integrations/Credits.php index 2050fc1f..a82105cc 100644 --- a/app/Integrations/Credits.php +++ b/app/Integrations/Credits.php @@ -71,7 +71,7 @@ class Credits return json_decode((new Client())->get($this->url, [ 'headers' => ['Accept' => 'application/json', 'User-Agent' => defined('CACHET_VERSION') ? 'cachet/'.constant('CACHET_VERSION') : 'cachet'], ])->getBody(), true); - catch (Exception $e) { + } catch (Exception $e) { return self::FAILED; } });