api edispatcher/mxservices reponse correcte en cas d'erreur (fixes #31881)
This commit is contained in:
parent
224cc87e77
commit
68410eeb34
|
@ -779,9 +779,9 @@ $api('$id',data);";
|
||||||
$debug = ob_get_clean();
|
$debug = ob_get_clean();
|
||||||
//$debug=json_encode($request->query);
|
//$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)){
|
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";
|
$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();
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
@ -789,15 +789,13 @@ $api('$id',data);";
|
||||||
$datasource = $em->getRepository('CadolesEdispatcherBundle:Datasource')->findOneBy(["token"=>$token]);
|
$datasource = $em->getRepository('CadolesEdispatcherBundle:Datasource')->findOneBy(["token"=>$token]);
|
||||||
if (!$datasource) {
|
if (!$datasource) {
|
||||||
$output["error"]="no datasource session found for token = $token";
|
$output["error"]="no datasource session found for token = $token";
|
||||||
return new Response(json_encode($output), 400);
|
|
||||||
}
|
}
|
||||||
$login = $datasource->getUsername();
|
$login = $datasource->getUsername();
|
||||||
|
|
||||||
// Récupérer l'utilisateur
|
// Récupérer l'utilisateur
|
||||||
$user=$em->getRepository('CadolesCoreBundle:User')->findOneBy(["username"=>$login]);
|
$user=$em->getRepository('CadolesCoreBundle:User')->findOneBy(["username"=>$login]);
|
||||||
if(!$user) {
|
if(!$user) {
|
||||||
$output["error"]="user not exist";
|
$output["error"]="user does not exist";
|
||||||
return new Response(json_encode($output), 400);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// chercher l'item
|
// chercher l'item
|
||||||
|
@ -805,7 +803,7 @@ $api('$id',data);";
|
||||||
if(!$item) {
|
if(!$item) {
|
||||||
$altitem=$em->getRepository('CadolesPortalBundle:Item')->findOneBy(["url"=>$favurl."?gestion_edispatcher=locale"]);
|
$altitem=$em->getRepository('CadolesPortalBundle:Item')->findOneBy(["url"=>$favurl."?gestion_edispatcher=locale"]);
|
||||||
if(!$altitem) {
|
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);
|
return new Response(json_encode($output), 400);
|
||||||
} else {
|
} else {
|
||||||
$item = $altitem;
|
$item = $altitem;
|
||||||
|
@ -814,11 +812,16 @@ $api('$id',data);";
|
||||||
|
|
||||||
$bookmark = $em->getRepository('CadolesPortalBundle:Bookmark')->findOneBy(["user"=>$user,"item"=>$item]);
|
$bookmark = $em->getRepository('CadolesPortalBundle:Bookmark')->findOneBy(["user"=>$user,"item"=>$item]);
|
||||||
$title="";
|
$title="";
|
||||||
$subtitle="";
|
$subtitle="";
|
||||||
$output="";
|
$message="";
|
||||||
if(!$bookmark) {
|
|
||||||
if ($action=="BOOKMARK_ADD") {
|
|
||||||
|
|
||||||
|
if (isset($output["error"]) {
|
||||||
|
$message=$output["error"];
|
||||||
|
$success=0;
|
||||||
|
} else {
|
||||||
|
$output="";
|
||||||
|
if(!$bookmark) {
|
||||||
|
if ($action=="BOOKMARK_ADD") {
|
||||||
$bookmark = new Bookmark();
|
$bookmark = new Bookmark();
|
||||||
$bookmark->setTitle($item->getTitle());
|
$bookmark->setTitle($item->getTitle());
|
||||||
$title=$item->getTitle();
|
$title=$item->getTitle();
|
||||||
|
@ -832,34 +835,30 @@ $api('$id',data);";
|
||||||
$bookmark->setUser($user);
|
$bookmark->setUser($user);
|
||||||
$em->persist($bookmark);
|
$em->persist($bookmark);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
$success=1;
|
$success=1;
|
||||||
$output="<html><body>
|
$message="$title : $subtitle a été ajouté à vos favoris";
|
||||||
<form id='form2submit' name='form2submit' method='POST' action='$callback'>
|
} else {
|
||||||
<input name='action' id='action' type='hidden' value='$action' />
|
$success=0;
|
||||||
<input name='message' id='message' type='hidden' value='$title : $subtitle a été ajouté à vos favoris' />
|
$message="item introuvable en favori mais action=DEL (retrait)";
|
||||||
<input name='success' id='success' type='hidden' value='1' />
|
}
|
||||||
<input name='id' id='id' type='hidden' value='$id' />
|
} else {
|
||||||
<input name='callbackid' id='callbackid' type='hidden' value='$callbackid' />
|
if ($action=="BOOKMARK_DEL") {
|
||||||
</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") {
|
|
||||||
|
|
||||||
$em->remove($bookmark);
|
$em->remove($bookmark);
|
||||||
$em->flush();
|
$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>
|
$output="<html><body>
|
||||||
<form id='form2submit' name='form2submit' method='POST' action='$callback'>
|
<form id='form2submit' name='form2submit' method='POST' action='$callback'>
|
||||||
<input name='action' id='action' type='hidden' value='$action' />
|
<input name='action' id='action' type='hidden' value='$action' />
|
||||||
<input name='message' id='message' type='hidden' value='item supprimé de vos favoris' />
|
<input name='message' id='message' type='hidden' value='$message' />
|
||||||
<input name='success' id='success' type='hidden' value='1' />
|
<input name='success' id='success' type='hidden' value='$success' />
|
||||||
<input name='id' id='id' type='hidden' value='$id' />
|
<input name='id' id='id' type='hidden' value='$id' />
|
||||||
<input name='callbackid' id='callbackid' type='hidden' value='$callbackid' />
|
<input name='callbackid' id='callbackid' type='hidden' value='$callbackid' />
|
||||||
</form>
|
</form>
|
||||||
|
@ -869,8 +868,7 @@ document.form2submit.submit();
|
||||||
</body></html>
|
</body></html>
|
||||||
";
|
";
|
||||||
|
|
||||||
} else $success=0; // item deja en favori mais demande d'ajout
|
|
||||||
}
|
|
||||||
|
|
||||||
$reponse = new Response();
|
$reponse = new Response();
|
||||||
$reponse->setContent($output);
|
$reponse->setContent($output);
|
||||||
|
|
Loading…
Reference in New Issue