Commit 7b1e04cf authored by Ayush Tiwari's avatar Ayush Tiwari

erp5_catalog: Remove usage of default_sql_catalog_id attribute from ERP5CatalogTool class

For compatibilty, we have added 2 extra functions, but in no way we need
to use this attribute as it doesn't give any meaning for ERP5CatalogTool
to have a default SQL Catalog.
parent 0481f1bb
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Standard Property" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_local_properties</string> </key>
<value>
<tuple>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>select_variable</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>string</string> </value>
</item>
</dictionary>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>mode</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>string</string> </value>
</item>
</dictionary>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>elementary_type/string</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>The id of the default SQL Catalog</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>default_sql_catalog_id_property</string> </value>
</item>
<item>
<key> <string>mode</string> </key>
<value> <string>w</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Standard Property</string> </value>
</item>
<item>
<key> <string>select_variable</string> </key>
<value> <string>getSQLCatalogIdList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -86,7 +86,6 @@
<key> <string>right</string> </key>
<value>
<list>
<string>my_default_sql_catalog_id</string>
<string>my_default_erp5_catalog_id</string>
</list>
</value>
......
......@@ -403,6 +403,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
# Update some required attributes to the portal_catalog object
parent.portal_catalog.default_erp5_catalog_id = self.default_sql_catalog_id
del parent.portal_catalog.default_sql_catalog_id
security.declarePublic('getPreferredSQLCatalogId')
def getPreferredSQLCatalogId(self, id=None):
......@@ -412,7 +413,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
if id is None:
# Check if we want to use an archive
#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):
try:
archive = self.restrictedTraverse(archive_path)
......
......@@ -78,7 +78,7 @@ class ArchiveTool(BaseTool):
"""
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") \
if x.getCatalogId() == current_catalog]
if len(current_archive_list) == 0:
......
......@@ -112,23 +112,18 @@ class ERP5CatalogTool(BaseTool, CMFCore_CatalogTool):
def _bootstrap(self):
pass
def _setDefaultErp5CatalogId(self, value):
"""
Override this setter function so as to keep default_sql_catalog_id
and default_erp5_catalog_id same for portal_catalog after everyhting has
been migrated to erp5 portal_catalog
"""
self._baseSetDefaultErp5CatalogId(value)
self._baseSetDefaultSqlCatalogId(value)
def getDefaultSqlCatalogId(self):
return self.default_erp5_catalog_id
def _edit(self, **kw):
def _setDefaultSqlCatalogId(self, value):
"""
Override to update both default_sql_catalog_id and default_erp5_catalog_id
in same edit
Function to maintain compatibility between ZSQLCatalog and ERP5CatalogTool
Notice that we update the attribute `default_erp5_catalog_id` here and not
the property. This is because there maybe cases(migration) whern we don't
have accessors defined and there we'll need the attribute.
"""
BaseTool._edit(self, **kw)
value = self.getDefaultErp5CatalogId()
self._setDefaultErp5CatalogId(value)
self.default_erp5_catalog_id = value
# Filter content (ZMI))
def filtered_meta_types(self, user=None):
......@@ -172,6 +167,9 @@ class ERP5CatalogTool(BaseTool, CMFCore_CatalogTool):
return self._getOb(id, default_value)
security.declarePublic('getSQLCatalog')
getSQLCatalog = getERP5Catalog # For compatibilty
security.declarePrivate('reindexCatalogObject')
def reindexCatalogObject(self, object, idxs=None, sql_catalog_id=None,**kw):
'''Update catalog after object data has changed.
......
......@@ -115,7 +115,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
def beforeTearDown(self):
# 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
# clear Modules
for module in [ self.getPersonModule(),
......
......@@ -197,19 +197,22 @@ class ZCatalog(Folder, Persistent, Implicit):
def getSQLCatalogIdList(self):
return self.objectIds(spec=('SQLCatalog',))
def getDefaultSqlCatalogId(self):
return self.default_sql_catalog_id
security.declarePublic('getSQLCatalog')
def getSQLCatalog(self, id=None, default_value=None):
"""
Get the default SQL Catalog.
"""
if id is None:
if not self.default_sql_catalog_id:
if not self.getDefaultSqlCatalogId():
id_list = self.getSQLCatalogIdList()
if len(id_list) > 0:
self.default_sql_catalog_id = id_list[0]
else:
return default_value
id = self.default_sql_catalog_id
id = self.getDefaultSqlCatalogId()
return self._getOb(id, default_value)
......@@ -256,7 +259,7 @@ class ZCatalog(Folder, Persistent, Implicit):
"""
#LOG("_setHotReindexingState call", 300, state)
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:
self.hot_reindexing_state = None
......@@ -283,7 +286,7 @@ class ZCatalog(Folder, Persistent, Implicit):
current_archive = self.portal_archives.getCurrentArchive()
else:
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,
destination_sql_catalog_id=destination_sql_catalog_id,
skin_selection_dict=skin_selection_dict,
......@@ -381,8 +384,8 @@ class ZCatalog(Folder, Persistent, Implicit):
"""
Exchange two databases.
"""
if self.default_sql_catalog_id == source_sql_catalog_id:
self.default_sql_catalog_id = destination_sql_catalog_id
if self.getDefaultSqlCatalogId() == source_sql_catalog_id:
self._setDefaultSqlCatalogId(destination_sql_catalog_id)
id_tool = getattr(self.getPortalObject(), 'portal_ids', None)
if id_tool is None:
# Insert the latest generated uid.
......@@ -402,6 +405,12 @@ class ZCatalog(Folder, Persistent, Implicit):
if sql_connection_id_dict is not None:
self.changeSQLConnectionIds(self.portal_skins, sql_connection_id_dict)
def _setDefaultSqlCatalogId(self, value):
'''
Separate this part for compatibilty between CatalogTool and ERP5CatalogTool
'''
self.default_sql_catalog_id = value
security.declareProtected(manage_zcatalog_entries, 'manage_hotReindexAll')
def manage_hotReindexAll(self, source_sql_catalog_id,
destination_sql_catalog_id,
......@@ -453,7 +462,7 @@ class ZCatalog(Folder, Persistent, Implicit):
' you want to do is a "clear catalog" and an '\
'"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 '\
'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