I am working on an event to delete unused keywords, however I am running into problems determining whether or not a keyword is used for classification across any of the publications. We are using these keywords in component metadata; the field is a multi-valued Text field with values selected from a Category (Select Box).
I was hoping it would be as easy as doing something similar to below:
// OFFER_CODE_URI is the WebDav path to the Category (keywords also created here)
var category = component.Session.GetObject(OFFER_CODE_URI) as Category;
var childkeywords = category.GetKeywords().ToArray();
foreach (Keyword keyword in childkeywords)
{
if (!keyword.HasUsingItems())
{
// Do some exception handling ..
keyword.Delete();
}
}
However, I noticed that the 'HasUsingItems()' is returning true even if the Keyword is not used for classification (but still remains unselected in the Select Box), even though I can go manually delete the keyword from the CMS. I have also tried using the method 'GetClassifiedItems()' and counting the number of classified items, however this seems to be publication specific.
if (keyword.GetClassifiedItems().Count() == 0)
{
// Do some exception handling ..
keyword.Delete();
}
I could loop through the necessary publications, checking to see whether or not the keyword has classified items in any of the publications and then delete it if it does not, however this could get quite expensive. I am looking for a more efficient method to determine whether or not I can delete() a keyword if it is not used for classification across any of the publications. Thanks in advance.