Commit e4abada6 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Upgrade support was not commited.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2219 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f1ee867e
...@@ -66,6 +66,10 @@ class BaseTemplateItem(Implicit, Persistent): ...@@ -66,6 +66,10 @@ class BaseTemplateItem(Implicit, Persistent):
def uninstall(self, context, **kw): def uninstall(self, context, **kw):
pass pass
def trash(self, context, new_item, **kw):
# trash is quite similar to uninstall.
return self.uninstall(context, new_item=new_item, trash=1, **kw)
class ObjectTemplateItem(BaseTemplateItem): class ObjectTemplateItem(BaseTemplateItem):
""" """
This class is used for generic objects and as a subclass. This class is used for generic objects and as a subclass.
...@@ -90,11 +94,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -90,11 +94,7 @@ class ObjectTemplateItem(BaseTemplateItem):
self._archive[relative_url] = object self._archive[relative_url] = object
object.wl_clearLocks() object.wl_clearLocks()
def _backupObject(self, container, object_id, **kw):
def _handleConflict(self, container, object_id, **kw):
raise TemplateConflictError, '%s conflicts in %s' % (object_id, container.id)
# This below is not used.
container_ids = container.objectIds() container_ids = container.objectIds()
n = 0 n = 0
new_object_id = object_id new_object_id = object_id
...@@ -113,7 +113,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -113,7 +113,7 @@ class ObjectTemplateItem(BaseTemplateItem):
#LOG('Installing' , 0, '%s in %s with %s' % (self.id, container.getPhysicalPath(), self.export_string)) #LOG('Installing' , 0, '%s in %s with %s' % (self.id, container.getPhysicalPath(), self.export_string))
container_ids = container.objectIds() container_ids = container.objectIds()
if object_id in container_ids: # Object already exists if object_id in container_ids: # Object already exists
self._handleConflict(container, object_id) self._backupObject(container, object_id)
# Set a hard link # Set a hard link
#if not object.cb_isCopyable(): #if not object.cb_isCopyable():
# raise CopyError, eNotSupported % escape(relative_url) # raise CopyError, eNotSupported % escape(relative_url)
...@@ -130,12 +130,20 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -130,12 +130,20 @@ class ObjectTemplateItem(BaseTemplateItem):
def uninstall(self, context, **kw): def uninstall(self, context, **kw):
portal = context.getPortalObject() portal = context.getPortalObject()
trash = kw.get('trash', 0)
for relative_url in self._archive.keys(): for relative_url in self._archive.keys():
container_path = relative_url.split('/')[0:-1] container_path = relative_url.split('/')[0:-1]
object_id = relative_url.split('/')[-1] object_id = relative_url.split('/')[-1]
try:
container = portal.unrestrictedTraverse(container_path) container = portal.unrestrictedTraverse(container_path)
if trash:
self._backupObject(container, object_id)
else:
if object_id in container.objectIds(): if object_id in container.objectIds():
container.manage_delObjects([object_id]) container.manage_delObjects([object_id])
except:
pass
BaseTemplateItem.uninstall(self, context, **kw) BaseTemplateItem.uninstall(self, context, **kw)
...@@ -240,6 +248,7 @@ class SkinTemplateItem(ObjectTemplateItem): ...@@ -240,6 +248,7 @@ class SkinTemplateItem(ObjectTemplateItem):
if skin_id not in skin_id_list: if skin_id not in skin_id_list:
new_selection.append(skin_id) new_selection.append(skin_id)
ps.manage_skinLayers(skinpath = tuple(new_selection), skinname = skin_name, add_skin = 1) ps.manage_skinLayers(skinpath = tuple(new_selection), skinname = skin_name, add_skin = 1)
ObjectTemplateItem.uninstall(self, context, **kw) ObjectTemplateItem.uninstall(self, context, **kw)
...@@ -257,7 +266,7 @@ class PortalTypeTemplateItem(ObjectTemplateItem): ...@@ -257,7 +266,7 @@ class PortalTypeTemplateItem(ObjectTemplateItem):
""" """
This is used in order to construct the full list This is used in order to construct the full list
of mapping between type and list of workflow associated of mapping between type and list of workflow associated
This is only usefull in order to use This is only useful in order to use
portal_workflow.manage_changeWorkflows portal_workflow.manage_changeWorkflows
""" """
pw = context.portal_workflow pw = context.portal_workflow
...@@ -605,7 +614,9 @@ class ModuleTemplateItem(BaseTemplateItem): ...@@ -605,7 +614,9 @@ class ModuleTemplateItem(BaseTemplateItem):
portal = context.getPortalObject() portal = context.getPortalObject()
for id,mapping in self._archive.items(): for id,mapping in self._archive.items():
if id in portal.objectIds(): if id in portal.objectIds():
raise TemplateConflictError, 'the module %s already exists' % id module = portal._getOb(id)
module.portal_type = mapping['portal_type'] # XXX
else:
module = portal.newContent(id=id, portal_type=mapping['portal_type']) module = portal.newContent(id=id, portal_type=mapping['portal_type'])
module.setTitle(mapping['title']) module.setTitle(mapping['title'])
for name,role_list in mapping['permission_list']: for name,role_list in mapping['permission_list']:
...@@ -622,9 +633,15 @@ class ModuleTemplateItem(BaseTemplateItem): ...@@ -622,9 +633,15 @@ class ModuleTemplateItem(BaseTemplateItem):
id_list = p.objectIds() id_list = p.objectIds()
for id in self._archive.keys(): for id in self._archive.keys():
if id in id_list: if id in id_list:
try:
p.manage_delObjects([id]) p.manage_delObjects([id])
except:
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
class DocumentTemplateItem(BaseTemplateItem): class DocumentTemplateItem(BaseTemplateItem):
...@@ -720,6 +737,19 @@ class RoleTemplateItem(BaseTemplateItem): ...@@ -720,6 +737,19 @@ class RoleTemplateItem(BaseTemplateItem):
p.__ac_roles__ = tuple(roles.keys()) p.__ac_roles__ = tuple(roles.keys())
BaseTemplateItem.uninstall(self, context, **kw) BaseTemplateItem.uninstall(self, context, **kw)
def trash(self, context, new_item, **kw):
p = context.getPortalObject()
new_roles = {}
for role in new_item._archive.keys():
new_roles[role] = 1
roles = {}
for role in p.__ac_roles__:
roles[role] = 1
for role in self._archive.keys():
if role in roles and role not in new_role:
del roles[role]
p.__ac_roles__ = tuple(roles.keys())
class CatalogResultKeyTemplateItem(BaseTemplateItem): class CatalogResultKeyTemplateItem(BaseTemplateItem):
...@@ -1064,7 +1094,8 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1064,7 +1094,8 @@ Business Template is a set of definitions, such as skins, portal types and categ
""" """
installed_bt = self.portal_templates.getInstalledBusinessTemplate(self.getTitle()) installed_bt = self.portal_templates.getInstalledBusinessTemplate(self.getTitle())
if installed_bt is not None: if installed_bt is not None:
raise TemplateConflictError, 'upgrade is not implemented yet' installed_bt.trash(self)
installed_bt.replace()
# Update local dictionary containing all setup parameters # Update local dictionary containing all setup parameters
# This may include mappings # This may include mappings
...@@ -1107,6 +1138,45 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1107,6 +1138,45 @@ Business Template is a set of definitions, such as skins, portal types and categ
install = WorkflowMethod(install) install = WorkflowMethod(install)
def trash(self, new_bt, **kw):
"""
Trash unnecessary items before upograding to a new business template.
This is similar to uninstall, but different in that this does not remove
all items.
"""
# Update local dictionary containing all setup parameters
# This may include mappings
self.portal_templates.updateLocalConfiguration(self, **kw)
local_configuration = self.portal_templates.getLocalConfiguration(self)
# Actions, catalog
self._action_item.trash(local_configuration, new_bt._action_item)
self._catalog_result_key_item.trash(local_configuration, new_bt._catalog_result_key_item)
self._catalog_result_table_item.trash(local_configuration, new_bt._catalog_result_table_item)
# Skins
self._skin_item.trash(local_configuration, new_bt._skin_item)
# Portal Types
self._portal_type_item.trash(local_configuration, new_bt._portal_type_item)
# Modules.
self._module_item.trash(local_configuration, new_bt._module_item)
# Objects and properties
self._path_item.trash(local_configuration, new_bt._path_item)
self._workflow_item.trash(local_configuration, new_bt._workflow_item)
self._category_item.trash(local_configuration, new_bt._category_item)
self._catalog_method_item.trash(local_configuration, new_bt._catalog_method_item)
self._site_property_item.trash(local_configuration, new_bt._site_property_item)
# Classes and security information
self._product_item.trash(local_configuration, new_bt._product_item)
self._property_sheet_item.trash(local_configuration, new_bt._property_sheet_item)
self._document_item.trash(local_configuration, new_bt._document_item)
self._extension_item.trash(local_configuration, new_bt._extension_item)
self._role_item.trash(local_configuration, new_bt._role_item)
def uninstall(self, **kw): def uninstall(self, **kw):
""" """
For uninstall based on paramaters provided in **kw For uninstall based on paramaters provided in **kw
...@@ -1259,4 +1329,3 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1259,4 +1329,3 @@ Business Template is a set of definitions, such as skins, portal types and categ
ordered list ordered list
""" """
return self._getOrderedList('template_module_id') return self._getOrderedList('template_module_id')
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