Commit 02ba86cd authored by Ayush Tiwari's avatar Ayush Tiwari Committed by 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 6106323a
<?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 @@ ...@@ -86,7 +86,6 @@
<key> <string>right</string> </key> <key> <string>right</string> </key>
<value> <value>
<list> <list>
<string>my_default_sql_catalog_id</string>
<string>my_default_erp5_catalog_id</string> <string>my_default_erp5_catalog_id</string>
</list> </list>
</value> </value>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="StringField" module="Products.Formulator.StandardFields"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>my_default_sql_catalog_id</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
<item>
<key> <string>required_not_found</string> </key>
<value> <string>Input is required but no input given.</string> </value>
</item>
<item>
<key> <string>too_long</string> </key>
<value> <string>Too much input was given.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_maxwidth</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_width</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>input_type</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_length</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>truncate</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_maxwidth</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_width</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>input_type</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_length</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>truncate</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_maxwidth</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_width</string> </key>
<value> <int>20</int> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>input_type</string> </key>
<value> <string>text</string> </value>
</item>
<item>
<key> <string>max_length</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Default SQL Catalog</string> </value>
</item>
<item>
<key> <string>truncate</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <int>0</int> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -431,6 +431,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -431,6 +431,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
# Update some required attributes to the portal_catalog object # Update some required attributes to the portal_catalog object
parent.portal_catalog.default_erp5_catalog_id = self.default_sql_catalog_id parent.portal_catalog.default_erp5_catalog_id = self.default_sql_catalog_id
del parent.portal_catalog.default_sql_catalog_id
security.declarePublic('getPreferredSQLCatalogId') security.declarePublic('getPreferredSQLCatalogId')
def getPreferredSQLCatalogId(self, id=None): def getPreferredSQLCatalogId(self, id=None):
...@@ -440,7 +441,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -440,7 +441,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:
......
...@@ -113,23 +113,18 @@ class ERP5CatalogTool(BaseTool, CMFCore_CatalogTool): ...@@ -113,23 +113,18 @@ class ERP5CatalogTool(BaseTool, CMFCore_CatalogTool):
def _bootstrap(self): def _bootstrap(self):
pass pass
def _setDefaultErp5CatalogId(self, value): def getDefaultSqlCatalogId(self):
""" return self.default_erp5_catalog_id
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 _edit(self, **kw): def _setDefaultSqlCatalogId(self, value):
""" """
Override to update both default_sql_catalog_id and default_erp5_catalog_id Function to maintain compatibility between ZSQLCatalog and ERP5CatalogTool
in same edit
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) self.default_erp5_catalog_id = value
value = self.getDefaultErp5CatalogId()
self._setDefaultErp5CatalogId(value)
# Filter content (ZMI)) # Filter content (ZMI))
def filtered_meta_types(self, user=None): def filtered_meta_types(self, user=None):
...@@ -173,6 +168,9 @@ class ERP5CatalogTool(BaseTool, CMFCore_CatalogTool): ...@@ -173,6 +168,9 @@ class ERP5CatalogTool(BaseTool, CMFCore_CatalogTool):
return self._getOb(id, default_value) return self._getOb(id, default_value)
security.declarePublic('getSQLCatalog')
getSQLCatalog = getERP5Catalog # For compatibilty
security.declarePrivate('reindexCatalogObject') security.declarePrivate('reindexCatalogObject')
def reindexCatalogObject(self, object, idxs=None, sql_catalog_id=None,**kw): def reindexCatalogObject(self, object, idxs=None, sql_catalog_id=None,**kw):
'''Update catalog after object data has changed. '''Update catalog after object data has changed.
......
...@@ -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,22 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -197,19 +197,22 @@ 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
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.default_sql_catalog_id = 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 +259,7 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -256,7 +259,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 +286,7 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -283,7 +286,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 +384,8 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -381,8 +384,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.
...@@ -402,6 +405,12 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -402,6 +405,12 @@ class ZCatalog(Folder, Persistent, Implicit):
if sql_connection_id_dict is not None: if sql_connection_id_dict is not None:
self.changeSQLConnectionIds(self.portal_skins, sql_connection_id_dict) 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') security.declareProtected(manage_zcatalog_entries, 'manage_hotReindexAll')
def manage_hotReindexAll(self, source_sql_catalog_id, def manage_hotReindexAll(self, source_sql_catalog_id,
destination_sql_catalog_id, destination_sql_catalog_id,
...@@ -453,7 +462,7 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -453,7 +462,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