Controller/WikiTagController.php
changeset 67 989d9e117586
parent 65 ba6b8e38d90e
child 68 e7384fb35f7a
equal deleted inserted replaced
66:868d0fcdbb99 67:989d9e117586
   199             if($found==true){
   199             if($found==true){
   200                 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400);
   200                 return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400);
   201             }
   201             }
   202             // We create the new tag or get the already existing tag. $tag, $revision_id, $created
   202             // We create the new tag or get the already existing tag. $tag, $revision_id, $created
   203             try {
   203             try {
   204                 $ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label);
   204                 $ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label, $this->container->getParameter('wiki_tag.ignore_wikipedia_error'));
   205             }
   205             }
   206             catch (\Exception $e){
   206             catch (\Exception $e){
   207                 return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400);
   207                 return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400);
   208             }
   208             }
   209             $tag = $ar[0];
   209             $tag = $ar[0];
   561     private function updateTagWithNewLabel($tag, $label)
   561     private function updateTagWithNewLabel($tag, $label)
   562     {
   562     {
   563         if($tag!=null && $label!=null){
   563         if($tag!=null && $label!=null){
   564             // We get the Wikipedia informations for the sent label
   564             // We get the Wikipedia informations for the sent label
   565             $tag_label_normalized = WikiTagUtils::normalizeTag($label);
   565             $tag_label_normalized = WikiTagUtils::normalizeTag($label);
   566             $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
   566             $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized, null, $this->container->getParameter('wiki_tag.ignore_wikipedia_error'));
   567             $tag->setWikipediaInfo($wp_response);
   567             $tag->setWikipediaInfo($wp_response);
   568             // Save datas.
   568             // Save datas.
   569             $em = $this->getDoctrine()->getEntityManager();
   569             $em = $this->getDoctrine()->getEntityManager();
   570             $em->persist($tag);
   570             $em->persist($tag);
   571             $em->flush();
   571             $em->flush();