From 1c70b2fb7e66826876fa052f250063f6f80768be Mon Sep 17 00:00:00 2001
From: Kazuhiko Shiozaki <kazuhiko@nexedi.com>
Date: Mon, 10 Nov 2008 20:13:14 +0000
Subject: [PATCH] Since r.24533 made updateRelatedContent() not call
 CMFCategory's updateRelatedContent(), we need to call the method recursively
 if needed. This will fix the failure of testCopySupport.py.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24551 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Tool/CategoryTool.py | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/product/ERP5/Tool/CategoryTool.py b/product/ERP5/Tool/CategoryTool.py
index 9ab0c7f89c..1851ddd4ef 100644
--- a/product/ERP5/Tool/CategoryTool.py
+++ b/product/ERP5/Tool/CategoryTool.py
@@ -34,6 +34,7 @@ from Products.CMFCategory.CategoryTool import CategoryTool as CMFCategoryTool
 from Products.ERP5Type.Tool.BaseTool import BaseTool
 from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2
 from AccessControl import ClassSecurityInfo
+from Acquisition import aq_base
 from Globals import InitializeClass, DTMLFile, PersistentMapping
 from OFS.Folder import Folder as OFS_Folder
 from Products.ERP5Type import Permissions
@@ -177,8 +178,21 @@ class CategoryTool(CopyContainer, CMFCategoryTool, BaseTool):
           membership_list.append(new_category)
         predicate.edit(membership_criterion_category_list=membership_list,
                        activate_kw=activate_kw)
-      # We do not need to to things recursively since
-      # updateRelatedContent is already recursive.
+
+      # update related recursively if required
+      aq_context = aq_base(context)
+      if getattr(aq_context, 'listFolderContents', None) is not None:
+        for o in context.listFolderContents():
+          new_o_category_url = o.getRelativeUrl()
+          # Relative Url is based on parent new_category_url so we must
+          # replace new_category_url with previous_category_url to find
+          # the new category_url for the subobject
+          previous_o_category_url = self.updateRelatedCategory(
+              new_o_category_url,
+              new_category_url,
+              previous_category_url)
+          self.updateRelatedContent(o, previous_o_category_url,
+                                    new_o_category_url)
 
 InitializeClass( CategoryTool )
 
-- 
2.30.9