From 99f3c372a9487e1df4bf6cee9edeede98900e301 Mon Sep 17 00:00:00 2001 From: Ninassi Benjamin <benjamin.ninassi@inria.fr> Date: Thu, 27 Sep 2018 18:08:45 +0200 Subject: [PATCH] improvement of failed logo detection --- .../Command/VerifyStructuresLogoCommand.php | 22 +++++++++++++++---- .../Controller/StructureController.php | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/ClassCodeBundle/Command/VerifyStructuresLogoCommand.php b/src/ClassCodeBundle/Command/VerifyStructuresLogoCommand.php index ab4aba2..4788cec 100644 --- a/src/ClassCodeBundle/Command/VerifyStructuresLogoCommand.php +++ b/src/ClassCodeBundle/Command/VerifyStructuresLogoCommand.php @@ -50,10 +50,9 @@ class VerifyStructuresLogoCommand extends ContainerAwareCommand foreach ($structures as $structure) { $logo = $structure->getLogo(); if($logo){ - $file_headers = @get_headers($logo); - if(!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') { - $logo_error_tab[]="Le logo ".$logo." n'existe pas (file not found) pour la structure <b>".$structure->getName()."</b>"; - $exists = false; + $exists = $this->is_url_exist($logo); + if(!$exists){ + $logo_error_tab[]="Le logo ".$logo." n'existe pas (file not found) pour la structure <b>".$structure->getName()."</b>"; } }else{ $logo_error_tab[]="Pas de logo défini pour la structure <b>".$structure->getName()."</b>"; @@ -99,6 +98,21 @@ class VerifyStructuresLogoCommand extends ContainerAwareCommand $mailer = $container->get('mailer'); $mailer->send($message); } + + private function is_url_exist($url){ + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_NOBODY, true); + curl_exec($ch); + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + if($code == 200){ + $status = true; + }else{ + $status = false; + } + curl_close($ch); + return $status; + } } \ No newline at end of file diff --git a/src/ClassCodeBundle/Controller/StructureController.php b/src/ClassCodeBundle/Controller/StructureController.php index 7621ccf..27402c0 100644 --- a/src/ClassCodeBundle/Controller/StructureController.php +++ b/src/ClassCodeBundle/Controller/StructureController.php @@ -179,7 +179,7 @@ class StructureController extends Controller $structuresLogos = array(); foreach ($structures as $structure) { $logo = $structure->getLogo(); - if($logo && !in_array ($logo,$structuresLogos)){ + if($logo && !in_array($logo,$structuresLogos)){ $structuresLogos[] = $logo; } } -- GitLab