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

bt5_config: Add rebuildBusinessManager to have choice while rebuilding

parent 8b2e45ef
...@@ -469,6 +469,11 @@ class BusinessManager(Folder): ...@@ -469,6 +469,11 @@ class BusinessManager(Folder):
LOG('Business Manager', INFO, 'Building Business Manager') LOG('Business Manager', INFO, 'Building Business Manager')
removable_sub_object_path_list = kw.get('removable_sub_object_path', []) removable_sub_object_path_list = kw.get('removable_sub_object_path', [])
removable_property_dict = kw.get('removable_property', {}) removable_property_dict = kw.get('removable_property', {})
# Now, we need to put a check here for returning whih objects should be
# updated during rebuild of BM
checkNeeded = kw.get('checkNeeded', False)
# Build all paths if there is no check required(i.e, its a new build action)
if not checkNeeded:
if not no_action: if not no_action:
self.storeTemplateData(isBuild=True, **kw) self.storeTemplateData(isBuild=True, **kw)
for path_item in self.objectValues(): for path_item in self.objectValues():
...@@ -478,6 +483,13 @@ class BusinessManager(Folder): ...@@ -478,6 +483,13 @@ class BusinessManager(Folder):
kwargs['remove_sub_objects'] = item_path in removable_sub_object_path_list kwargs['remove_sub_objects'] = item_path in removable_sub_object_path_list
path_item.build(self, **kwargs) path_item.build(self, **kwargs)
return self return self
else:
item_path_list = kw.get('item_path_list', [])
if item_path_list:
for path in item_path_list:
item = self.getBusinessItemByPath(path)
item.build(self)
return self
def flattenBusinessManager(self): def flattenBusinessManager(self):
""" """
......
...@@ -1933,6 +1933,76 @@ class TemplateTool (BaseTool): ...@@ -1933,6 +1933,76 @@ class TemplateTool (BaseTool):
bm.setStatus('installed') bm.setStatus('installed')
def rebuildBusinessManager(self, bm):
"""
Compare the sub-objects in the Business Manager to the previous built
state to give user powet to decide on which item to rebuild.
"""
checkNeeded = True
changed_path_list = []
if bm.getBuildingState() not in ['built', 'modified']:
# In case the building_state is not built, we build the BM without
# comparing anything
checkNeeded = False
return checkNeeded, changed_path_list
portal = self.getPortalObject()
for item in bm.objectValues():
# Check for the change compared to old building state, i.e, if there is
# some change made at ZODB state(it also count changes made due to
# change while installation of other BM)
path = item.getProperty('item_path')
try:
if item.isProperty:
# Get the value for Business Property Item
value = item.getProperty('item_property_value')
# Get the value at ZODB
relative_url, property_id = path.split('#')
obj = portal.restrictedTraverse(relative_url)
property_value = obj.getProperty(property_id)
# If the value at ZODB for the property is none, raise KeyError
# This is important to have compatibility between the way we check
# path as well as property. Otherwise, if we install a new property,
# we are always be getting an Error that there is change made at
# ZODB for this property
if not property_value:
raise KeyError
obj = property_value
else:
# Get the value of the Business Path Item
value_list = item.objectValues()
if value_list:
value = value_list[0]
else:
# If there is no value, it means the path_item is new, thus no
# need to comapre hash and check anything
changed_path_list.append((path, 'New'))
continue
# Get the object at ZODB
obj = portal.restrictedTraverse(path)
# Calculate hash for value at ZODB
obj_sha = self.calculateComparableHash(obj, item.isProperty)
# Calculate hash for value at property_value
item_sha = self.calculateComparableHash(value, item.isProperty)
# Compare the hash with the item hash
if obj_sha != item_sha:
changed_path_list.append((path, 'Changed'))
else:
changed_path_list.append((path, 'Unchanged'))
# KeyError is raised in case the value/object has been deleted at ZODB
except KeyError:
changed_path_list.append((path, 'Deleted'))
return checkNeeded, changed_path_list
security.declareProtected(Permissions.ManagePortal, security.declareProtected(Permissions.ManagePortal,
'updateInstallationState') 'updateInstallationState')
def compareInstallationState(self, bm_list): def compareInstallationState(self, bm_list):
......
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