Commit 350c51fd authored by Ayush Tiwari's avatar Ayush Tiwari

erp5_catalog: Use migration function to update ERP5Catalog object also.

Earlier, migrateSQLCatalogToERP5Catalog was used only for creating a new ERP5Catalog
and then migrating the objects and properties from sql catalog to this new ERP5 catalog.
This sometimes led to the problem while we install new business templates which do have
Catalog methods. So, the soluton to this is to update this migration function to do the
updation part also. So now we can call this function everytime after we install a BT5
and it'll create/update ERP5Catalog as per needed.

Please note that this hack is not an efficient way to carry this process. Instead the
better option imho(Ayush) is to change completely the BT5 methods structure of handling
Catalog methods which at present time have hardcoded sql_catalog name attached to their
paths.
parent 79d1e814
......@@ -1687,7 +1687,14 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
This function should be run at the end of ERP5 Site installation so as to
maintain consistency for the objects.
We will also shift the default_sql_catalog_id to the new catalog object.
UPDATE: This function could be called from anywhere in ERP5, cause it will
update the objects and properties of ERP5Catalog if it already exists.
For example: We can use it to run everytime after we install a business
template which might be updating CatalogTemplateMethodItems.
Now, we don't shift the default_sql_catalog_id, instead we have a new
property default_erp5_catalog_id and functions like getERP5Catalog and
getERP5CatalogIdList whose usage is recommended.
"""
# We'll be migrating Persistent Objects
from Products.ERP5Type.dynamic.persistent_migration import PickleUpdater
......@@ -1695,24 +1702,30 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
PickleUpdater(self)
# Getting ERP5 Catalog Tool
tool = self.portal_catalog
sql_catalog = tool.getSQLCatalog()
catalog_tool = self.portal_catalog
sql_catalog = catalog_tool.getSQLCatalog()
new_id = 'erp5_mysql_innodb_new'
# If there is no default SQL Catalog installed already, add a warning log
# in ERP5Site and break the migration
if not sql_catalog:
from Products.ERPType.Log import log
from Products.ERP5Type.Log import log
warning_message = 'No SQLCatlaog found out. No migration going to happen'
log(warning_message)
return
if not isinstance(sql_catalog, ERP5Catalog) and new_id \
not in self.portal_catalog.keys():
# Create new ERP5 Catalog
self.portal_catalog.manage_addProduct['ERP5Catalog'].manage_addERP5Catalog(
not in catalog_tool.keys():
if not new_id in catalog_tool.objectIds():
# Create new ERP5Catalog object if it doesn't exist
catalog_tool.manage_addProduct['ERP5Catalog'].manage_addERP5Catalog(
id = new_id,
title = '')
new_erp5_catalog = self.portal_catalog._getOb('erp5_mysql_innodb_new')
new_erp5_catalog = catalog_tool._getOb(new_id)
# No need to migrate if the new_erp5_catalog is not an object of ERP5Catlog
if not isinstance(new_erp5_catalog, ERP5Catalog):
return
# Copy-paste objects from SQLCatalog to ERP5Catalog
for id in sql_catalog.objectIds():
ob = sql_catalog._getOb(id)
......@@ -1737,8 +1750,9 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
value = getattr(sql_catalog, property_id)
new_erp5_catalog._updateProperty(id=property_id, value=value)
# Use the new ERP5Catalog object as the default sql catalog
self.portal_catalog.default_sql_catalog_id = new_id
# Update default erp5 catalog id, everytime we run migration
# ERP5 Catalog(basically when this fucntion is called while creating ERP5Site)
catalog_tool.default_erp5_catalog_id = new_id
Globals.InitializeClass(ERP5Site)
......
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