Commit 437a197e authored by Ayush Tiwari's avatar Ayush Tiwari

multiple_catalog:[Workaround] ERP5SiteReindexAll should reindex in all catalog...

multiple_catalog:[Workaround] ERP5SiteReindexAll should reindex in all catalog by creating activities for each one of them
parent 4a746445
...@@ -10,12 +10,15 @@ if clear_catalog: ...@@ -10,12 +10,15 @@ if clear_catalog:
if is_subscribed: if is_subscribed:
portal.portal_alarms.unsubscribe() portal.portal_alarms.unsubscribe()
# Reindex person module catalog_id_list = [portal.portal_catalog.getSQLCatalog().id]
print "#### Indexing person_module, stage 1 ####"
person_module=getattr(portal, 'person_module', None) for sql_catalog_id in catalog_id_list:
higher_priority = 1 + additional_priority # Reindex person module
if person_module is not None : print "#### Indexing person_module, stage 1 ####"
tag = 'person_stage_1' person_module=getattr(portal, 'person_module', None)
higher_priority = 1 + additional_priority
if person_module is not None :
tag = 'person_stage_1_%s'%sql_catalog_id
person_module.recurseCallMethod( person_module.recurseCallMethod(
method_id='immediateReindexObject', method_id='immediateReindexObject',
group_method_id='portal_catalog/catalogObjectList', group_method_id='portal_catalog/catalogObjectList',
...@@ -29,17 +32,16 @@ if person_module is not None : ...@@ -29,17 +32,16 @@ if person_module is not None :
max_depth=1, # Do not reindex Person's subobjects max_depth=1, # Do not reindex Person's subobjects
) )
print "#### Indexing translations ####" print "#### Indexing translations ####"
context.ERP5Site_updateTranslationTable(sql_catalog_id=sql_catalog_id) context.ERP5Site_updateTranslationTable(sql_catalog_id=sql_catalog_id)
# Reindex categories
print "#### Indexing categories ####"
folder_tag = 'module_%s'%sql_catalog_id
folder_after_tag = ('person_stage_1_%s'%sql_catalog_id, 'group_person_stage_1')
object_tag = 'category_%s'%sql_catalog_id
object_after_tag = folder_after_tag
# Reindex categories context.portal_categories.activate(
print "#### Indexing categories ####"
folder_tag = 'module'
folder_after_tag = ('person_stage_1', 'group_person_stage_1')
object_tag = 'category'
object_after_tag = folder_after_tag
context.portal_categories.activate(
tag=folder_tag, tag=folder_tag,
priority=higher_priority, priority=higher_priority,
after_tag=folder_after_tag).Folder_reindexAll( after_tag=folder_after_tag).Folder_reindexAll(
...@@ -52,14 +54,14 @@ context.portal_categories.activate( ...@@ -52,14 +54,14 @@ context.portal_categories.activate(
start_tree=start_tree, start_tree=start_tree,
stop_tree=stop_tree,) stop_tree=stop_tree,)
print "#### Indexing alarms ####" print "#### Indexing alarms ####"
print "#### Indexing active results ####" print "#### Indexing active results ####"
folder_tag = 'module' folder_tag = 'module_%s'%sql_catalog_id
folder_after_tag = ('category', 'person_stage_1', 'group_person_stage_1') folder_after_tag = ('category_%s'%sql_catalog_id, 'person_stage_1_%s'%sql_catalog_id, 'group_person_stage_1')
object_tag = 'document' object_tag = 'document_%s'%sql_catalog_id
object_after_tag = folder_after_tag object_after_tag = folder_after_tag
object_priority = 2 + additional_priority object_priority = 2 + additional_priority
for folder in [context.portal_alarms, context.portal_activities]: for folder in [context.portal_alarms, context.portal_activities]:
folder.activate( folder.activate(
tag=folder_tag, tag=folder_tag,
priority=object_priority, priority=object_priority,
...@@ -73,9 +75,9 @@ for folder in [context.portal_alarms, context.portal_activities]: ...@@ -73,9 +75,9 @@ for folder in [context.portal_alarms, context.portal_activities]:
start_tree=start_tree, start_tree=start_tree,
stop_tree=stop_tree,) stop_tree=stop_tree,)
print "#### Indexing preferences ####" print "#### Indexing preferences ####"
preference_tag = 'portal_preferences' preference_tag = 'portal_preferences_%s'%sql_catalog_id
context.portal_preferences.activate( context.portal_preferences.activate(
tag=preference_tag, tag=preference_tag,
after_tag='category', after_tag='category',
priority=additional_priority).Folder_reindexAll( priority=additional_priority).Folder_reindexAll(
...@@ -86,15 +88,15 @@ context.portal_preferences.activate( ...@@ -86,15 +88,15 @@ context.portal_preferences.activate(
start_tree=start_tree, start_tree=start_tree,
stop_tree=stop_tree,) stop_tree=stop_tree,)
# We index simulation first to make sure we can calculate tests # We index simulation first to make sure we can calculate tests
# (ie. related quantity) # (ie. related quantity)
print "#### Indexing simulation ####" print "#### Indexing simulation ####"
folder_tag = 'module' folder_tag = 'module_%s'%sql_catalog_id
folder_after_tag = ('category', 'document', 'person_stage_1', 'group_person_stage_1', preference_tag) folder_after_tag = ('category_%s'%sql_catalog_id, 'document_%s'%sql_catalog_id, 'person_stage_1_%s'%sql_catalog_id, 'group_person_stage_1', preference_tag)
object_tag = 'simulation' object_tag = 'simulation_%s'%sql_catalog_id
object_after_tag = folder_after_tag object_after_tag = folder_after_tag
object_priority = 3 + additional_priority object_priority = 3 + additional_priority
context.portal_simulation.activate( context.portal_simulation.activate(
tag=folder_tag, tag=folder_tag,
priority=higher_priority, priority=higher_priority,
after_tag=folder_after_tag).Folder_reindexAll( after_tag=folder_after_tag).Folder_reindexAll(
...@@ -107,20 +109,34 @@ context.portal_simulation.activate( ...@@ -107,20 +109,34 @@ context.portal_simulation.activate(
start_tree=start_tree, start_tree=start_tree,
stop_tree=stop_tree,) stop_tree=stop_tree,)
# We index tools secondly # XXX: Hack to avoid even trying to index these objects
print "#### Indexing tools ####" restricted_tool_id_list = ( 'portal_alarms', 'portal_activities',
'portal_classes', 'portal_preferences',
'portal_simulation', 'portal_uidhandler',
'portal_actions', 'portal_memberdata',
'portal_skins', 'portal_undo',
'portal_url', 'portal_workflow',
'portal_discussion', 'portal_membership',
'portal_registration', 'portal_properties',
'portal_metadata', 'portal_syndication',
'portal_syndication', 'portal_syndication',
)
folder_tag = 'module' # We index tools secondly
folder_after_tag = ('category', 'person_stage_1', 'group_person_stage_1', preference_tag) print "#### Indexing tools ####"
object_tag = 'document' folder_tag = 'module_%s'%sql_catalog_id
object_after_tag = folder_after_tag folder_after_tag = ('category_%s'%sql_catalog_id, 'person_stage_1_%s'%sql_catalog_id, 'group_person_stage_1', preference_tag)
object_priority = 2 + additional_priority object_tag = 'document_%s'%sql_catalog_id
tool_list = [x for x in portal.objectValues() if \ object_after_tag = folder_after_tag
x.getUid != portal.getUid and \ object_priority = 2 + additional_priority
tool_list = [x for x in portal.objectValues() if \
x.meta_type != 'ERP5 Folder' and \ x.meta_type != 'ERP5 Folder' and \
x.id not in ('portal_alarms', 'portal_activities', 'portal_classes', 'portal_preferences', 'portal_simulation', 'portal_uidhandler')] x.id != portal.id and \
x.id not in restricted_tool_id_list]
for folder in tool_list: for folder in tool_list:
try:
folder.activate( folder.activate(
tag=folder_tag, tag=folder_tag,
priority=object_priority, priority=object_priority,
...@@ -133,16 +149,27 @@ for folder in tool_list: ...@@ -133,16 +149,27 @@ for folder in tool_list:
sql_catalog_id=sql_catalog_id, sql_catalog_id=sql_catalog_id,
start_tree=start_tree, start_tree=start_tree,
stop_tree=stop_tree,) stop_tree=stop_tree,)
except:
continue
# for sql_catalog_id in catalog_id_list:
# Then we index ERP5 Python Scripts
print "#### Indexing ERP5 Python Scripts ####"
for path, obj in portal.portal_skins.ZopeFind(portal.portal_skins, obj_metatypes=('ERP5 Python Script',), search_sub=1):
obj.activate(tag=folder_tag,
priority=object_priority,
after_tag=folder_after_tag).immediateReindexObject(sql_catalog_id=sql_catalog_id)
# Then we index ERP5 Python Scripts and ERP5 Form #for sql_catalog_id in catalog_id_list:
print "#### Indexing ERP5 Python Scripts, ERP5 Forms and ERP5 Reports ####" # Then we index ERP5 SQL Methods
for _, obj in portal.portal_skins.ZopeFind(portal.portal_skins, obj_metatypes=('ERP5 Python Script', 'ERP5 Form', 'ERP5 Report'), search_sub=1): print "#### Indexing ERP5 SQL Methods ####"
for path, obj in portal.portal_skins.ZopeFind(portal.portal_skins, obj_metatypes=('ERP5 SQL Method',), search_sub=1):
obj.activate(tag=folder_tag, obj.activate(tag=folder_tag,
priority=object_priority, priority=object_priority,
after_tag=folder_after_tag).immediateReindexObject(sql_catalog_id=sql_catalog_id) after_tag=folder_after_tag).immediateReindexObject(sql_catalog_id=sql_catalog_id)
# Then we index everything except inventories # Then we index everything except inventories
for folder in portal.objectValues(("ERP5 Folder",)): for folder in portal.objectValues(("ERP5 Folder",)):
if folder.getId().find('inventory') < 0: if folder.getId().find('inventory') < 0:
print "#### Indexing contents inside folder %s ####" % folder.id print "#### Indexing contents inside folder %s ####" % folder.id
folder.activate( folder.activate(
...@@ -158,10 +185,10 @@ for folder in portal.objectValues(("ERP5 Folder",)): ...@@ -158,10 +185,10 @@ for folder in portal.objectValues(("ERP5 Folder",)):
start_tree=start_tree, start_tree=start_tree,
stop_tree=stop_tree,) stop_tree=stop_tree,)
# Then we index inventories # Then we index inventories
object_tag = 'inventory' object_tag = 'inventory_%s'%sql_catalog_id
object_after_tag = ('module', 'category', 'person_stage_1', 'document', 'group_person_stage_1') object_after_tag = ('module_%s'%sql_catalog_id, 'category_%s'%sql_catalog_id, 'person_stage_1_%s'%sql_catalog_id, 'document_%s'%sql_catalog_id, 'group_person_stage_1')
for folder in portal.objectValues(("ERP5 Folder",)): for folder in portal.objectValues(("ERP5 Folder",)):
if folder.getId().find('inventory') >= 0: if folder.getId().find('inventory') >= 0:
print "#### Indexing contents inside folder %s ####" % folder.id print "#### Indexing contents inside folder %s ####" % folder.id
folder.activate( folder.activate(
...@@ -177,28 +204,29 @@ for folder in portal.objectValues(("ERP5 Folder",)): ...@@ -177,28 +204,29 @@ for folder in portal.objectValues(("ERP5 Folder",)):
start_tree=start_tree, start_tree=start_tree,
stop_tree=stop_tree,) stop_tree=stop_tree,)
# start activty from simulation because the erp5site is not an active object # start activty from simulation because the erp5site is not an active object
context.portal_simulation.activate( context.portal_simulation.activate(
after_tag=('inventory', 'simulation', 'person_stage_1', 'group_person_stage_1'), after_tag=('inventory_%s'%sql_catalog_id, 'simulation_%s'%sql_catalog_id, 'person_stage_1_%s'%sql_catalog_id, 'group_person_stage_1'),
priority=3 + additional_priority priority=3 + additional_priority
).InventoryModule_reindexMovementList( ).InventoryModule_reindexMovementList(
sql_catalog_id=sql_catalog_id, sql_catalog_id=sql_catalog_id,
final_activity_tag='last_inventory_activity') final_activity_tag='last_inventory_activity_%s'%sql_catalog_id)
# restore alarm node # restore alarm node
if clear_catalog and is_subscribed: if clear_catalog and is_subscribed:
portal.portal_alarms.activate(after_tag=('inventory', 'module', 'inventory', 'simulation', 'person_stage_1', portal.portal_alarms.activate(after_tag=('inventory_%s'%sql_catalog_id, 'module_%s'%sql_catalog_id, 'inventory_%s'%sql_catalog_id, 'simulation_%s'%sql_catalog_id, 'person_stage_1_%s'%sql_catalog_id,
'group_person_stage_1', 'last_inventory_activity', 'document')).subscribe() 'group_person_stage_1', 'last_inventory_activity_%s'%sql_catalog_id, 'document_%s'%sql_catalog_id)).subscribe()
if final_activity_tag is not None: if final_activity_tag is not None:
# Start a dummy activity which will get discarded when all started activities # Start a dummy activity which will get discarded when all started activities
# (and all activities they trigger) are over. # (and all activities they trigger) are over.
# Started on portal_simulation because activate does not work on portal object... # Started on portal_simulation because activate does not work on portal object...
# No idea if there is a better place. # No idea if there is a better place.
context.portal_simulation.activate(tag=final_activity_tag, context.portal_simulation.activate(tag=final_activity_tag,
priority=3 + additional_priority, priority=3 + additional_priority,
after_tag=('module', 'inventory', 'simulation', 'person_stage_1', after_tag=('module_%s'%sql_catalog_id, 'inventory_%s'%sql_catalog_id, 'simulation_%s'%sql_catalog_id, 'person_stage_1_%s'%sql_catalog_id,
'group_person_stage_1', 'last_inventory_activity', 'document') 'group_person_stage_1', 'last_inventory_activity_%s'%sql_catalog_id, 'document_%s'%sql_catalog_id)
).getId() ).getId()
folder_after_tag = ()
return printed return printed
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