From f17c4949519d11f293d9426589eba82915bcc625 Mon Sep 17 00:00:00 2001
From: Ivan Tyagov <ivan@nexedi.com>
Date: Wed, 26 Nov 2008 15:50:33 +0000
Subject: [PATCH] If a business template contains skin folder which registers a
 new skin make sure that when this skin folder is uninstalled the skin is
 removed from portal_skins tool. This way both install/uninstall process is
 consistent with respect to skin handling.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24710 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/BusinessTemplate.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/product/ERP5/Document/BusinessTemplate.py b/product/ERP5/Document/BusinessTemplate.py
index 758e41deeb..f15eb1cffd 100644
--- a/product/ERP5/Document/BusinessTemplate.py
+++ b/product/ERP5/Document/BusinessTemplate.py
@@ -966,7 +966,13 @@ class ObjectTemplateItem(BaseTemplateItem):
                                         # in case object is already backup and/or removed
         if trash and trashbin is not None:
           self.portal_trash.backupObject(trashbin, container_path, object_id, save=1, keep_subobjects=1)
-        container.manage_delObjects([object_id])
+        if container.meta_type == 'CMF Skins Tool':
+          # we are removing a skin folder, check and remove if registered skin selection
+          skin_folder = container[object_id]
+          registered_skin_selections = getattr(skin_folder, 'business_template_registered_skin_selections', None)
+          if registered_skin_selections is not None:
+            container.manage_skinLayers(chosen=registered_skin_selections, del_skin=1)
+          container.manage_delObjects([object_id])
         if container.aq_parent.meta_type == 'ERP5 Catalog' and len(container.objectIds()) == 0:
           # We are removing a ZSQLMethod, remove the SQLCatalog if empty
           container.getParentValue().manage_delObjects([container.id])
-- 
2.30.9