Debug case sentive tag modification.
authorcavaliet
Thu, 10 Nov 2011 12:40:22 +0100
changeset 32 38dcd2db04e4
parent 31 b910b4f7485f
child 33 6c87166b819c
Debug case sentive tag modification.
Controller/WikiTagController.php
Utils/WikiTagUtils.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);
 
     }
 
--- 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);
     }