Commit 272b0be4 authored by Ayush Tiwari's avatar Ayush Tiwari

multiple_catalog: Index in all the catalogs available

parent 9c809286
......@@ -716,11 +716,14 @@ class ZCatalog(Folder, Persistent, Implicit):
immediate_reindex_archive=1, **kw):
"""Catalog a list of objects.
"""
catalog_id_list = self.getERP5CatalogIdList()
for sql_catalog_id in catalog_id_list:
catalog = self.getSQLCatalog(sql_catalog_id)
hot_reindexing = (self.hot_reindexing_state is not None) and \
(catalog is not None) and \
(self.source_sql_catalog_id == catalog.id)
archiving = self.archive_path is not None
wrapped_object_list = []
failed_object_list = []
url_list = []
archive_list = []
......@@ -760,7 +763,6 @@ class ZCatalog(Folder, Persistent, Implicit):
default_catalog = self.getSQLCatalog()
# Construct list of object to catalogged
current_catalog_object_list = []
for obj in object_list:
if hot_reindexing:
try:
......@@ -798,7 +800,10 @@ class ZCatalog(Folder, Persistent, Implicit):
goto_current_catalog = 1
if goto_current_catalog:
current_catalog_object_list.append(obj)
# wrap object only when sure it will be reindex now
# thus security uid is also reindex
wrap_obj = self.wrapObject(obj, sql_catalog_id=sql_catalog_id)
wrapped_object_list.append(wrap_obj)
# run activity or execute for each archive depending on priority
if catalog_dict:
......@@ -807,56 +812,49 @@ class ZCatalog(Folder, Persistent, Implicit):
# if we reindex in current catalog, do not relaunch an activity for this
continue
d = catalog_dict[catalog_id]
# build the wrapped object list
wrapped_object_list_2 = []
for obj in d['obj']:
try:
wrap_obj = self.wrapObject(obj, sql_catalog_id=catalog_id)
wrapped_object_list_2.append(wrap_obj)
except ConflictError:
raise
except:
LOG('WARNING ZSQLCatalog', 0, 'wrapObject failed on the object %r' % (obj,), error=sys.exc_info())
failed_object_list.append(obj)
# hot_reindexing is True when creating an object during a hot reindex, in this case, we don't want
# to reindex it in destination catalog, it will be recorded an play only once
if not hot_reindexing and self.hot_reindexing_state != HOT_REINDEXING_DOUBLE_INDEXING_STATE and \
self.destination_sql_catalog_id == catalog_id:
destination_catalog = self.getSQLCatalog(self.destination_sql_catalog_id)
# reindex objects in destination catalog
destination_catalog.catalogObjectList(
self.wrapObjectList(
object_value_list=d['obj'],
catalog_value=destination_catalog,
),
**kw
)
destination_catalog.catalogObjectList(wrapped_object_list_2, **kw)
else:
archive_catalog = self.getSQLCatalog(catalog_id)
if immediate_reindex_archive:
archive_catalog.catalogObjectList(
self.wrapObjectList(
object_value_list=d['obj'],
catalog_value=archive_catalog,
),
**kw
)
archive_catalog.catalogObjectList(wrapped_object_list_2, **kw)
else:
for obj in d['obj']:
obj._reindexObject(sql_catalog_id=catalog_id, activate_kw = \
{'priority': d['priority']}, disable_archive=1, **kw)
if catalog is not None:
if current_catalog_object_list:
catalog.catalogObjectList(
self.wrapObjectList(
object_value_list=current_catalog_object_list,
catalog_value=catalog,
),
**kw
)
if wrapped_object_list:
catalog.catalogObjectList(wrapped_object_list, **kw)
if hot_reindexing:
destination_catalog = self.getSQLCatalog(self.destination_sql_catalog_id)
if destination_catalog.id != catalog.id:
if self.hot_reindexing_state == HOT_REINDEXING_RECORDING_STATE:
destination_catalog.recordObjectList(url_list, 1)
elif object_list:
destination_catalog.catalogObjectList(
self.wrapObjectList(
object_value_list=object_list,
catalog_value=destination_catalog,
),
**kw
)
else:
wrapped_destination_object_list = []
for obj in object_list:
wrap_obj = self.wrapObject(obj, sql_catalog_id=self.destination_sql_catalog_id)
wrapped_destination_object_list.append(wrap_obj)
if wrapped_destination_object_list:
destination_catalog.catalogObjectList(wrapped_destination_object_list,**kw)
object_list[:] = failed_object_list
......@@ -886,6 +884,8 @@ class ZCatalog(Folder, Persistent, Implicit):
priority=archive.getPriority()).uncatalog_object(uid=uid,path=path,
sql_catalog_id=catalog_id)
catalog_id_list = self.getERP5CatalogIdList()
for sql_catalog_id in catalog_id_list:
catalog = self.getSQLCatalog(sql_catalog_id)
if catalog is not None:
catalog.uncatalogObject(uid=uid,path=path)
......@@ -901,6 +901,8 @@ class ZCatalog(Folder, Persistent, Implicit):
security.declarePrivate('beforeUncatalogObject')
def beforeUncatalogObject(self, uid=None,path=None, sql_catalog_id=None):
""" wrapper around catalog """
catalog_id_list = self.getERP5CatalogIdList()
for sql_catalog_id in catalog_id_list:
catalog = self.getSQLCatalog(sql_catalog_id)
if catalog is not None:
catalog.beforeUncatalogObject(uid=uid,path=path)
......
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