Commit 97c46cc0 authored by Sebastien Robin's avatar Sebastien Robin

allow to use hotReindex in unit test


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2034 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 587603c1
...@@ -302,6 +302,9 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -302,6 +302,9 @@ class ZCatalog(Folder, Persistent, Implicit):
if self.default_sql_catalog_id == source_sql_catalog_id: if self.default_sql_catalog_id == source_sql_catalog_id:
self.default_sql_catalog_id = destination_sql_catalog_id self.default_sql_catalog_id = destination_sql_catalog_id
LOG('exchangeDatabases skin_selection_dict:',0,skin_selection_dict)
if skin_selection_dict is not None:
LOG('exchangeDatabases skin_selection_dict:',0,'we will do manage_skinLayers')
for skin_name, selection in self.portal_skins.getSkinPaths(): for skin_name, selection in self.portal_skins.getSkinPaths():
if skin_name in skin_selection_dict: if skin_name in skin_selection_dict:
new_selection = tuple(skin_selection_dict[skin_name]) new_selection = tuple(skin_selection_dict[skin_name])
...@@ -319,19 +322,33 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -319,19 +322,33 @@ class ZCatalog(Folder, Persistent, Implicit):
changeSQLConnectionIds(self.portal_skins) changeSQLConnectionIds(self.portal_skins)
def manage_hotReindexAll(self, REQUEST, RESPONSE, URL1): def manage_hotReindexAll(self, source_sql_catalog_id='erp5_mysql',
destination_sql_catalog_id='erp5_mysql',
source_sql_connection_id_list = None,
destination_sql_connection_id_list = None,
skin_name_list = None,
skin_selection_list = None,
REQUEST=None, RESPONSE=None):
""" """
Reindex objects from scratch in the background then switch to the newly created database. Reindex objects from scratch in the background then switch to the newly created database.
""" """
# Get parameters. # Get parameters.
source_sql_catalog_id = REQUEST.get('source_sql_catalog_id') #source_sql_catalog_id = REQUEST.get('source_sql_catalog_id')
destination_sql_catalog_id = REQUEST.get('destination_sql_catalog_id') #destination_sql_catalog_id = REQUEST.get('destination_sql_catalog_id')
source_sql_connection_id_list = REQUEST.get('source_sql_connection_id_list') #source_sql_connection_id_list = REQUEST.get('source_sql_connection_id_list')
destination_sql_connection_id_list = REQUEST.get('destination_sql_connection_id_list') #destination_sql_connection_id_list = REQUEST.get('destination_sql_connection_id_list')
skin_name_list = REQUEST.get('skin_name_list') #skin_name_list = REQUEST.get('skin_name_list')
skin_selection_list = REQUEST.get('skin_selection_list') #skin_selection_list = REQUEST.get('skin_selection_list')
LOG('source_sql_catalog_id',0,source_sql_catalog_id)
LOG('destination_sql_catalog_id',0,destination_sql_catalog_id)
LOG('source_sql_connection_id_list',0,source_sql_connection_id_list)
LOG('destination_sql_connection_id_list',0,destination_sql_connection_id_list)
LOG('skin_name_list',0,skin_name_list)
LOG('skin_selection_list',0,skin_selection_list)
# Construct a mapping for skin selections. # Construct a mapping for skin selections.
skin_selection_dict = None
if skin_name_list is not None and skin_selection_list is not None:
skin_selection_dict = {} skin_selection_dict = {}
for name, selection_list in zip(skin_name_list, skin_selection_list): for name, selection_list in zip(skin_name_list, skin_selection_list):
# Make sure that there is no extra space. # Make sure that there is no extra space.
...@@ -343,6 +360,8 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -343,6 +360,8 @@ class ZCatalog(Folder, Persistent, Implicit):
skin_selection_dict[name] = new_selection_list skin_selection_dict[name] = new_selection_list
# Construct a mapping for connection ids. # Construct a mapping for connection ids.
sql_connection_id_dict = None
if source_sql_connection_id_list is not None and destination_sql_connection_id_list is not None:
sql_connection_id_dict = {} sql_connection_id_dict = {}
for source_sql_connection_id, destination_sql_connection_id in zip(source_sql_connection_id_list, destination_sql_connection_id_list): for source_sql_connection_id, destination_sql_connection_id in zip(source_sql_connection_id_list, destination_sql_connection_id_list):
if source_sql_connection_id != destination_sql_connection_id: if source_sql_connection_id != destination_sql_connection_id:
...@@ -367,10 +386,14 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -367,10 +386,14 @@ class ZCatalog(Folder, Persistent, Implicit):
# XXX Commit transactions very often and use resolve_path to get objects instead of objectValues # XXX Commit transactions very often and use resolve_path to get objects instead of objectValues
# XXX This is not to be disturbed by normal user operations in the foreground. # XXX This is not to be disturbed by normal user operations in the foreground.
# XXX Otherwise, many read conflicts happen and hot reindexing restarts again and again. # XXX Otherwise, many read conflicts happen and hot reindexing restarts again and again.
for path in self.Catalog_getIndexablePathList(): LOG('hotReindex, skin_core.objectIds',0,self.portal_skins.erp5_core.objectIds())
LOG('hotReindex, skin_core.__dict__',0,self.portal_skins.__dict__)
#for path in self.Catalog_getIndexablePathList():
for path in self.portal_skins.erp5_core.Catalog_getIndexablePathList():
object = self.resolve_path(path) object = self.resolve_path(path)
if object is None: continue if object is None: continue
id_list = object.objectIds() id_list = object.objectIds()
# object.activate(passive_commit=1, priority=5).queueCataloggedObject(sql_catalog_id=destination_sql_catalog_id)
object = None object = None
get_transaction().commit() # Should not have references to objects too long. get_transaction().commit() # Should not have references to objects too long.
...@@ -404,8 +427,10 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -404,8 +427,10 @@ class ZCatalog(Folder, Persistent, Implicit):
finally: finally:
# Finish. # Finish.
LOG('hotReindexObjectList', 0, 'Finishing hot reindexing') LOG('hotReindexObjectList', 0, 'Finishing hot reindexing')
self.activate(passive_commit=1, after_method_id='exchageDatabases', priority=5).setHotReindexingState('finished') self.activate(passive_commit=1, after_method_id='exchangeDatabases', priority=5).setHotReindexingState('finished')
if RESPONSE is not None:
URL1 = REQUEST.get('URL1')
RESPONSE.redirect(URL1 + '/manage_catalogHotReindexing?manage_tabs_message=Catalog%20Changed') RESPONSE.redirect(URL1 + '/manage_catalogHotReindexing?manage_tabs_message=Catalog%20Changed')
def manage_edit(self, RESPONSE, URL1, threshold=1000, REQUEST=None): def manage_edit(self, RESPONSE, URL1, threshold=1000, REQUEST=None):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment