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.
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
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 :(
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.
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 ?
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.
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)
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!
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)
Even if it's not used anymore you still can't delete it: http://umbraco.codeplex.com/workitem/29306
Jeroen
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 :(
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
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
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 ?
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.
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:
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)
is working on a reply...