From aef0a140cabb6447008aaf854ec46fa997091450 Mon Sep 17 00:00:00 2001 From: soufiane Date: Wed, 12 Nov 2025 11:28:29 +0100 Subject: [PATCH] wip #7825 0:30 --- app/Jobs/AuditLink.php | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/app/Jobs/AuditLink.php b/app/Jobs/AuditLink.php index 18151be88..cdeaf2fde 100644 --- a/app/Jobs/AuditLink.php +++ b/app/Jobs/AuditLink.php @@ -31,7 +31,16 @@ class AuditLink extends Base foreach ($allLinks as $fb => $link) { // Error code start with 4 or 5 // Redirection code start with 3 - $curlResponse = FluidbookAuditLink::getHttpCode($link['url']); + try { + $curlResponse = FluidbookAuditLink::getHttpCode($link['url']); + }catch (\Error $e) { + echo "Error when trying to get http code: " . $e->getMessage().PHP_EOL; + continue; + }catch (\Exception $e) { + echo "Exception when trying to get http code: " . $e->getMessage() . PHP_EOL; + continue; + } + $httpCode = $curlResponse['httpcode']; $finalurl = ''; $finalcodeurl = ''; @@ -45,9 +54,17 @@ class AuditLink extends Base } } - if(str_starts_with($httpCode, 3)) { - $finalurl = $curlResponse['finalurl']; - $finalcodeurl = FluidbookAuditLink::getHttpCode($curlResponse['finalurl'])['httpcode']; + if (str_starts_with($httpCode, 3)) { + try { + $finalurl = $curlResponse['finalurl']; + $finalcodeurl = FluidbookAuditLink::getHttpCode($curlResponse['finalurl'])['httpcode']; + }catch (\Error $e) { + echo "Error when trying to get final url: " . $e->getMessage().PHP_EOL; + continue; + }catch (\Exception $e) { + echo "Exception when trying to get final url: " . $e->getMessage() . PHP_EOL; + continue; + } } $comment = FluidbookAuditLink::getHttpCodeComment($httpCode); @@ -69,9 +86,11 @@ class AuditLink extends Base ]; } - $keys = array_slice(array_keys($externalLinks[0]), 1); + if($externalLinks) { + $keys = array_slice(array_keys($externalLinks[0]), 1); - DB::table('fluidbook_audit_link')->upsert($externalLinks, ['id'], $keys); + DB::table('fluidbook_audit_link')->upsert($externalLinks, ['id'], $keys); + } Log::info('Job exécuté avec succès'); } -- 2.39.5