Commit 2fe9d8d0 authored by Ayush Tiwari's avatar Ayush Tiwari

erp5_catalog: Copy objects as well as properties from SQLCatalog to ERP5Catalog

We need objects as well as properties to be setup because objects inside Catalogs
are basically zsql_methods which is what is needed when we use the properties.

For example: making call to `new_erp5_catalog.sql_clear_catalog` would return
a tuple of zsql methods which are basically catalog objects.
Right now, we are copying everything from SQLCatalog to the new ERP5Catalog without
checking for any conflicts(which is why there might be some overwrite).
This is why its recommended to call the migration function only furing ERP5Site setup.
TODO: This overwriting would be fixed later on so to make the migration function
a bit more generic and use it anytime-anywhere.
parent b3243941
......@@ -1693,24 +1693,45 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
from Products.ERP5Type.dynamic.persistent_migration import PickleUpdater
from Products.ERP5Catalog.ERP5Catalog import ERP5Catalog
PickleUpdater(self)
# Getting ERP5 Catalog Tool
tool = self.portal_catalog
sql_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
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(
id = new_id,
title = '')
new_erp5_catalog = self._getOb('erp5_mysql_innodb_new')
# Copy data from erp5_mysql_innodb, which was the older SQL Catalog
catalog_data = self.portal_catalog.manage_copyObjects(ids=\
('erp5_mysql_innodb',))
# Paste catalog data from erp5_mysql_innodb which is a SQLCatalog.Catalog
# object to erp5_mysql_innodb_new, which is ERP5Catalog object
self.portal_catalog['erp5_mysql_innodb_new'].manage_pasteObjects(catalog_data)
new_erp5_catalog = self.portal_catalog._getOb('erp5_mysql_innodb_new')
# Copy-paste objects from SQLCatalog to ERP5Catalog
for id in sql_catalog.objectIds():
ob = sql_catalog._getOb(id)
# Check if the object is copyable
# The copying attributes are from OFS.CopySupport
if hasattr(ob, '_canCopy'):
# Get a copy of object for new conainer, i.e. new_erp5_catalog
ob = ob._getCopy(new_erp5_catalog)
ob._setId(id)
# Set the copied object in the new_erp5_catalog
new_erp5_catalog._setObject(id, ob)
ob = new_erp5_catalog._getOb(id)
ob._postCopy(new_erp5_catalog, op=0)
# Update properties list for the new catalog from the SQLCatalog
# Not an efficient way to carry this
for property_id in sql_catalog.propertyIds():
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
......@@ -2267,6 +2288,9 @@ class ERP5Generator(PortalGenerator):
self.setupWorkflow(p)
self.setupERP5Core(p,**kw)
self.setupERP5Promise(p,**kw)
# Make call to migration only after ERP5Core has been setup aas we'll need
# business templates.
p.migrateSQLCatalogToERP5Catalog()
# Make sure the cache is initialized
p.portal_caches.updateCache()
......
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