From 1f67e854bb9aa1273be541b5f8604be33ec513cd Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sun, 28 Jan 2018 16:57:15 -0800 Subject: [PATCH] don't run web hooks for manually created trips --- compass/app/Jobs/TripComplete.php | 59 ++++++++++++++++--------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/compass/app/Jobs/TripComplete.php b/compass/app/Jobs/TripComplete.php index 005958a..210db0d 100644 --- a/compass/app/Jobs/TripComplete.php +++ b/compass/app/Jobs/TripComplete.php @@ -34,34 +34,37 @@ class TripComplete extends Job implements SelfHandling, ShouldQueue ////////////////////////////////// // Web Hooks - $urls = preg_split('/\s+/', $db->ping_urls); - - // Build a trip object that looks like the active trip format from Overland - $trip = [ - 'trip' => [ - 'mode' => $this->_data['properties']['mode'], - 'start_location' => $this->_data['properties']['start_location'], - 'end_location' => $this->_data['properties']['end_location'], - 'distance' => $this->_data['properties']['distance'], - 'start' => $this->_data['properties']['start'], - 'end' => $this->_data['properties']['end'] - ] - ]; - $trip = json_encode($trip, JSON_UNESCAPED_SLASHES); - - foreach($urls as $url) { - if(trim($url)) { - $ch = curl_init($url); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, [ - 'Content-Type: application/json', - 'Authorization: Bearer '.$db->read_token, - 'Compass-Url: '.env('BASE_URL').'api/trip?token='.$db->read_token - ]); - curl_setopt($ch, CURLOPT_POSTFIELDS, $trip); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_exec($ch); - Log::info("Notifying ".$url." of a completed trip"); + // Don't run the web hooks for manually created trips + if(isset($this->_data['properties']['end_location'])) { + $urls = preg_split('/\s+/', $db->ping_urls); + + // Build a trip object that looks like the active trip format from Overland + $trip = [ + 'trip' => [ + 'mode' => $this->_data['properties']['mode'], + 'start_location' => $this->_data['properties']['start_location'], + 'end_location' => $this->_data['properties']['end_location'], + 'distance' => $this->_data['properties']['distance'], + 'start' => $this->_data['properties']['start'], + 'end' => $this->_data['properties']['end'] + ] + ]; + $trip = json_encode($trip, JSON_UNESCAPED_SLASHES); + + foreach($urls as $url) { + if(trim($url)) { + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'Content-Type: application/json', + 'Authorization: Bearer '.$db->read_token, + 'Compass-Url: '.env('BASE_URL').'api/trip?token='.$db->read_token + ]); + curl_setopt($ch, CURLOPT_POSTFIELDS, $trip); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_exec($ch); + Log::info("Notifying ".$url." of a completed trip"); + } } }