# HG changeset patch # User cavaliet # Date 1320925222 -3600 # Node ID 38dcd2db04e4016fb6c741a7f225248369cb240c # Parent b910b4f7485fe9cc9c3663d4f7236f315c256be2 Debug case sentive tag modification. diff -r b910b4f7485f -r 38dcd2db04e4 Controller/WikiTagController.php --- a/Controller/WikiTagController.php Wed Nov 09 17:33:26 2011 +0100 +++ b/Controller/WikiTagController.php Thu Nov 10 12:40:22 2011 +0100 @@ -151,7 +151,7 @@ $i = 0; while($i<$nb_tags && $found==false){ $dt = $tags[$i]; - if(strtolower($dt->getTag()->getLabel())==strtolower($tag_label)){ + if($dt->getTag()->getLabel()==$tag_label){ $found = true; } $i++; @@ -161,7 +161,7 @@ return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400); } // We create the new tag or get the already existing tag. $tag, $revision_id, $created - $ar = WikiTagUtils::getOrCreateTag($tag_label, $this->getDoctrine());// tag, revision_id, created = get_or_create_tag(tag_label) + $ar = WikiTagUtils::getOrCreateTag($tag_label, $this->getDoctrine()); $tag = $ar[0]; $revision_id = $ar[1]; $created = $ar[2]; @@ -182,9 +182,9 @@ $doc->setManualOrder(true); // We save the datas $em->flush(); - // We render the document's tags - return $this->renderDocTags($id_doc); } + // We render the document's tags + return $this->renderDocTags($id_doc); } diff -r b910b4f7485f -r 38dcd2db04e4 Utils/WikiTagUtils.php --- a/Utils/WikiTagUtils.php Wed Nov 09 17:33:26 2011 +0100 +++ b/Utils/WikiTagUtils.php Thu Nov 10 12:40:22 2011 +0100 @@ -38,6 +38,7 @@ } } } + $wp_request_done = false; if($tag==null){ $tag = new Tag(); $tag->setLabel($tag_label_normalized); @@ -47,11 +48,35 @@ } else{ $created = false; + $match_exists = false; + // Even if a tag with the normalised label exists, IF this tag is not wikipedia semantised, + // we search if a wikipedia semantised version exists in the base + foreach ($tags as $t){ + if($t->getUrlStatus()==Tag::$TAG_URL_STATUS_DICT['match']){ + $tag = $t; + $match_exists = true; + break; + } + } + if($match_exists==false){ + $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized); + $status = $wp_response['status']; + if($status==Tag::$TAG_URL_STATUS_DICT['match']){ + $tag = new Tag(); + $tag->setLabel($tag_label_normalized); + $tag->setOriginalLabel($tag_label); + $tag->setNormalizedLabel($tag_label_normalized); + $created = true; + $wp_request_done = true; + } + } } // We request Wikipedia if the tag is created if($created==true){ - $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized); + if($wp_request_done==false){ + $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized); + } $new_label = $wp_response['new_label']; $status = $wp_response['status']; $url = $wp_response['wikipedia_url']; @@ -83,7 +108,6 @@ else{ $wikipedia_revision_id = null; } - //return "coucou4"; return array($tag, $wikipedia_revision_id, $created);//, $wpReponse); }