# -*- coding: utf-8 # Copyright 2005 by Meelis Mets from Products.CMFCore.utils import getToolByName from Products.Archetypes.Extensions.utils import install_subskin, installTypes from Products.Archetypes.public import listTypes from Products.Archetypes.utils import shasattr from StringIO import StringIO import string from Products.Eportfolio.config import GLOBALS, PROJECT_NAME def install(self): """ install. """ out = StringIO() install_subskin(self, out, GLOBALS) installTypes(self, out, listTypes(PROJECT_NAME), PROJECT_NAME) #if not hasattr(self, 'update_tool'): addTool = self.manage_addProduct[PROJECT_NAME].manage_addTool # Add the tool by its meta_type # addTool('UpdateTool') if not hasattr(self, 'caching_tool'): addTool('CachingTool') # Check whether we're upgrading or not qi=getToolByName(self, 'portal_quickinstaller') p=qi._getOb(PROJECT_NAME, None) if p: oldVersion=p.getInstalledVersion() else: oldVersion="0" newVersion=qi.getProductVersion(PROJECT_NAME) migrate(self,out,oldVersion,newVersion) return out.getvalue() def uninstall(self): """ uninstall """ out = StringIO() return out.getvalue() def migrate(self, out, old, new): """ migrate """ if not old or old=="0": return if new==old: return if new>out, "Migrating from %s to %s" % (old, new) if old<="0.2.6": from Products.Eportfolio.Blog import BlogRedirector for x in self.Members.objectValues('Eportfolio'): try: x.blog._setObject('redirector', BlogRedirector()) except: pass if old<="0.3.1": for x in self.Members.objectValues('Eportfolio'): if not shasattr(x.taskmanager, 'right_slots'): #if 'here/portlet_drawer/macros/portlet-additem' not in x.taskmanager.getProperty('right_slots'): x.taskmanager._setProperty('right_slots', ['here/portlet_calendar/macros/portlet','here/portlet_drawer/macros/portlet-additem',], 'lines') else: x.taskmanager._updateProperty('right_slots', ['here/portlet_calendar/macros/portlet','here/portlet_drawer/macros/portlet-additem',]) if shasattr(x.competency, 'largeIcon'): x.competency.largeIcon="comp.gif" if old<="0.3.2": from Products.Eportfolio.Groups import Groups for x in self.Members.objectValues('Eportfolio'): if not shasattr(x, 'groups'): groups = Groups('groups') x._setObject(groups.id, groups) ob=getattr(x,groups.id) ob.setTitle('Groups') ob.reindexObject() if old<="0.3.3": for x in self.Members.objectValues('Eportfolio'): if not shasattr(x.profile, 'right_slots'): x.profile._setProperty('right_slots', ['here/portlet_profile/macros/portlet',], 'lines') else: x.profile._updateProperty('right_slots', ['here/portlet_profile/macros/portlet',]) if old<="0.3.4": for mf in self.Members.objectValues('Eportfolio'): blog = getattr(mf, 'blog') if not shasattr(blog, 'right_slots'): blog._setProperty('right_slots', [ 'here/portlet_calendar/macros/portlet', 'here/portlet_new_content/macros/portlet-additem', 'here/portlet_blog/macros/portlet-additem', 'here/portlet_blog/macros/portlet-blogroll', 'here/portlet_workflow/macros/portlet-workflow', 'here/portlet_reference_to_competencies/macros/portlet', 'here/portlet_blog/macros/tagcloud',], 'lines') else: blog._updateProperty('right_slots', [ 'here/portlet_calendar/macros/portlet', 'here/portlet_new_content/macros/portlet-additem', 'here/portlet_blog/macros/portlet-additem', 'here/portlet_blog/macros/portlet-blogroll', 'here/portlet_workflow/macros/portlet-workflow', 'here/portlet_reference_to_competencies/macros/portlet', 'here/portlet_blog/macros/tagcloud',]) tm = getattr(mf, 'taskmanager') if not shasattr(tm, 'right_slots'): tm._setProperty('right_slots', [ 'here/portlet_calendar/macros/portlet', 'here/portlet_new_content/macros/portlet-additem', 'here/portlet_drawer/macros/portlet_links', 'here/portlet_reference_to_competencies/macros/portlet',], 'lines') else: tm._updateProperty('right_slots', [ 'here/portlet_calendar/macros/portlet', 'here/portlet_new_content/macros/portlet-additem', 'here/portlet_drawer/macros/portlet_links', 'here/portlet_reference_to_competencies/macros/portlet',]) drawer = getattr(mf, 'drawer') if not shasattr(drawer, 'right_slots'): drawer._setProperty('right_slots', [ 'here/portlet_calendar/macros/portlet', 'here/portlet_new_content/macros/portlet-additem', 'here/portlet_drawer/macros/portlet_links', 'here/portlet_reference_to_competencies/macros/portlet',], 'lines') else: drawer._updateProperty('right_slots', [ 'here/portlet_calendar/macros/portlet', 'here/portlet_new_content/macros/portlet-additem', 'here/portlet_drawer/macros/portlet_links', 'here/portlet_reference_to_competencies/macros/portlet']) if old<="0.3.5": for mf in self.Members.objectValues('Eportfolio'): blog = getattr(mf, 'blog') if not shasattr(blog, 'left_slots'): blog._setProperty('left_slots', [ 'here/portlet_eportfolio/macros/portlet', 'here/portlet_calendar/macros/portlet',], 'lines') else: blog._updateProperty('left_slots', [ 'here/portlet_eportfolio/macros/portlet', 'here/portlet_calendar/macros/portlet',]) if not shasattr(blog, 'right_slots'): blog._setProperty('right_slots', [ 'here/portlet_new_content/macros/portlet-additem', 'here/portlet_blog/macros/portlet-additem', 'here/portlet_blog/macros/portlet-blogroll', 'here/portlet_workflow/macros/portlet-workflow', 'here/portlet_reference_to_competencies/macros/portlet', 'here/portlet_blog/macros/tagcloud',], 'lines') else: blog._updateProperty('right_slots', [ 'here/portlet_new_content/macros/portlet-additem', 'here/portlet_blog/macros/portlet-additem', 'here/portlet_blog/macros/portlet-blogroll', 'here/portlet_workflow/macros/portlet-workflow', 'here/portlet_reference_to_competencies/macros/portlet', 'here/portlet_blog/macros/tagcloud',]) tm = getattr(mf, 'taskmanager') if not shasattr(tm, 'left_slots'): tm._setProperty('left_slots', [ 'here/portlet_eportfolio/macros/portlet', 'here/portlet_calendar/macros/portlet',], 'lines') else: tm._updateProperty('left_slots', [ 'here/portlet_eportfolio/macros/portlet', 'here/portlet_calendar/macros/portlet',]) if not shasattr(tm, 'right_slots'): tm._setProperty('right_slots', [ 'here/portlet_new_content/macros/portlet-additem', 'here/portlet_drawer/macros/portlet_links', 'here/portlet_reference_to_competencies/macros/portlet', 'here/portlet_tasks/macros/portlet-tasks',], 'lines') else: tm._updateProperty('right_slots', [ 'here/portlet_new_content/macros/portlet-additem', 'here/portlet_drawer/macros/portlet_links', 'here/portlet_reference_to_competencies/macros/portlet', 'here/portlet_tasks/macros/portlet-tasks',]) drawer = getattr(mf, 'drawer') if not shasattr(drawer, 'left_slots'): drawer._setProperty('left_slots', [ 'here/portlet_eportfolio/macros/portlet', 'here/portlet_calendar/macros/portlet',], 'lines') else: drawer._updateProperty('left_slots', [ 'here/portlet_eportfolio/macros/portlet', 'here/portlet_calendar/macros/portlet',]) if not shasattr(drawer, 'right_slots'): drawer._setProperty('right_slots', [ 'here/portlet_new_content/macros/portlet-additem', 'here/portlet_drawer/macros/portlet_links', 'here/portlet_reference_to_competencies/macros/portlet',], 'lines') else: drawer._updateProperty('right_slots', [ 'here/portlet_new_content/macros/portlet-additem', 'here/portlet_drawer/macros/portlet_links', 'here/portlet_reference_to_competencies/macros/portlet']) groups = getattr(mf, 'groups') if not shasattr(groups, 'left_slots'): groups._setProperty('left_slots', [ 'here/portlet_eportfolio/macros/portlet', 'here/portlet_calendar/macros/portlet',], 'lines') else: groups._updateProperty('left_slots', [ 'here/portlet_eportfolio/macros/portlet', 'here/portlet_calendar/macros/portlet',]) if not shasattr(groups, 'right_slots'): groups._setProperty('right_slots', [], 'lines') else: groups._updateProperty('right_slots', []) competency = getattr(mf, 'competency') if not shasattr(competency, 'left_slots'): competency._setProperty('left_slots', [ 'here/portlet_eportfolio/macros/portlet', 'here/portlet_calendar/macros/portlet',], 'lines') else: competency._updateProperty('left_slots', [ 'here/portlet_eportfolio/macros/portlet', 'here/portlet_calendar/macros/portlet',]) if not shasattr(competency, 'right_slots'): competency._setProperty('right_slots', ['here/portlet_competency/macros/portlet',], 'lines') else: competency._updateProperty('right_slots', ['here/portlet_competency/macros/portlet',]) if old<="0.3.6": if hasattr(self, 'portal_calendar'): self._delObject('portal_calendar') #if not hasattr(self, 'portal_calendar'): addTool = self.manage_addProduct[PROJECT_NAME].manage_addTool # Add the tool by its meta_type addTool('CalendarTool') if old<="0.3.7": for mf in self.Members.objectValues('Eportfolio'): drawer = getattr(mf, 'drawer') if not shasattr(drawer, 'right_slots'): drawer._setProperty('right_slots', [ 'here/portlet_new_content/macros/portlet-additem', 'here/portlet_workflow/macros/portlet-workflow', 'here/portlet_reference_to_competencies/macros/portlet', 'here/portlet_drawer/macros/portlet_links',], 'lines') else: drawer._updateProperty('right_slots', [ 'here/portlet_new_content/macros/portlet-additem', 'here/portlet_workflow/macros/portlet-workflow', 'here/portlet_reference_to_competencies/macros/portlet', 'here/portlet_drawer/macros/portlet_links']) if old<="0.3.8": for mf in self.Members.objectValues('Eportfolio'): x = mf if not shasattr(x.taskmanager, 'right_slots'): #if 'here/portlet_drawer/macros/portlet-additem' not in x.taskmanager.getProperty('right_slots'): x.taskmanager._setProperty('right_slots', ['here/portlet_calendar/macros/portlet','here/portlet_new_content/macros/portlet-additem',], 'lines') else: x.taskmanager._updateProperty('right_slots', ['here/portlet_calendar/macros/portlet','here/portlet_new_content/macros/portlet-additem',]) if old<="0.3.9": print >>out, "Migrating from %s to %s, 0.3.9" % (old, new) for mf in self.Members.objectValues('Eportfolio'): print mf tm = getattr(mf, 'taskmanager') if not shasattr(tm, 'right_slots'): tm._setProperty('right_slots', [ 'here/portlet_new_content/macros/portlet-additem', 'here/portlet_drawer/macros/portlet_links', 'here/portlet_reference_to_competencies/macros/portlet', 'here/portlet_tasks/macros/portlet-tasks',], 'lines') else: tm._updateProperty('right_slots', [ 'here/portlet_new_content/macros/portlet-additem', 'here/portlet_drawer/macros/portlet_links', 'here/portlet_reference_to_competencies/macros/portlet', 'here/portlet_tasks/macros/portlet-tasks',]) if old<="0.4.1": print >>out, "Migrating from %s to %s" % (old, new) from Products.Eportfolio.Dashboard import Dashboard for x in self.Members.objectValues('Eportfolio'): if not shasattr(x, 'dashboard'): dashboard = Dashboard('dashboard') x._setObject(dashboard.id, dashboard) ob=getattr(x,dashboard.id) ob.setTitle('Dashboard') ob._setProperty('left_slots', [ 'here/portlet_eportfolio/macros/portlet', 'here/portlet_calendar/macros/portlet',], 'lines') ob._setProperty('right_slots', [ 'here/portlet_tasks/macros/portlet-tasks', 'here/portlet_blog/macros/portlet-blogroll',], 'lines') ob.reindexObject() if old<="0.4.2": print >>out, "Migrating from %s to %s" % (old, new) for x in self.Members.objectValues('Eportfolio'): if not shasattr(x.profile, 'left_slots'): x.profile._setProperty('left_slots', [ 'here/portlet_eportfolio/macros/portlet', 'here/portlet_calendar/macros/portlet',], 'lines') else: x.profile._updateProperty('left_slots', [ 'here/portlet_eportfolio/macros/portlet', 'here/portlet_calendar/macros/portlet',]) if old<="0.4.3": print >>out, "Migrating from %s to %s" % (old, new) for eport in self.Members.objectValues("Eportfolio"): eport_creator = eport.Creator() for dash_obj in eport.objectValues("Dashboard"): acl_users = self.acl_users user = self.acl_users.getUser(eport_creator) dash_obj.changeOwnership(user) if old<="0.4.4": print >> out, "Migrating from %s to %s" % (old, new) from Products.ZCatalog.Catalog import CatalogError try: catalog_tool = getToolByName(self, 'portal_catalog') catalog_tool.manage_addColumn("UID") except CatalogError: pass ft = getToolByName(self, 'portal_factory') types_list = ft.getFactoryTypes() types_list['StructuredTemplate'] = 1 ft.manage_setPortalFactoryTypes(None, types_list) if old<="0.4.5": print >>out, "Migration from %s to %s" % (old, new) wtool = getToolByName(self, 'portal_workflow') wtool.manage_addWorkflow('simple_workflow (Eportfolio simple workflow)', 'simple_workflow') wtool.setChainForPortalTypes(('StructuredTemplate',), 'simple_workflow') wtool.updateRoleMappings() if old<="0.4.6": print >>out, "Migration from %s to %s" % (old, new) gtool = getToolByName(self, 'portal_groups') groups = gtool.listGroupIds() from Products.CMFCore.permissions import View for group in groups: if group != 'Administrators' and group != 'Reviewers': group_ob = gtool.getGroupareaFolder(group) if group_ob is None: continue group_ob.manage_permission(View, ('Manager','Owner'), 0) for folder in group_ob.objectValues(): folder.manage_permission(View, ('Manager','Owner'), 0)