source: trunk/Extensions/Install.py @ 450

Revision 450, 10.1 KB checked in by jukka, 13 years ago (diff)

Fixed #511, spent 2h.

Line 
1# Copyright 2006 by the LeMill Team (see AUTHORS)
2#
3# This file is part of Calibrate LeMill.
4#
5# Calibrate LeMill is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# Calibrate LeMill is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with Calibrate LeMill; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19"""Plone product installer script"""
20
21from Products.CMFCore.utils import getToolByName
22from Products.Archetypes.Extensions.utils import install_subskin, installTypes
23from Products.Archetypes.public import listTypes
24
25from StringIO import StringIO
26import string
27
28from Products.LeMill.config import GLOBALS, PROJECTNAME, MEMBER_PROPERTIES
29
30def install(self):
31        """Installs this Plone product. Called by the quick_installer tool."""
32        # HOOK: This is executed when the Plone site with LeMill customization
33        # is created, or when a reinstall for the LeMill product is called from
34        # quick_installer.
35       
36        out = StringIO()
37        # Don't install the skin layer here - the configuration methods setup a
38        # whole new skin for us.
39
40        # Check whether we're upgrading or not
41        qi=getToolByName(self, 'portal_quickinstaller')
42        p=qi._getOb(PROJECTNAME, None)
43        if p:
44                oldVersion=p.getInstalledVersion()
45        else:
46                oldVersion="0"
47        newVersion=qi.getProductVersion(PROJECTNAME)
48
49
50        print >>out,"Installing content archetypes..."
51        installTypes(self, out, listTypes(PROJECTNAME), PROJECTNAME)
52
53        print >>out,"Installing portal tools..."
54        if not hasattr(self, 'lemill_search'):
55                addTool = self.manage_addProduct[PROJECTNAME].manage_addTool
56                # Add the tool by its meta_type
57                addTool('LeMillSearch')
58        if not hasattr(self, 'lemill_tool'):
59                addTool = self.manage_addProduct[PROJECTNAME].manage_addTool
60                # Add the tool by its meta_type
61                addTool('LeMillTool')
62        if not hasattr(self, 'lemill_usertool'):
63                addTool = self.manage_addProduct[PROJECTNAME].manage_addTool
64                # Add the tool by its meta_type
65                addTool('LeMillUserTool')
66
67
68        print >>out,"Registering remote search preference panel..."
69        # Register lemill_search_conf under controlpanel.
70        # admins can register additional search locations there.
71        # ticket #107
72        cp = getToolByName( self, 'portal_controlpanel')
73        REMOTE_SEARCH_ID='lemill_remote_search'
74        cp.unregisterConfiglet(REMOTE_SEARCH_ID)
75        cp.addAction(REMOTE_SEARCH_ID,
76                'LeMill search',
77                'string:${portal_url}/prefs_lemill_search_form',
78                permission='Manage portal',
79                category='Products',
80                appId='LeMill')
81
82        # Call migration script
83        migrate(self,out,oldVersion,newVersion)
84
85        print >>out,"Installation completed."
86        # Done, return whatever messages we got
87        return out.getvalue()
88
89def migrate(self,out,old,new):
90        """Migrate existing content. If we're installing a newer version
91        of LeMill over an existing one, we may need to alter the existing
92        content so that it's compatible with the new version."""
93
94        # Note that versions are strings, not numbers.
95       
96        if not old: return
97        if new==old: return
98        if new<old:
99                print >>out,"Can't downgrade content from %s to %s!" % (old,new)
100                return
101
102        print >>out,"Migrating from %s to %s" % (old,new)
103
104        # NB: All setupXXX methods from ConfigurationMethods are executed when
105        # running a reinstall from quick_installer.
106
107        # Example iteration, changing all content objects
108        # Adapt this to change objects so they are compatible with the
109        # changes made into the system
110        if 1 == 0: # Let's not really run it...
111                for ob in self.content.objectValues(('Piece','Material')):
112                        ob.edit(title=ob.Title()+"!")
113
114        if old<"0.3":
115                print >>out, "Migration not supported for versions below 0.3"
116                return
117
118        # Add migration stuff here, in ascending order of version
119        # NOTE: If you make a syntax error here, portal_quickinstaller
120        # will just report LeMill as "removed from Products folder"
121        # (running "python Extensions/Install.py" will report syntax errors)
122        if old<="0.3":
123                print >>out, "Starting migration from 0.3..."
124                # Migrate from 0.3
125                # Member information is no longer stored in memberdata tool
126                # This is the old property list:
127                old=(
128                        ('firstname', 'string',''),
129                        ('lastname', 'string',''),
130                        ('fullname', 'string','hidden'),
131                        ('nickname', 'string',''),
132                        ('messenger1', 'string',''),
133                        ('messenger2', 'string',''),
134                        ('messenger3', 'string',''),
135                        ('home_page', 'string',''),
136                        ('location_country', 'string',''),
137                        ('location_area', 'string',''),
138                        ('language_skills', 'lines',''),
139                        ('skills', 'lines',''),
140                        ('interests', 'lines',''),
141                        ('tags', 'lines','hidden'),
142                        ('used_content', 'lines','hidden'),
143                        )
144                # This is the current list:
145                current = MEMBER_PROPERTIES
146                mdat_tool = getToolByName(self, 'portal_memberdata')
147                # Remove any properties not in the current list
148                deleteThese=[]
149                for prop in old:
150                        if not prop[0] in [x[0] for x in current]:
151                                deleteThese.append(prop[0])
152                print >>out,"Removing these obsolete member properties: %s" % ", ".join(deleteThese)
153                mdat_tool.manage_delProperties(deleteThese)
154                print >>out,"Migration from 0.3 complete."
155               
156        if old<="0.3.1":
157                # Migrate from 0.3.1
158                # Add initial history entry to all objects
159                print >>out,"Starting migration from 0.3.1..."
160                def initiateHistory(objs):
161                        for ob in objs:
162                                if not ob.getHistory():
163                                        ob.storeInHistory(fields=(),summary='History information started.',storeAuthor=False)
164                print >>out,"Adding initial history entry to learning resources..."
165                initiateHistory(self.content.objectValues(('Material',)))
166                initiateHistory(self.activities.objectValues(('Activity',)))
167                initiateHistory(self.tools.objectValues(('Tool',)))
168                print >>out,"Updating left slots and state..."
169                for ob in self.community.objectValues(('GroupBlog','MemberFolder')) + \
170            self.activities.objectValues(('Activity',)) + \
171            self.tools.objectValues(('Tool',)):
172                    ob.content_status_modify(workflow_action='publish')
173                    if not hasattr(ob.aq_base, 'left_slots'):
174                        ob._setProperty('left_slots', ['here/portlet_%s_actions/macros/portlet' % ob.meta_type.lower(),], 'lines')
175
176                print >>out,"Migration from 0.3.1 complete."
177        if old<="0.3.2":
178            # Migrate from 0.3.2
179            # move history from LearningResource class to Resource class
180            print >>out,"Starting migration from 0.3.2..."
181            def moveHistory(objs):
182                for obj in objs:
183                    if hasattr(obj, '_LearningResource__history'):
184                        setattr(obj, '_Resource__history', getattr(obj, '_LearningResource__history'))
185                        del obj._LearningResource__history
186                    if not obj.getHistory():
187                        obj.storeInHistory(fields=(),summary='History information started.',storeAuthor=False)
188            print >>out,"Moving history information to Resource class"
189            moveHistory(self.content.objectValues(('Material', 'Piece')))
190            moveHistory(self.activities.objectValues(('Activity',)))
191            moveHistory(self.tools.objectValues(('Tool',)))
192        if old<="0.4":
193            print >>out, "Starting migration from 0.4"
194            for x in self.content.objectValues(('Material', 'Piece')):
195                tags = x.getTags()
196                x.setTags(', '.join(tags))
197            print >>out, "Attaching license"
198            for x in self.content.objectValues(('Piece',)):
199                x.setRights('CreativeCommons')
200            print >>out, "Migration from 0.4 complete"
201        if old<='0.4.1':
202            print >>out, "Starting migration from 0.4.1"
203            groupdatatool=getToolByName(self,"portal_groupdata")
204            for prop in ['tags','email','scope']:
205                if groupdatatool.hasProperty(prop):
206                    groupdatatool.manage_delProperties([prop])
207                print >>out, "Migration from 0.4.1 complete"
208        if old<='0.4.2':
209                print >>out, "Starting migration from 0.4.2"
210                for group in self.community.objectValues(('GroupBlog',)):
211                    for post in group.objectValues(('BlogPost',)):
212                        post._setProperty('left_slots', ['here/portlet_groupblog_actions/macros/portlet',], 'lines')
213                print >>out, "Migration from 0.4.2 complete"
214        print >>out,"Migration completed."
215
216
217def uninstall(self):
218        """ uninstall """
219        out = StringIO()
220        # We don't have any way of uninstalling, at this point.
221        return out.getvalue()
222
Note: See TracBrowser for help on using the repository browser.