-
Notifications
You must be signed in to change notification settings - Fork 2
/
addons.py
401 lines (343 loc) · 14.5 KB
/
addons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# -*- coding: UTF-8 -*-
from plone import api
from zExceptions import BadRequest
from zope.lifecycleevent import modified
import logging
log = logging.getLogger(__name__)
def remove_ploneformgen(context=None, check_linkintegrity=True):
portal = api.portal.get()
portal_types = api.portal.get_tool('portal_types')
portal_catalog = api.portal.get_tool('portal_catalog')
qi = api.portal.get_tool('portal_quickinstaller')
log.info('removing PloneFormGen')
old_types = [
'FormFolder',
]
old_types = [i for i in old_types if i in portal_types]
for old_type in old_types:
log.info(u'Deleting Existing Instances of {}!'.format(old_type))
for brain in portal_catalog(portal_type=old_type):
log.info(u'Removing {}!'.format(brain.getPath()))
api.content.delete(brain.getObject(), check_linkintegrity=check_linkintegrity) # noqa: E501
try:
portal.manage_delObjects(['formgen_tool'])
except AttributeError:
pass
try:
portal.portal_properties.manage_delObjects(['ploneformgen_properties'])
except BadRequest:
pass
if qi.isProductInstalled('PloneFormGen'):
qi.uninstallProducts(['PloneFormGen'])
if qi.isProductInstalled('Products.PloneFormGen'):
qi.uninstallProducts(['Products.PloneFormGen'])
def remove_plonekeywordmanager(context=None):
qi = api.portal.get_tool('portal_quickinstaller')
# remove PloneKeywordManager
log.info('removing PloneKeywordManager')
if qi.isProductInstalled('PloneKeywordManager'):
qi.uninstallProducts(['PloneKeywordManager'])
def remove_solgema_fullcalendar(context=None):
qi = api.portal.get_tool('portal_quickinstaller')
log.info('removing Solgema.fullcalendar')
if qi.isProductInstalled('Solgema.fullcalendar'):
# do not remove types
cascade = (
'skins', 'actions', 'portalobjects', 'workflows', 'slots',
'registrypredicates', 'adapters', 'utilities',
)
qi.uninstallProducts(['Solgema.fullcalendar'], cascade=cascade)
def remove_multiple_addons(context=None):
qi = api.portal.get_tool('portal_quickinstaller')
portal_properties = api.portal.get_tool('portal_properties')
portal_setup = api.portal.get_tool('portal_setup')
portal_catalog = api.portal.get_tool('portal_catalog')
portal = api.portal.get()
portal_controlpanel = api.portal.get_tool('portal_controlpanel')
# collective.quickupload
log.info('removing collective.quickupload')
if qi.isProductInstalled('collective.quickupload'):
qi.uninstallProducts(['collective.quickupload'])
try:
portal_properties.manage_delObjects(['quickupload_properties'])
except BadRequest:
pass
# collective.plonetruegallery
log.info('removing collective.plonetruegallery')
if qi.isProductInstalled('collective.plonetruegallery'):
qi.uninstallProducts(['collective.plonetruegallery'])
# Products.RedirectionTool
log.info('removing Products.RedirectionTool')
if qi.isProductInstalled('Products.RedirectionTool'):
qi.uninstallProducts(['Products.RedirectionTool'])
if qi.isProductInstalled('RedirectionTool'):
qi.uninstallProducts(['RedirectionTool'])
# collective.portletclass
log.info('removing collective.portletclass')
if qi.isProductInstalled('collective.portletclass'):
qi.uninstallProducts(['collective.portletclass'])
# collective.weightedportlets
log.info('removing collective.weightedportlets')
if qi.isProductInstalled('collective.weightedportlets'):
qi.uninstallProducts(['collective.weightedportlets'])
# starzel.firstitem
log.info('removing starzel.firstitem')
for brain in portal_catalog.searchResults(portal_type='Folder'):
obj = brain.getObject()
if getattr(obj.aq_base, 'layout', None) == 'firstitem_view':
obj.manage_delProperties(['layout'])
modified(obj)
if qi.isProductInstalled('starzel.firstitem'):
qi.uninstallProducts(['starzel.firstitem'])
if getattr(portal, 'layout', None) == 'firstitem_view':
portal.manage_delProperties(['layout'])
try:
portal_properties.manage_delObjects(['cli_properties'])
except BadRequest:
pass
log.info('removing collective.js.fancybox')
if qi.isProductInstalled('collective.js.fancybox'):
qi.uninstallProducts(['collective.js.fancybox'])
log.info('removing collective.z3cform.widgets')
if qi.isProductInstalled('collective.z3cform.widgets'):
qi.uninstallProducts(['collective.z3cform.widgets'])
log.info('removing collective.z3cform.keywordwidget')
if qi.isProductInstalled('collective.z3cform.keywordwidget'):
qi.uninstallProducts(['collective.z3cform.keywordwidget'])
log.info('removing collective.z3cform.datetimewidget')
if qi.isProductInstalled('collective.z3cform.datetimewidget'):
qi.uninstallProducts(['collective.z3cform.datetimewidget'])
# Remove collective.easyslider
if qi.isProductInstalled('collective.easyslider'):
from collective.easyslider.interfaces import IViewEasySlider
for brain in api.content.find(
object_provides=IViewEasySlider.__identifier__):
obj = brain.getObject()
# noLongerProvides(obj, IViewEasySlider)
if obj.getLayout() == 'sliderview':
obj.manage_delProperties(['layout'])
log.info('removed easyslider from {}'.format(brain.getURL()))
portal_controlpanel.unregisterConfiglet('easyslieder')
qi.uninstallProducts(['collective.easyslider'])
try:
portal_properties.manage_delObjects(['easyslideshow_properties'])
except BadRequest:
pass
# remove cciaa.modulistica
log.info('removing cciaa.modulistica')
if qi.isProductInstalled('cciaa.modulistica'):
portal_catalog._removeIndex('getRawRelatedItems')
from cciaa.modulistica.interfaces import CCIAAModAbleContent
for brain in api.content.find(
object_provides=CCIAAModAbleContent.__identifier__):
obj = brain.getObject()
# noLongerProvides(obj, IViewEasySlider)
if obj.getLayout() == 'cciaa_modulistica_view':
obj.manage_delProperties(['layout'])
log.info('removed cciaa.modulistica from {}'.format(brain.getURL())) # noqa: E501
qi.uninstallProducts(['cciaa.modulistica'])
# Solgema.fullcalendar
log.info('removing Solgema.fullcalendar')
if qi.isProductInstalled('Solgema.fullcalendar'):
qi.uninstallProducts(['Solgema.fullcalendar'])
# collective.imagetags
log.info('removing collective.imagetags')
if qi.isProductInstalled('collective.imagetags'):
portal_controlpanel.unregisterConfiglet('imagetags')
# do not uninstall utilities since that will nuke the registry
cascade = [
'types', 'skins', 'actions', 'portalobjects', 'workflows', 'slots',
'registrypredicates', 'adapters']
qi.uninstallProducts(['collective.imagetags'], cascade=cascade)
# wpd.mmxi.countdown
# delete portlet instance
from plone.portlets.interfaces import IPortletAssignmentMapping
from plone.portlets.interfaces import IPortletManager
from zope.component import getMultiAdapter
from zope.component import getUtility
log.info('removing wpd.mmxi.countdown')
content = api.content.get(path='/nm/example-intranet')
if content:
manager = getUtility(
IPortletManager, name='plone.leftcolumn', context=content)
mapping = getMultiAdapter(
(content, manager), IPortletAssignmentMapping)
try:
del mapping['wpd-countdown']
except KeyError:
pass
if qi.isProductInstalled('wpd.mmxi.countdown'):
qi.uninstallProducts(['wpd.mmxi.countdown'])
# Products.Carousel
log.info('removing Products.Carousel')
if qi.isProductInstalled('Products.Carousel'):
qi.uninstallProducts(['Products.Carousel'])
# Products.PlonePopoll
log.info('removing Products.PlonePopoll')
if qi.isProductInstalled('PlonePopoll'):
qi.uninstallProducts(['PlonePopoll'])
# eea.facetednavigation
log.info('removing eea.facetednavigation')
if qi.isProductInstalled('eea.facetednavigation'):
qi.uninstallProducts(['eea.facetednavigation'])
# eea.relations
log.info('removing eea.relations')
if qi.isProductInstalled('eea.relations'):
qi.uninstallProducts(['eea.relations'])
# Products.ECLecture
log.info('removing Products.ECLecture')
if qi.isProductInstalled('ECLecture'):
qi.uninstallProducts(['ECLecture'])
# Products.ImageEditor
log.info('removing Products.ImageEditor')
if qi.isProductInstalled('ImageEditor'):
qi.uninstallProducts(['ImageEditor'])
# collective.plonetruegallery
log.info('removing collective.plonetruegallery')
if qi.isProductInstalled('collective.plonetruegallery'):
qi.uninstallProducts(['collective.plonetruegallery'])
# zettwerk.ui
log.info('removing zettwerk.ui')
if qi.isProductInstalled('zettwerk.ui'):
qi.uninstallProducts(['zettwerk.ui'])
# Solgema.fullcalendar
log.info('removing Solgema.fullcalendar')
if qi.isProductInstalled('Solgema.fullcalendar'):
qi.uninstallProducts(['Solgema.fullcalendar'])
# Solgema.ContextualContentMenu
log.info('removing Solgema.ContextualContentMenu')
if qi.isProductInstalled('Solgema.ContextualContentMenu'):
qi.uninstallProducts(['Solgema.ContextualContentMenu'])
# Products.ImageEditor
log.info('removing Products.ImageEditor')
if qi.isProductInstalled('Products.ImageEditor'):
qi.uninstallProducts(['Products.ImageEditor'])
try:
portal_properties.manage_delObjects(['imageeditor'])
except BadRequest:
pass
# collective.easyslideshow
log.info('removing collective.easyslideshow')
if qi.isProductInstalled('collective.easyslideshow'):
qi.uninstallProducts(['collective.easyslideshow'])
try:
portal_properties.manage_delObjects(['easyslideshow_properties'])
except BadRequest:
pass
# collective.quickupload
log.info('removing collective.quickupload')
if qi.isProductInstalled('collective.quickupload'):
qi.uninstallProducts(['collective.quickupload'])
try:
portal_properties.manage_delObjects(['quickupload_properties'])
except BadRequest:
pass
# collective.prettyphoto
log.info('removing collective.prettyphoto')
if qi.isProductInstalled('collective.prettyphoto'):
qi.uninstallProducts(['collective.prettyphoto'])
try:
portal_properties.manage_delObjects(['prettyphoto_properties'])
except BadRequest:
pass
# collective.plonefinder
log.info('removing collective.plonefinder')
if qi.isProductInstalled('collective.plonefinder'):
qi.uninstallProducts(['collective.plonefinder'])
# Products.PloneFormGen
log.info('removing Products.PloneFormGen')
if qi.isProductInstalled('PloneFormGen'):
qi.uninstallProducts(['PloneFormGen'])
try:
portal_properties.manage_delObjects(['ploneformgen_properties'])
except BadRequest:
pass
# DataGridField
log.info('removing DataGridField')
if qi.isProductInstalled('DataGridField'):
qi.uninstallProducts(['DataGridField'])
# collective.js.fullcalendar
log.info('removing collective.js.fullcalendar')
if qi.isProductInstalled('collective.js.fullcalendar'):
qi.uninstallProducts(['collective.js.fullcalendar'])
# Products.PloneFlashUpload (not installed)
log.info('removing Products.PloneFlashUpload')
if qi.isProductInstalled('Products.PloneFlashUpload'):
qi.uninstallProducts(['Products.PloneFlashUpload'])
# p4a.subtyper
log.info('removing p4a.subtyper')
if qi.isProductInstalled('p4a.subtyper'):
qi.uninstallProducts(['p4a.subtyper'])
# collective.externaleditor
log.info('removing collective.externaleditor')
if qi.isProductInstalled('collective.externaleditor'):
qi.uninstallProducts(['collective.externaleditor'])
# collective.ckeditor
log.info('removing collective.ckeditor')
if qi.isProductInstalled('collective.ckeditor'):
qi.uninstallProducts(['collective.ckeditor'])
try:
portal_properties.manage_delObjects(['ckeditor_properties'])
except BadRequest:
pass
# redturtle.smartlink
log.info('removing redturtle.smartlink')
if qi.isProductInstalled('redturtle.smartlink'):
# run migration
portal_setup.runAllImportStepsFromProfile(
'profile-redturtle.smartlink:smartLinkToATLink', purge_old=False)
qi.uninstallProducts(['redturtle.smartlink'])
# collective.js.jqueryui
log.info('removing collective.js.jqueryui')
if qi.isProductInstalled('collective.js.jqueryui'):
qi.uninstallProducts(['collective.js.jqueryui'])
try:
portal_properties.manage_delObjects(['jqueryui_properties'])
except BadRequest:
pass
addons = [
'collective.solr',
'underscore.js',
'plone.formwidget.recurrence',
'operun.media',
'collective.js.colorpicker',
'fourdigits.portlet.twitter',
'collective.js.moment',
'plone.app.relationfield',
'fourdigits.portlet.twitter',
'collective.js.colorpicker',
'plone.formwidget.recurrence',
'plone.formwidget.autocomplete',
]
for addon in addons:
if qi.isProductInstalled(addon):
log.info(u'Uninstalling {}'.format(addon))
qi.uninstallProducts([addon])
else:
log.info(u'{} is not installed'.format(addon))
def cleanup_behaviors(context=None):
# Remove obsolete behaviors
portal_types = api.portal.get_tool('portal_types')
to_delete = [
'plone.app.stagingbehavior.interfaces.IStagingSupport',
'collective.plonetruegallery.interfaces.IGallery',
'plone.app.referenceablebehavior.referenceable.IReferenceable',
]
content_types = [
'Collection',
'Document',
'Event',
'File',
'Folder',
'News Item',
]
for ct in content_types:
changed = False
fti = portal_types[ct]
behaviors = list(fti.behaviors)
for behavior in to_delete:
if behavior in behaviors:
behaviors.remove(behavior)
changed = True
if changed:
fti._updateProperty('behaviors', tuple(behaviors))