Commit 6151ae47 authored by Julien Muchembled's avatar Julien Muchembled

When upgrading a BT:

* Fix comparison of objects. This skips objects that have no modification.
* Stop hiding modified workflow subobjects.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24785 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4b27091a
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
# #
############################################################################## ##############################################################################
import sys import fnmatch, os, re, shutil, sys
from Shared.DC.ZRDB.Connection import Connection as RDBConnection from Shared.DC.ZRDB.Connection import Connection as RDBConnection
from Globals import Persistent, PersistentMapping from Globals import Persistent, PersistentMapping
from Acquisition import Implicit, aq_base from Acquisition import Implicit, aq_base
...@@ -54,8 +54,6 @@ from Products.ERP5Type.Utils import readLocalTest, \ ...@@ -54,8 +54,6 @@ from Products.ERP5Type.Utils import readLocalTest, \
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.RoleInformation import RoleInformation from Products.ERP5Type.RoleInformation import RoleInformation
import fnmatch
import re, os
from OFS.Traversable import NotFound from OFS.Traversable import NotFound
from OFS import XMLExportImport from OFS import XMLExportImport
from cStringIO import StringIO from cStringIO import StringIO
...@@ -77,7 +75,7 @@ from Products.ERP5Type import tarfile ...@@ -77,7 +75,7 @@ from Products.ERP5Type import tarfile
from urllib import quote, unquote from urllib import quote, unquote
from difflib import unified_diff from difflib import unified_diff
import posixpath import posixpath
import shutil import transaction
# those attributes from CatalogMethodTemplateItem are kept for # those attributes from CatalogMethodTemplateItem are kept for
# backward compatibility # backward compatibility
...@@ -609,34 +607,34 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -609,34 +607,34 @@ class ObjectTemplateItem(BaseTemplateItem):
self._objects[file_name[:-4]] = obj self._objects[file_name[:-4]] = obj
def preinstall(self, context, installed_bt, **kw): def preinstall(self, context, installed_bt, **kw):
#XXX -12 used here is -len('TemplateItem')
modified_object_list = {} modified_object_list = {}
if context.getTemplateFormatVersion() == 1: if context.getTemplateFormatVersion() == 1:
portal = context.getPortalObject() upgrade_list = []
new_keys = self._objects.keys() type_name = self.__class__.__name__.split('TemplateItem')[-2]
for path in new_keys: for path in self._objects:
if installed_bt._objects.has_key(path): if installed_bt._objects.has_key(path):
# compare object to see it there is changes upgrade_list.append((path,
new_object = self._objects[path] self.removeProperties(installed_bt._objects[path])))
old_object = installed_bt._objects[path]
old_object = self.removeProperties(old_object)
new_io = StringIO()
old_io = StringIO()
OFS.XMLExportImport.exportXML(new_object._p_jar, new_object._p_oid, new_io)
OFS.XMLExportImport.exportXML(old_object._p_jar, old_object._p_oid, old_io)
new_obj_xml = new_io.getvalue()
old_obj_xml = old_io.getvalue()
new_io.close()
old_io.close()
if new_obj_xml != old_obj_xml:
modified_object_list.update({path : ['Modified', self.__class__.__name__[:-12]]})
else: # new object else: # new object
modified_object_list.update({path : ['New', self.__class__.__name__[:-12]]}) modified_object_list[path] = 'New', type_name
# update _p_jar property of objects cleaned by removeProperties
transaction.savepoint(optimistic=True)
for path, old_object in upgrade_list:
# compare object to see it there is changes
new_object = self._objects[path]
new_io = StringIO()
old_io = StringIO()
OFS.XMLExportImport.exportXML(new_object._p_jar, new_object._p_oid, new_io)
OFS.XMLExportImport.exportXML(old_object._p_jar, old_object._p_oid, old_io)
new_obj_xml = new_io.getvalue()
old_obj_xml = old_io.getvalue()
new_io.close()
old_io.close()
if new_obj_xml != old_obj_xml:
modified_object_list[path] = 'Modified', type_name
# get removed object # get removed object
old_keys = installed_bt._objects.keys() for path in set(installed_bt._objects) - set(self._objects):
for path in old_keys: modified_object_list[path] = 'Removed', type_name
if path not in new_keys:
modified_object_list.update({path : ['Removed', self.__class__.__name__[:-12]]})
return modified_object_list return modified_object_list
def _backupObject(self, action, trashbin, container_path, object_id, **kw): def _backupObject(self, action, trashbin, container_path, object_id, **kw):
...@@ -1306,53 +1304,19 @@ class WorkflowTemplateItem(ObjectTemplateItem): ...@@ -1306,53 +1304,19 @@ class WorkflowTemplateItem(ObjectTemplateItem):
def __init__(self, id_list, tool_id='portal_workflow', **kw): def __init__(self, id_list, tool_id='portal_workflow', **kw):
return ObjectTemplateItem.__init__(self, id_list, tool_id=tool_id, **kw) return ObjectTemplateItem.__init__(self, id_list, tool_id=tool_id, **kw)
def preinstall(self, context, installed_bt, **kw):
modified_object_list = {}
if context.getTemplateFormatVersion() == 1:
portal = context.getPortalObject()
new_keys = self._objects.keys()
for path in new_keys:
if installed_bt._objects.has_key(path):
# compare object to see it there is changes
new_object = self._objects[path]
old_object = installed_bt._objects[path]
new_io = StringIO()
old_io = StringIO()
OFS.XMLExportImport.exportXML(new_object._p_jar, new_object._p_oid, new_io)
OFS.XMLExportImport.exportXML(old_object._p_jar, old_object._p_oid, old_io)
new_obj_xml = new_io.getvalue()
old_obj_xml = old_io.getvalue()
new_io.close()
old_io.close()
if new_obj_xml != old_obj_xml:
wf_id = path.split('/')[:2]
modified_object_list.update({'/'.join(wf_id) : ['Modified', 'Workflow']})
else: # new object
modified_object_list.update({path : ['New', 'Workflow']})
# get removed object
old_keys = installed_bt._objects.keys()
for path in old_keys:
if path not in new_keys:
modified_object_list.update({path : ['Removed', self.__class__.__name__[:-12]]})
return modified_object_list
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
if context.getTemplateFormatVersion() == 1: if context.getTemplateFormatVersion() == 1:
portal = context.getPortalObject() portal = context.getPortalObject()
# sort to add objects before their subobjects
keys = self._objects.keys()
keys.sort()
update_dict = kw.get('object_to_update') update_dict = kw.get('object_to_update')
force = kw.get('force') force = kw.get('force')
for path in keys: # sort to add objects before their subobjects
wf_path = '/'.join(path.split('/')[:2]) for path in sorted(self._objects):
if wf_path in update_dict or force: if force:
if not force:
action = update_dict[wf_path]
if action == 'nothing':
continue
else:
action = 'backup' action = 'backup'
else:
action = update_dict.get(path)
if action in (None, 'nothing'):
continue
container_path = path.split('/')[:-1] container_path = path.split('/')[:-1]
object_id = path.split('/')[-1] object_id = path.split('/')[-1]
try: try:
......
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