From 68410eeb340c7869a203881a2561a5a0dac2e80d Mon Sep 17 00:00:00 2001 From: Pierre Cadeot Date: Wed, 10 Mar 2021 17:07:11 +0400 Subject: [PATCH] api edispatcher/mxservices reponse correcte en cas d'erreur (fixes #31881) --- .../Controller/ApiController.php | 66 +++++++++---------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/src/ninegate-1.0/src/Cadoles/EdispatcherBundle/Controller/ApiController.php b/src/ninegate-1.0/src/Cadoles/EdispatcherBundle/Controller/ApiController.php index feab9931..43cf90cd 100755 --- a/src/ninegate-1.0/src/Cadoles/EdispatcherBundle/Controller/ApiController.php +++ b/src/ninegate-1.0/src/Cadoles/EdispatcherBundle/Controller/ApiController.php @@ -779,9 +779,9 @@ $api('$id',data);"; $debug = ob_get_clean(); //$debug=json_encode($request->query); + //return new Response(json_encode($output), 400); if(is_null($token)||is_null($libelle)||is_null($icon)||is_null($favurl)||is_null($nom)||is_null($categorie)||is_null($callback)||is_null($action)||is_null($callbackid)){ $output["error"]="missing parameter : token - id - libelle - icon - favurl - nom - categorie - callback - action - callbackid"; - return new Response(json_encode($output), 400); } $em = $this->getDoctrine()->getManager(); @@ -789,15 +789,13 @@ $api('$id',data);"; $datasource = $em->getRepository('CadolesEdispatcherBundle:Datasource')->findOneBy(["token"=>$token]); if (!$datasource) { $output["error"]="no datasource session found for token = $token"; - return new Response(json_encode($output), 400); } $login = $datasource->getUsername(); // Récupérer l'utilisateur $user=$em->getRepository('CadolesCoreBundle:User')->findOneBy(["username"=>$login]); if(!$user) { - $output["error"]="user not exist"; - return new Response(json_encode($output), 400); + $output["error"]="user does not exist"; } // chercher l'item @@ -805,7 +803,7 @@ $api('$id',data);"; if(!$item) { $altitem=$em->getRepository('CadolesPortalBundle:Item')->findOneBy(["url"=>$favurl."?gestion_edispatcher=locale"]); if(!$altitem) { - $output["error"]="item with url=$favurl(?gestion_edispatcher=locale) not exist"; + $output["error"]="item with url=$favurl(?gestion_edispatcher=locale) not found"; return new Response(json_encode($output), 400); } else { $item = $altitem; @@ -814,11 +812,16 @@ $api('$id',data);"; $bookmark = $em->getRepository('CadolesPortalBundle:Bookmark')->findOneBy(["user"=>$user,"item"=>$item]); $title=""; - $subtitle=""; - $output=""; - if(!$bookmark) { - if ($action=="BOOKMARK_ADD") { + $subtitle=""; + $message=""; + if (isset($output["error"]) { + $message=$output["error"]; + $success=0; + } else { + $output=""; + if(!$bookmark) { + if ($action=="BOOKMARK_ADD") { $bookmark = new Bookmark(); $bookmark->setTitle($item->getTitle()); $title=$item->getTitle(); @@ -832,34 +835,30 @@ $api('$id',data);"; $bookmark->setUser($user); $em->persist($bookmark); $em->flush(); - $success=1; - $output=" -
- - - - - -
- - -"; - - - } else $success=0; // item pas en favori, mais ce n'est pas une demande d'ajout - } else { - if ($action=="BOOKMARK_DEL") { - + $success=1; + $message="$title : $subtitle a été ajouté à vos favoris"; + } else { + $success=0; + $message="item introuvable en favori mais action=DEL (retrait)"; + } + } else { + if ($action=="BOOKMARK_DEL") { $em->remove($bookmark); $em->flush(); - $success=1; + $success=1; + $message="item supprimé de vos favoris"; + } else { + $success=0; + $message="item deja en favori mais action=ADD (ajout)"; + } + } + } + $output="
- - + +
@@ -869,8 +868,7 @@ document.form2submit.submit(); "; - } else $success=0; // item deja en favori mais demande d'ajout - } + $reponse = new Response(); $reponse->setContent($output);