2016-12-03 79 views
0

当我从cq5/AEM中的标签部分删除标签时,相同的标签m =未从页面引用(cq:tags)部分删除。如何从引用(cq:tags)中删除标签,将其从标签列表中删除?

到目前为止,我成功地找到了标签被引用的路径。但无法从(cq:tags)部分删除该标签。谁能帮我。

我真的试图实现它在脚本

(function() { 
if (window.location.pathname !== "/tagging") { 
    return; 
} 

registerShowRefsAlert(); 

//the query to find tag references (pages and assets) 
var CHECK_TAGS_SQL_2_QUERY = "SELECT * from [nt:base] AS t WHERE NAME(t) = 'jcr:content' " + 
           "AND CONTAINS(t.*, 'PLACEHOLDER')"; 

var query = ''; 
function registerShowRefsAlert(){ 

    var tagAdmin = CQ.tagging.TagAdmin, 
     deleteTagFn = tagAdmin.deleteTag; 

    //override ootb function to inject the logic showing references alert 
    tagAdmin.deleteTag = function(){ 
     var tagPath = tagAdmin.getSelectedTag(); 

     if (tagPath == null) { 
      return; 
     } 

     tagPath = tagPath.substring(this.tagsBasePath.length + 1); 

     var tagInfo = CQ.tagging.parseTag(tagPath, true), 
      query = encodeURIComponent(CHECK_TAGS_SQL_2_QUERY.replace("PLACEHOLDER", tagInfo.getTagID())); 

     //you may want to replace this crxde lite call with a servlet returning query results 
     query = "/crx/de/query.jsp?type=JCR-SQL2&showResults=true&stmt=" + query; 

     //"this" here is tagadmin object, passed as context 
     $.ajax({ url: query, context: this }).done(showAlert); 
    }; 

    function showAlert(data){ 
     console.log('query value' + query); 
     if(_.isEmpty(data) || _.isEmpty(data.results)){ 
      deleteTagFn.call(this); 
      return; 
     } 

     var message = "Selected tag is referenced. Click 'yes' to proceed deleting, 'no' to cancel the operation.<br><br>"; 

     _.each(data.results, function(result){ 
      message = message + result.path + "<br>"; 
     }); 

     CQ.Ext.Msg.show({ 
      "title": "Delete Tag", 
      "msg": message, 
      "buttons": CQ.Ext.Msg.YESNO, 
      "icon": CQ.Ext.MessageBox.QUESTION, 
      "fn": function (btnId) { 
       if (btnId == "yes") { 
        this.postTagCommand("deleteTag", tagAdmin.getSelectedTag()); 
        //Iterator<Resource> it = tag.find(); 
        //console.log('the tag id' + it); 
        //this.deleteTag(it); 
       } 
      }, 
      "scope": this 
     }); 
    } 
} 

}());

enter image description here

回答

0

它最终清晰起来,它只是以异步的方式这样做。

采取一种方法,您已将标记添加到页面然后将其删除。如果您然后进入该页面通过UI查看与其关联的标签,则该标签不会显示出来。但是,如果您进入CRX/DE,您仍然会看到它与页面关联。

如果您通过TagManager API执行搜索,它将找不到与已删除标签关联的任何页面。

原因似乎是所有与标签交互的api都会在请求时解析标签。我相信这是为了便于您移动标签或将其合并到另一个标签中的情况。

有一个叫com.day.cq.tagging.impl.TagGarbageCollector

夜间作业将通过和识别标签并加以解决,而你的情况会导致它从页面移除。

或者为了解释,您不需要做任何特别的事情,这些标签会每晚更新。

+0

对不起,迟到repy和非常感谢。它运行良好。 – shabarinath