Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Allan Molsen Larsen 22 posts 192 karma points
    Jul 21, 2014 @ 13:30
    Allan Molsen Larsen
    1

    Document Types usage count

    Hi 

    I just love the new feature which allows you to change document type on content in Umbraco 7. This feature makes it easier to clean up old Umbraco sites after an upgrade. Nice! :-)

    This leads to my question. Is there a way to keep track of document types that are not in being used anymore? 

  • Anders Bjerner 487 posts 2989 karma points MVP 7x admin c-trib
    Jul 22, 2014 @ 14:34
    Anders Bjerner
    100

    My approach would be something like:

    1. Get list of all document types
    2. Loop through each document type, and do a XPath lookup in the XML cache

    In code this would look something like:

    IContentTypeService service = UmbracoContext.Current.Application.Services.ContentTypeService;
    UmbracoHelper helper = new UmbracoHelper(UmbracoContext.Current);
    
    foreach (IContentType contentType in service.GetAllContentTypes()) {
        <p>@contentType.Alias: @(helper.TypedContentAtXPath("descendant-or-self::" + contentType.Alias + "[@isDoc]").Count())</p>
    }
    

    Depending on your XML cache, this might take some time (took a few seconds for a installation with 30k nodes). Also notice that this will only work if all documents are in the XML cache, and it won't look at documents in the recycle bin.

  • Allan Molsen Larsen 22 posts 192 karma points
    Jul 22, 2014 @ 22:10
    Allan Molsen Larsen
    0

    Thanks Anders

    The site I'm upgrading only has about 2k nodes, so no problem running your snippet. It does exactly what I needed, thanks :-)

    Anyone running this snippet, remember the using statement:

    @using Umbraco.Core.Services
    
Please Sign in or register to post replies

Write your reply to:

Draft