Copied to clipboard

Flag this post as spam?

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


  • Sébastien Richer 194 posts 430 karma points
    Mar 26, 2012 @ 17:13
    Sébastien Richer
    0

    How to find out if a template is currently being used?

    Hello,

    I have a bunch of templates in my project and want to do some housekeeping. I'm wondering if there is a quick way to find out is a specific template is currently being used by nodes and if so what are those nodes.

    Is there a plugin for this? Maybe I could query directly SQL, this is juste for internal dev occasionnal needs.

    Thanks!

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Mar 26, 2012 @ 17:20
    Hendy Racher
    0

    Hi Sébastien,

    Does the following SQL help ? (it'll only return nodes using that exact template id, so bear in mind any template inheritance)

     
    /* Return all content nodes that use a given template ID */

    DECLARE @templateId AS int
    SET @templateId = 1234


    SELECT C.path AS 'Path',
    C.level AS 'Level',
    C.id AS 'Node Id',
    C.text AS 'Text',
    A.alias AS 'docType Alias'
    FROM cmsContentType A
    LEFT OUTER JOIN cmsContent B ON A.nodeId = B.contentType
    INNER JOIN umbracoNode C ON B.nodeId = C.id
    WHERE A.nodeId IN (

    SELECT contentTypeNodeId
    FROM cmsDocumentType A
    INNER JOIN cmsContentType B ON A.contentTypeNodeId = B.nodeId
    WHERE templateNodeid = @templateId
    )
    ORDER BY text ASC
  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 26, 2012 @ 17:36
    Jeroen Breuer
    0

    Even if it's not used anymore you still can't delete it: http://umbraco.codeplex.com/workitem/29306

    Jeroen

  • Sébastien Richer 194 posts 430 karma points
    Mar 26, 2012 @ 17:41
    Sébastien Richer
    0

    It says "Resolved with changeset 79278." but how was it resolved... who knows....

    Thanks Hendy, that query worked. I might reverse it to fin unused templates. Thanks!

     

    Edit: Ohh wait Jeroen has a good point, I can see nodes are using a specific template, but when I look at that node through the CMS it's not assigned to that template. Ohh this is bad :(

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Mar 26, 2012 @ 17:46
    Hendy Racher
    0

    Hi Sébastien,

    If you do update the SQL to return all unused templates, any change you could post it back here ? Reckon that'd be a really useful snippet :)

    Hendy

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 26, 2012 @ 17:49
    Jeroen Breuer
    0

    It was fixed that you now get a message if you try to delete saying that you can't. Probably not what you wanted to hear. If you want to delete templates you'll probably also need to delete het version history of the nodes which used the template.

    Jeroen

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Mar 26, 2012 @ 17:49
    Hendy Racher
    0

    Uh oh, that's a bit worrying - not come across that issue before.. sitill I guess it makes sense if you have to roll back to a previous version - can they be deleted if the version history is cleared ?

  • Sébastien Richer 194 posts 430 karma points
    Mar 26, 2012 @ 17:52
    Sébastien Richer
    0

    The trouble I have here is that having unused templates, will create unused code in my project and then increase the amount of code to maintain. Indeed history causes an issue here. There should be an option to "retire" a template, the important part is that the "local file" be removed so it's cleared from the project / source control / visual studio project. I'll try and talk to collegues see how they manage issues like this.

  • Rodion Novoselov 694 posts 859 karma points
    Mar 26, 2012 @ 20:28
    Rodion Novoselov
    0

    Hi. Some time ago I came across the issue with unused templetes as well. It looks to be caused by old versions of a document that prevent deletion of the template record from the database with a foreign key. I realised that it can be fixed with nulling corresponding "templateId" values in the "dbo.cmsDocument" table like this:

    update dbo.cmsDocument
      set templateId = NULL
      where templateId = <yourTemplateIdHere>

    Than you can delete the unused template using the backoffice without problems. Be carefull executing the sql statement so that not to null unwanted records. (The best is to create a database backup beforehand of course)

     

Please Sign in or register to post replies

Write your reply to:

Draft