diff --git a/app/Services/RunIndicatorAnalysisService.php b/app/Services/RunIndicatorAnalysisService.php index a8a60125..19608be1 100644 --- a/app/Services/RunIndicatorAnalysisService.php +++ b/app/Services/RunIndicatorAnalysisService.php @@ -141,16 +141,16 @@ public function sendApiRequestIndicator($secret_key, $query_url, $query_sql, $ge 'sql' => $query_sql, 'geometry' => $geometry, ]); - + if ($response->successful()) { $gfwDataFile = tempnam(sys_get_temp_dir(), 'gfw_') . '.json'; $geometryFile = tempnam(sys_get_temp_dir(), 'geom_') . '.json'; $outputFile = tempnam(sys_get_temp_dir(), 'output_') . '.json'; - + try { file_put_contents($gfwDataFile, json_encode($response->json())); file_put_contents($geometryFile, json_encode($geometry)); - + $process = new Process([ 'python3', base_path() . '/resources/python/gfw-area-adjustment/app.py', @@ -158,14 +158,15 @@ public function sendApiRequestIndicator($secret_key, $query_url, $query_sql, $ge $geometryFile, $outputFile, ]); - + $process->run(); - - if (!$process->isSuccessful()) { + + if (! $process->isSuccessful()) { Log::error('Area adjustment failed: ' . $process->getErrorOutput()); + return $response; } - + $adjustedData = json_decode(file_get_contents($outputFile), true); return new \Illuminate\Http\Client\Response( @@ -175,9 +176,10 @@ public function sendApiRequestIndicator($secret_key, $query_url, $query_sql, $ge json_encode($adjustedData) ) ); - + } catch (\Exception $e) { Log::error('Error adjusting areas: ' . $e->getMessage()); + return $response; } finally { @unlink($gfwDataFile); @@ -185,7 +187,7 @@ public function sendApiRequestIndicator($secret_key, $query_url, $query_sql, $ge @unlink($outputFile); } } - + return $response; }