Entity/TagRepository.php
changeset 58 87bf6ec8af90
parent 42 0e57c730bb18
child 59 ea562f37d7a5
--- a/Entity/TagRepository.php	Tue Dec 06 14:53:12 2011 +0100
+++ b/Entity/TagRepository.php	Thu Dec 08 23:48:55 2011 +0100
@@ -58,9 +58,11 @@
         $tags = $this->findBy(array('normalizedLabel' => $tag_label_normalized));
         $tag = null;
         foreach ($tags as $t) {
-            if($tag==null || $t->getUrlStatus()!=Tag::$TAG_URL_STATUS_DICT['null_result']) {
+            if($tag==null
+            || $tag->getUrlStatus() === Tag::$TAG_URL_STATUS_DICT['unsemantized']
+            || ($tag->getUrlStatus() === Tag::$TAG_URL_STATUS_DICT['null_result'] && $t->getUrlStatus() !== Tag::$TAG_URL_STATUS_DICT['unsemantized'])) {
                 $tag = $t;
-                if($t->getUrlStatus()!=Tag::$TAG_URL_STATUS_DICT['null_result']) {
+                if($tag->getUrlStatus()!=Tag::$TAG_URL_STATUS_DICT['unsemantized'] && $tag->getUrlStatus()!=Tag::$TAG_URL_STATUS_DICT['null_result']) {
                     break;
                 }
             }
@@ -75,32 +77,10 @@
         }
         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) {
+        // We request Wikipedia if the tag is created or if this is a null result
+        if($created==true || $tag->getUrlStatus()===Tag::$TAG_URL_STATUS_DICT['null_result']) {
             
             if($wp_request_done==false) {
                 $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);