From c66dbeee89560ff06a892ddcc3f3e1b4d8424cfe Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Wed, 31 Oct 2007 10:33:50 +0000
Subject: [PATCH] Prevent catalog clear from failing when portal_ids table does
 not exist. Code structure taken from
 ZSQLCatalog/SQLCatalog.py:Catalog.clear() .

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17308 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Catalog/CatalogTool.py | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/product/ERP5Catalog/CatalogTool.py b/product/ERP5Catalog/CatalogTool.py
index 334b0c8f6e..11dc98bd70 100644
--- a/product/ERP5Catalog/CatalogTool.py
+++ b/product/ERP5Catalog/CatalogTool.py
@@ -604,10 +604,19 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
       Clears the catalog by calling a list of methods
       """
       id_tool = self.getPortalObject().portal_ids
-      # Call generate new id in order to store the last id into
-      # the zodb
-      id_tool.generateNewLengthId(id_group='portal_activity')
-      id_tool.generateNewLengthId(id_group='portal_activity_queue')
+      try:
+        # Call generate new id in order to store the last id into
+        # the zodb
+        id_tool.generateNewLengthId(id_group='portal_activity')
+        id_tool.generateNewLengthId(id_group='portal_activity_queue')
+      except ConflictError:
+        raise
+      except:
+        # Swallow exceptions to allow catalog clear to happen.
+        # For example, is portal_ids table does not exist and exception will
+        # be thrown by portal_id methods.
+        LOG('ERP5Catalog.beforeCatalogClear', WARNING,
+            'beforeCatalogClear failed', error=sys.exc_info())
 
     security.declarePrivate('unrestrictedSearchResults')
     def unrestrictedSearchResults(self, REQUEST=None, **kw):
-- 
2.30.9