Esvaziando a lixeira Umbraco

Esvaziando a lixeira do Umbraco pelo banco de dados

Algumas vezes, principalmente na versão 6, executar o comando de limpar a lixeira pelo admin falha. Normalmente acontece porque a lixeira muito cheia. Uma alternativa é  limpar pelo banco usando o script abaixo:

--Descomente abaixo para verificar se o número de conteúdo retornados é o mesmo que o número na Lixeira
-- SELECT * FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20

-- Excluir todos os relacionamentos dos nós que estão na lixeira
CREATE TABLE #temp ([id] int);
INSERT #temp select id from umbracoNode where path like '%-20%' and id!=-20
 
-- Delete all 'related' nodes and table contents...
DELETE FROM cmsPreviewXml WHERE nodeId IN (SELECT id FROM #temp)
DELETE FROM cmsContentVersion WHERE contentId IN (SELECT id FROM #temp)
DELETE FROM cmsDocument WHERE nodeId IN (SELECT id FROM #temp)
DELETE FROM cmsContentXML WHERE nodeId IN (SELECT id FROM #temp)
DELETE FROM cmsContent WHERE nodeId IN (SELECT id FROM #temp)
DELETE FROM cmsPropertyData WHERE contentNodeId IN (SELECT id FROM #temp)
DELETE FROM umbracoUser2NodePermission WHERE nodeId IN (SELECT id FROM #temp)
DELETE FROM umbracoRelation  where parentId in (select id from #temp) or childId in (select id from #temp)
 
-- remove fk umbracoNode para poder remover
ALTER TABLE umbracoNode DROP CONSTRAINT FK_umbracoNode_umbracoNode
-- Excluindo do XML
DELETE FROM umbracoNode WHERE id in (SELECT id FROM #temp)
-- Adicionando o fk umbracoNode novamente
ALTER TABLE umbracoNode WITH NOCHECK ADD CONSTRAINT FK_umbracoNode_umbracoNode
FOREIGN KEY (parentId)
REFERENCES umbracoNode (id)

DROP TABLE #temp;
 

Isso ai