Commit 3ae7d5d9 authored by Ayush Tiwari's avatar Ayush Tiwari

ZSQLCatalog: Add getter and setter for default_sql_catalog_id in CatalogTool

parent d1a6b249
...@@ -369,7 +369,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -369,7 +369,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
if id is None: if id is None:
# Check if we want to use an archive # Check if we want to use an archive
#if getattr(aq_base(self.portal_preferences), 'uid', None) is not None: #if getattr(aq_base(self.portal_preferences), 'uid', None) is not None:
archive_path = self.portal_preferences.getPreferredArchive(sql_catalog_id=self.default_sql_catalog_id) archive_path = self.portal_preferences.getPreferredArchive(sql_catalog_id=self.getDefaultSqlCatalogId())
if archive_path not in ('', None): if archive_path not in ('', None):
try: try:
archive = self.restrictedTraverse(archive_path) archive = self.restrictedTraverse(archive_path)
......
...@@ -78,7 +78,7 @@ class ArchiveTool(BaseTool): ...@@ -78,7 +78,7 @@ class ArchiveTool(BaseTool):
""" """
Return the archive used for the current catalog Return the archive used for the current catalog
""" """
current_catalog = self.portal_catalog.default_sql_catalog_id current_catalog = self.portal_catalog.getDefaultSqlCatalogId()
current_archive_list = [x.getObject() for x in self.searchFolder(validation_state="validated") \ current_archive_list = [x.getObject() for x in self.searchFolder(validation_state="validated") \
if x.getCatalogId() == current_catalog] if x.getCatalogId() == current_catalog]
if len(current_archive_list) == 0: if len(current_archive_list) == 0:
......
...@@ -115,7 +115,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor): ...@@ -115,7 +115,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
def beforeTearDown(self): def beforeTearDown(self):
# restore default_catalog # restore default_catalog
self.portal.portal_catalog.default_sql_catalog_id = 'erp5_mysql_innodb' self.portal.portal_catalog._setDefaultSqlCatalogId('erp5_mysql_innodb')
self.portal.portal_catalog.hot_reindexing_state = None self.portal.portal_catalog.hot_reindexing_state = None
# clear Modules # clear Modules
for module in [ self.getPersonModule(), for module in [ self.getPersonModule(),
......
...@@ -197,19 +197,26 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -197,19 +197,26 @@ class ZCatalog(Folder, Persistent, Implicit):
def getSQLCatalogIdList(self): def getSQLCatalogIdList(self):
return self.objectIds(spec=('SQLCatalog',)) return self.objectIds(spec=('SQLCatalog',))
def getDefaultSqlCatalogId(self):
return self.default_sql_catalog_id
def _setDefaultSqlCatalogId(self, value):
if value:
self.default_sql_catalog_id = value
security.declarePublic('getSQLCatalog') security.declarePublic('getSQLCatalog')
def getSQLCatalog(self, id=None, default_value=None): def getSQLCatalog(self, id=None, default_value=None):
""" """
Get the default SQL Catalog. Get the default SQL Catalog.
""" """
if id is None: if id is None:
if not self.default_sql_catalog_id: if not self.getDefaultSqlCatalogId():
id_list = self.getSQLCatalogIdList() id_list = self.getSQLCatalogIdList()
if len(id_list) > 0: if len(id_list) > 0:
self.default_sql_catalog_id = id_list[0] self._setDefaultSqlCatalogId(id_list[0])
else: else:
return default_value return default_value
id = self.default_sql_catalog_id id = self.getDefaultSqlCatalogId()
return self._getOb(id, default_value) return self._getOb(id, default_value)
...@@ -256,7 +263,7 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -256,7 +263,7 @@ class ZCatalog(Folder, Persistent, Implicit):
""" """
#LOG("_setHotReindexingState call", 300, state) #LOG("_setHotReindexingState call", 300, state)
if source_sql_catalog_id is None: if source_sql_catalog_id is None:
source_sql_catalog_id = self.default_sql_catalog_id source_sql_catalog_id = self.getDefaultSqlCatalogId()
if state == HOT_REINDEXING_FINISHED_STATE: if state == HOT_REINDEXING_FINISHED_STATE:
self.hot_reindexing_state = None self.hot_reindexing_state = None
...@@ -283,7 +290,7 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -283,7 +290,7 @@ class ZCatalog(Folder, Persistent, Implicit):
current_archive = self.portal_archives.getCurrentArchive() current_archive = self.portal_archives.getCurrentArchive()
else: else:
current_archive = None current_archive = None
default_catalog_id = self.default_sql_catalog_id default_catalog_id = self.getDefaultSqlCatalogId()
self._exchangeDatabases(source_sql_catalog_id=source_sql_catalog_id, self._exchangeDatabases(source_sql_catalog_id=source_sql_catalog_id,
destination_sql_catalog_id=destination_sql_catalog_id, destination_sql_catalog_id=destination_sql_catalog_id,
skin_selection_dict=skin_selection_dict, skin_selection_dict=skin_selection_dict,
...@@ -381,8 +388,8 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -381,8 +388,8 @@ class ZCatalog(Folder, Persistent, Implicit):
""" """
Exchange two databases. Exchange two databases.
""" """
if self.default_sql_catalog_id == source_sql_catalog_id: if self.getDefaultSqlCatalogId() == source_sql_catalog_id:
self.default_sql_catalog_id = destination_sql_catalog_id self._setDefaultSqlCatalogId(destination_sql_catalog_id)
id_tool = getattr(self.getPortalObject(), 'portal_ids', None) id_tool = getattr(self.getPortalObject(), 'portal_ids', None)
if id_tool is None: if id_tool is None:
# Insert the latest generated uid. # Insert the latest generated uid.
...@@ -453,7 +460,7 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -453,7 +460,7 @@ class ZCatalog(Folder, Persistent, Implicit):
' you want to do is a "clear catalog" and an '\ ' you want to do is a "clear catalog" and an '\
'"ERP5Site_reindexAll".' '"ERP5Site_reindexAll".'
if source_sql_catalog_id != self.default_sql_catalog_id: if source_sql_catalog_id != self.getDefaultSqlCatalogId():
LOG('ZSQLCatalog', 0, 'Warning : Hot reindexing is started with a '\ LOG('ZSQLCatalog', 0, 'Warning : Hot reindexing is started with a '\
'source catalog which is not the default one.') 'source catalog which is not the default one.')
......
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