From 72312ab8fb642ab7b35235744639c2d681235f4e Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Sun, 5 Mar 2017 09:46:28 -0500 Subject: [PATCH 1/3] Handle and cache meetup API failures --- php-classes/RemoteSystems/Meetup.php | 17 ++++++++++-- site-root/home.php | 41 ++++++++++++++++------------ 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/php-classes/RemoteSystems/Meetup.php b/php-classes/RemoteSystems/Meetup.php index 834ef3f1..81441f51 100644 --- a/php-classes/RemoteSystems/Meetup.php +++ b/php-classes/RemoteSystems/Meetup.php @@ -3,12 +3,14 @@ namespace RemoteSystems; use Cache; +use Exception; class Meetup { public static $groupUrl; public static $signedEventsUrl; - public static $defaultCacheTime = 1800; + public static $defaultCacheTime = 600; + public static $failureCacheTime = 60; public static $eventsFilter; public static function getEventUrl($meetupID) @@ -31,9 +33,18 @@ public static function getEvents($ttl = null) } $cacheKey = 'meetup/events'; + $data = Cache::fetch($cacheKey); - if (!$data = Cache::fetch($cacheKey)) { - $data = json_decode(file_get_contents(static::$signedEventsUrl), true); + if ($data === null) { + // cached failure + throw new Exception('Meetup API unavailable'); + } elseif ($data === false) { + $data = @json_decode(@file_get_contents(static::$signedEventsUrl), true); + + if (!$data) { + Cache::store($cacheKey, null, static::$failureCacheTime); + throw new Exception('Meetup API unavailable'); + } if (static::$eventsFilter) { if (is_string(static::$eventsFilter)) { diff --git a/site-root/home.php b/site-root/home.php index 8b2e8f53..88a77e10 100644 --- a/site-root/home.php +++ b/site-root/home.php @@ -6,28 +6,33 @@ // meetups - $meetups = RemoteSystems\Meetup::getEvents(); - $nextMeetup = array_shift($meetups); + try { + $meetups = RemoteSystems\Meetup::getEvents(); - // detect if meetup is happening right now - if($nextMeetup && $nextMeetup['time'] < $now) { - $currentMeetup = $nextMeetup; $nextMeetup = array_shift($meetups); + + // detect if meetup is happening right now + if($nextMeetup && $nextMeetup['time'] < $now) { + $currentMeetup = $nextMeetup; + $nextMeetup = array_shift($meetups); + } + + // TODO: delete this! + elseif(!empty($_GET['force_current'])) { + $currentMeetup = $nextMeetup; + } + + if($currentMeetup) { + $currentMeetup['checkins'] = Laddr\MemberCheckin::getAllForMeetupByProject($currentMeetup['id']); + } + + $pageData['currentMeetup'] = $currentMeetup; + $pageData['nextMeetup'] = $nextMeetup; + $pageData['futureMeetups'] = $meetups; + } catch (Exception $e) { + // just omit meetup data } - // TODO: delete this! - elseif(!empty($_GET['force_current'])) { - $currentMeetup = $nextMeetup; - } - - if($currentMeetup) { - $currentMeetup['checkins'] = Laddr\MemberCheckin::getAllForMeetupByProject($currentMeetup['id']); - } - - $pageData['currentMeetup'] = $currentMeetup; - $pageData['nextMeetup'] = $nextMeetup; - $pageData['futureMeetups'] = $meetups; - // projects $pageData['projectsTotal'] = Laddr\Project::getCount(); From 7d9bc95ab8d69f9302d8852059e515468f3df131 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Sun, 5 Mar 2017 09:54:09 -0500 Subject: [PATCH 2/3] Remove no longer used projects/members data from home page --- site-root/home.php | 53 ---------------------------------------------- 1 file changed, 53 deletions(-) diff --git a/site-root/home.php b/site-root/home.php index 88a77e10..41597874 100644 --- a/site-root/home.php +++ b/site-root/home.php @@ -34,59 +34,6 @@ } -// projects - $pageData['projectsTotal'] = Laddr\Project::getCount(); - $pageData['projectsTags']['byTech'] = TagItem::getTagsSummary(array( - 'tagConditions' => array( - 'Handle LIKE "tech.%"' - ) - ,'itemConditions' => array( - 'ContextClass' => Laddr\Project::getStaticRootClass() - ) - ,'limit' => 10 - )); - $pageData['projectsTags']['byTopic'] = TagItem::getTagsSummary(array( - 'tagConditions' => array( - 'Handle LIKE "topic.%"' - ) - ,'itemConditions' => array( - 'ContextClass' => Laddr\Project::getStaticRootClass() - ) - ,'limit' => 10 - )); - $pageData['projectsTags']['byEvent'] = TagItem::getTagsSummary(array( - 'tagConditions' => array( - 'Handle LIKE "event.%"' - ) - ,'itemConditions' => array( - 'ContextClass' => Laddr\Project::getStaticRootClass() - ) - )); - $pageData['projectsStages'] = Laddr\Project::getStagesSummary(); - - -// members - $pageData['membersTotal'] = Emergence\People\Person::getCount(); - $pageData['membersTags']['byTech'] = TagItem::getTagsSummary(array( - 'tagConditions' => array( - 'Handle LIKE "tech.%"' - ) - ,'itemConditions' => array( - 'ContextClass' => Emergence\People\Person::getStaticRootClass() - ) - ,'limit' => 10 - )); - $pageData['membersTags']['byTopic'] = TagItem::getTagsSummary(array( - 'tagConditions' => array( - 'Handle LIKE "topic.%"' - ) - ,'itemConditions' => array( - 'ContextClass' => Emergence\People\Person::getStaticRootClass() - ) - ,'limit' => 10 - )); - - // build activity stream if (!$pageData['activity'] = Cache::fetch('home-activity')) { $existingTables = \DB::allValues('table_name', 'SELECT table_name FROM information_schema.TABLES WHERE TABLE_SCHEMA = SCHEMA()'); From 307e6c434a9a64738d07dc9b8255d90349c31bd7 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Sun, 5 Mar 2017 09:54:34 -0500 Subject: [PATCH 3/3] Restructure default navigation menu --- .../includes/site.nav-sitelinks.tpl | 49 ++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/html-templates/includes/site.nav-sitelinks.tpl b/html-templates/includes/site.nav-sitelinks.tpl index b40c1a4b..ec56c593 100644 --- a/html-templates/includes/site.nav-sitelinks.tpl +++ b/html-templates/includes/site.nav-sitelinks.tpl @@ -1,6 +1,43 @@ -
  • {_ "Projects"}
  • -
  • {_ "Members"}
  • -
  • {_ "Mission"}
  • -
  • {_ "How to Help"}
  • -
  • Discuss
  • -
  • {_ "Resources"}
  • \ No newline at end of file + + + + + + + + + \ No newline at end of file