api edispatcher/mxservices reponse correcte en cas d'erreur (fixes #31881)

This commit is contained in:
Pierre Cadeot 2021-03-10 17:07:11 +04:00
parent 224cc87e77
commit 68410eeb34
1 changed files with 32 additions and 34 deletions

View File

@ -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="<html><body>
<form id='form2submit' name='form2submit' method='POST' action='$callback'>
<input name='action' id='action' type='hidden' value='$action' />
<input name='message' id='message' type='hidden' value='$title : $subtitle a &eacute;t&eacute; ajout&eacute; &agrave; vos favoris' />
<input name='success' id='success' type='hidden' value='1' />
<input name='id' id='id' type='hidden' value='$id' />
<input name='callbackid' id='callbackid' type='hidden' value='$callbackid' />
</form>
<script>
document.form2submit.submit();
</script>
</body></html>
";
} 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 &eacute;t&eacute; ajout&eacute; &agrave; 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="<html><body>
<form id='form2submit' name='form2submit' method='POST' action='$callback'>
<input name='action' id='action' type='hidden' value='$action' />
<input name='message' id='message' type='hidden' value='item supprimé de vos favoris' />
<input name='success' id='success' type='hidden' value='1' />
<input name='message' id='message' type='hidden' value='$message' />
<input name='success' id='success' type='hidden' value='$success' />
<input name='id' id='id' type='hidden' value='$id' />
<input name='callbackid' id='callbackid' type='hidden' value='$callbackid' />
</form>
@ -869,8 +868,7 @@ document.form2submit.submit();
</body></html>
";
} else $success=0; // item deja en favori mais demande d'ajout
}
$reponse = new Response();
$reponse->setContent($output);