Commit cbe91644 authored by Aurel's avatar Aurel

allow to make diff of objects with the one in zodb


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4965 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1aacac22
...@@ -3215,15 +3215,22 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -3215,15 +3215,22 @@ Business Template is a set of definitions, such as skins, portal types and categ
modified_object_list = {} modified_object_list = {}
bt_title = self.getTitle() bt_title = self.getTitle()
installed_bt = self.portal_templates.getInstalledBusinessTemplate(title=bt_title)
# can be call to diff two Business Template in template tool
bt2 = kw.get('compare_to', None)
if bt2 is not None:
installed_bt = bt2
else:
installed_bt = self.portal_templates.getInstalledBusinessTemplate(title=bt_title)
if installed_bt is None: if installed_bt is None:
installed_bt_format = 0 # that will not check for modification installed_bt_format = 0 # that will not check for modification
else: else:
installed_bt_format = installed_bt.getTemplateFormatVersion() installed_bt_format = installed_bt.getTemplateFormatVersion()
# if reinstall business template, must compare to object in ZODB # if reinstall business template, must compare to object in ZODB
# and not to those in the installed Business Template because it is itself # and not to those in the installed Business Template because it is itself.
reinstall = 0 # same if we make a diff and selected only one business template
reinstall = 0
if installed_bt == self: if installed_bt == self:
reinstall = 1 reinstall = 1
bt2 = self.portal_templates.manage_clone(ob=installed_bt, id='installed_bt_for_diff') bt2 = self.portal_templates.manage_clone(ob=installed_bt, id='installed_bt_for_diff')
...@@ -3232,11 +3239,6 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -3232,11 +3239,6 @@ Business Template is a set of definitions, such as skins, portal types and categ
bt2.edit(description='tmp bt generated for diff') bt2.edit(description='tmp bt generated for diff')
bt2.build() bt2.build()
installed_bt = bt2 installed_bt = bt2
# can be call to diff two Business Template in template tool
bt2 = kw.get('compare_to', None)
if bt2 is not None:
installed_bt = bt2
new_bt_format = self.getTemplateFormatVersion() new_bt_format = self.getTemplateFormatVersion()
if installed_bt_format == 0 and new_bt_format == 0: if installed_bt_format == 0 and new_bt_format == 0:
...@@ -3250,7 +3252,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -3250,7 +3252,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
for path in item._objects.keys(): for path in item._objects.keys():
modified_object_list.update({path : ['New', item.__class__.__name__[:-12]]}) modified_object_list.update({path : ['New', item.__class__.__name__[:-12]]})
return modified_object_list return modified_object_list
# get the list of modified and new object # get the list of modified and new object
self.portal_templates.updateLocalConfiguration(self, **kw) self.portal_templates.updateLocalConfiguration(self, **kw)
local_configuration = self.portal_templates.getLocalConfiguration(self) local_configuration = self.portal_templates.getLocalConfiguration(self)
...@@ -3259,6 +3261,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -3259,6 +3261,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
old_item = getattr(installed_bt, item_name, None) old_item = getattr(installed_bt, item_name, None)
if new_item is not None: if new_item is not None:
if old_item is not None: if old_item is not None:
LOG('compare object item', 0, item_name)
modified_object = new_item.preinstall(context=local_configuration, installed_bt=old_item) modified_object = new_item.preinstall(context=local_configuration, installed_bt=old_item)
if len(modified_object) > 0: if len(modified_object) > 0:
modified_object_list.update(modified_object) modified_object_list.update(modified_object)
...@@ -3759,9 +3762,19 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -3759,9 +3762,19 @@ Business Template is a set of definitions, such as skins, portal types and categ
new_bt =self new_bt =self
# compare with a given business template # compare with a given business template
compare_to_zodb = 0
bt2_id = kw.get('compare_with', None) bt2_id = kw.get('compare_with', None)
if bt2_id is not None: if bt2_id is not None:
installed_bt = self.portal_templates._getOb(bt2_id) if bt2_id == self.getId():
compare_to_zodb = 1
installed_bt = self.getInstalledBusinessTemplate(title=self.getTitle())
bt2 = self.portal_templates.manage_clone(ob=installed_bt, id='installed_bt_for_diff')
# update portal types properties to get last modifications
bt2.getPortalTypesProperties()
bt2.edit(description='tmp bt generated for diff')
installed_bt = bt2
else:
installed_bt = self.portal_templates._getOb(bt2_id)
else: else:
installed_bt = self.getInstalledBusinessTemplate(title=self.getTitle()) installed_bt = self.getInstalledBusinessTemplate(title=self.getTitle())
if installed_bt == new_bt: if installed_bt == new_bt:
...@@ -3769,6 +3782,8 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -3769,6 +3782,8 @@ Business Template is a set of definitions, such as skins, portal types and categ
new_item = getattr(new_bt, item_name) new_item = getattr(new_bt, item_name)
installed_item = getattr(installed_bt, item_name) installed_item = getattr(installed_bt, item_name)
if compare_to_zodb:
installed_item.build(self)
new_object = new_item._objects[object_id] new_object = new_item._objects[object_id]
installed_object = installed_item._objects[object_id] installed_object = installed_item._objects[object_id]
# make diff # make diff
...@@ -3820,6 +3835,9 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -3820,6 +3835,9 @@ Business Template is a set of definitions, such as skins, portal types and categ
diff_msg += '\n'.join(diff_list) diff_msg += '\n'.join(diff_list)
else: else:
diff_msg = 'No diff' diff_msg = 'No diff'
if compare_to_zodb:
self.portal_templates.manage_delObjects(ids=['installed_bt_for_diff'])
return diff_msg return diff_msg
......
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