Commit 91e5f5a4 authored by Ayush Tiwari's avatar Ayush Tiwari Committed by Ayush Tiwari

bt5_prototype: Add removable_property parameter while building BP for path items

This will help in neglecting the properties and then save them in ObjectPropertyTempaltePackageItem.
This saves us from exporting properties twice, once with object and other with object path.

For ex:
BP5 erp5_mysql_innodb_catalog can be saved as
erp5_mysql_innodb.xml (but without all properties)
object_property_list.xml (keeping track of specific properties for erp5_mysql_innodb)
parent 93f68c1b
......@@ -154,15 +154,18 @@ class BusinessPackage(XMLObject):
return {}
security.declareProtected(Permissions.ManagePortal, 'build')
def build(self, no_action=False):
def build(self, no_action=False, **kw):
"""
Should also export the objects from PathTemplateItem to their xml format
"""
if not no_action:
self.storePathData()
# XXX: Explicitly calling build for items. Needs to be changed
self._path_item.build(self)
self._path_item.build(self, **kw)
try:
self._object_property_item.build(self)
except Exception:
import pdb; pdb.set_trace()
pass
security.declareProtected(Permissions.ManagePortal, 'storePathData')
......@@ -186,7 +189,7 @@ class BusinessPackage(XMLObject):
return result
security.declareProtected(Permissions.ManagePortal, 'export')
def export(self, path=None, local=0, bpa=None):
def export(self, path=None, local=0, bpa=None, **kw):
"""
Export the object
XXX: Are we planning to use something like archive for saving the exported
......@@ -194,9 +197,9 @@ class BusinessPackage(XMLObject):
"""
if not self.getBuildingState() == 'built':
raise BusinessPackageException, 'Package not built properly'
return self._export(path, local, bpa)
return self._export(path, local, bpa, **kw)
def _export(self, path=None, local=0, bpa=None):
def _export(self, path=None, local=0, bpa=None, **kw):
if bpa is None:
if local:
# we export into a folder tree
......@@ -227,7 +230,7 @@ class BusinessPackage(XMLObject):
for item_name in item_name_list:
item = getattr(self, item_name, None)
if item is not None:
item.export(context=self, bpa=bpa)
item.export(context=self, bpa=bpa, **kw)
return bpa.finishCreation()
......@@ -499,6 +502,7 @@ class PathTemplatePackageItem(Implicit, Persistent):
def removeProperties(self,
obj,
export,
properties=[],
keep_workflow_history=False,
keep_workflow_history_last_history_only=False):
"""
......@@ -507,10 +511,14 @@ class PathTemplatePackageItem(Implicit, Persistent):
obj._p_activate()
klass = obj.__class__
classname = klass.__name__
attr_set = {'_dav_writelocks', '_filepath', '_owner', '_related_index',
'last_id', 'uid',
'__ac_local_roles__', '__ac_local_roles_group_id_dict__'}
if properties:
for prop in properties:
if prop.endswith('_list'):
prop = prop[:-5]
attr_set.add(prop)
if export:
if keep_workflow_history_last_history_only:
self._removeAllButLastWorkflowHistory(obj)
......@@ -572,6 +580,9 @@ class PathTemplatePackageItem(Implicit, Persistent):
keys = self._path_archive.keys()
keys.sort()
hash_func = hashlib.sha1
# Check for properties_removed in kwargs
removable_property_dict = kw.get('removable_property', {})
removable_property_obj_list = removable_property_dict.keys()
for path in keys:
include_subobjects = 0
if path.endswith("**"):
......@@ -582,8 +593,12 @@ class PathTemplatePackageItem(Implicit, Persistent):
obj = obj.__of__(context)
_recursiveRemoveUid(obj)
id_list = obj.objectIds()
# Create list of properties which needed to be removed before export
removable_property_list = []
if path in removable_property_obj_list:
removable_property_list = removable_property_dict.get(path)
# XXX: This doesn't take care of workflow objects
obj = self.removeProperties(obj, 1)
obj = self.removeProperties(obj, 1, properties=removable_property_list)
if hasattr(aq_base(obj), 'groups'):
# we must keep groups because it's ereased when we delete subobjects
groups = deepcopy(obj.groups)
......
......@@ -596,6 +596,7 @@ class TemplateTool (BaseTool):
portal_path = self.getPortalObject()
template_path_list = []
property_path_list = []
# For modules, we don't need to create path for the module
module_list = import_template.getTemplateModuleIdList()
......@@ -666,26 +667,83 @@ class TemplateTool (BaseTool):
template_catalog_security_uid_column = import_template.getTemplateCatalogSecurityUidColumnList()
template_catalog_topic_key = import_template.getTemplateCatalogTopicKeyList()
catalog_property_list = [
template_catalog_datetime_key,
template_catalog_full_text_key,
template_catalog_keyword_key,
template_catalog_local_role_key,
template_catalog_multivalue_key,
template_catalog_related_key,
template_catalog_request_key,
template_catalog_result_key,
template_catalog_result_table,
template_catalog_role_key,
template_catalog_scriptable_key,
template_catalog_search_key,
template_catalog_security_uid_column,
template_catalog_topic_key,
]
is_property_added = any(catalog_property_list)
properties_removed = [
'sql_catalog_datetime_search_keys_list',
'sql_catalog_full_text_search_keys_list',
'sql_catalog_keyword_search_keys_list',
'sql_catalog_local_role_keys_list',
'sql_catalog_multivalue_keys_list',
'sql_catalog_related_keys_list',
'sql_catalog_request_keys_list',
'sql_search_result_keys_list',
'sql_search_tables_list',
'sql_catalog_role_keys_list',
'sql_catalog_scriptable_keys_list',
'sql_catalog_search_keys_list',
'sql_catalog_security_uid_columns_list',
'sql_catalog_topic_search_keys_list'
]
removable_property = {}
if is_property_added:
if catalog_method_path_list:
catalog_path = catalog_method_path_list[0].rsplit('/', 1)[0]
else:
catalog_path = 'portal_catalog/erp5_mysql_innodb'
template_path_list.append(catalog_path)
removable_property[catalog_path] = properties_removed
for prop in properties_removed:
property_path_list.append(catalog_path + ' | ' + prop)
# Add these catalog items in the object_property instead of adding
# dummy path item for them
property_path_list = []
if import_template.getTitle() == 'erp5_mysql_innodb_catalog':
template_path_list.extend('portal_catalog/erp5_mysql_innodb')
# Check if any catalog property exists and if yes, then we export the
# erp5_mysql_innodb object and use it for installation
# Add portal_property_sheets
property_sheet_id_list = import_template.getTemplatePropertySheetIdList()
property_sheet_path_list = []
for property_sheet in property_sheet_id_list:
property_sheet_path_list.append('portal_property_sheets/' + property_sheet)
property_sheet_path_list.append('portal_property_sheets/' + property_sheet + '/**')
template_path_list.extend(property_sheet_path_list)
# Create new objects for business package
bp5_package = self.newContent(
portal_type='Business Package',
title=import_package.getTitle()
title=import_template.getTitle()
)
bp5_package.edit(template_path_list=template_path_list)
bp5_package.build()
bp5_package.edit(
template_path_list=template_path_list,
template_object_property_list=property_path_list
)
kw['removable_property'] = removable_property
bp5_package.build(**kw)
# Export the newly built business package to the export directory
bp5_package.export(path=export_dir, local=True)
if is_installed:
import_package.uninstall()
import_template.uninstall()
security.declareProtected( 'Import/Export objects', 'migrateBTListToBP')
def migrateBTListToBP(self, repository_list, REQUEST=None, **kw):
......
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