Commit bf424d9c authored by Jérome Perrin's avatar Jérome Perrin

BusinessTemplate: do not delete module when uninstalling ModuleTemplateItem

parent c020b284
Pipeline #20943 failed with stage
...@@ -7679,6 +7679,46 @@ class TestBusinessTemplate(BusinessTemplateMixin): ...@@ -7679,6 +7679,46 @@ class TestBusinessTemplate(BusinessTemplateMixin):
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self)
def test_uninstall_module(self):
"""ModuleTemplateItem are not uninstalled
"""
self.portal.newContent(
id='dummy_module',
portal_type='Folder')
self.tic()
bt = self.portal.portal_templates.newContent(
portal_type='Business Template',
title='test_bt_%s' % self.id(),
template_module_id_list=('dummy_module',))
self.tic()
bt.build()
self.tic()
export_dir = tempfile.mkdtemp()
try:
bt.export(path=export_dir, local=True)
self.tic()
new_bt = self.portal.portal_templates.download(
url='file:/%s' % export_dir)
finally:
shutil.rmtree(export_dir)
# modify the document
self.portal.manage_delObjects(ids=['dummy_module'])
self.tic()
# install the business template
new_bt.install()
self.tic()
self.assertIsNotNone(self.portal._getOb('dummy_module', None))
# uninstall the business template, the module should be kept
new_bt.uninstall()
self.tic()
self.assertIsNotNone(self.portal._getOb('dummy_module', None))
class _ZodbComponentTemplateItemMixin(BusinessTemplateMixin): class _ZodbComponentTemplateItemMixin(BusinessTemplateMixin):
""" """
Test cases for all Test*TemplateItem test classes. Test cases for all Test*TemplateItem test classes.
......
...@@ -3794,32 +3794,9 @@ class ModuleTemplateItem(BaseTemplateItem): ...@@ -3794,32 +3794,9 @@ class ModuleTemplateItem(BaseTemplateItem):
self._objects[file_name[:-4]] = mapping self._objects[file_name[:-4]] = mapping
def uninstall(self, context, **kw): def uninstall(self, context, **kw):
trash = kw.get('trash', 0) # Do not remove any module for safety.
if trash:
return
object_path = kw.get('object_path', None)
trashbin = kw.get('trashbin', None)
if object_path is None:
keys = self._archive.keys()
else:
keys = [object_path]
p = context.getPortalObject()
id_list = p.objectIds()
for key in keys:
if key in id_list:
try:
if trash and trashbin is not None:
container_path = key.split('/')
self.portal_trash.backupObject(trashbin, container_path,
key, save=1, keep_subobjects=1)
p.manage_delObjects([key])
except NotFound:
pass
BaseTemplateItem.uninstall(self, context, **kw) BaseTemplateItem.uninstall(self, context, **kw)
def trash(self, context, new_item, **kw):
# Do not remove any module for safety.
pass
# XXX-arnau: when everything has been migrated to Components, this class # XXX-arnau: when everything has been migrated to Components, this class
# should be removed and only _ZodbComponentTemplateItem should remain # should be removed and only _ZodbComponentTemplateItem should remain
......
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