-
Notifications
You must be signed in to change notification settings - Fork 2
/
dexterity.py
197 lines (169 loc) · 5.64 KB
/
dexterity.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
# -*- coding: utf-8 -*-
from plone import api
from zope.globalrequest import getRequest
import logging
log = logging.getLogger(__name__)
# You could also look at:
# 1. This Talk by Alessandro Pisa:
# https://2017.ploneconf.org/talks/really-unconventional-migrations.html
# 2. The Inplace Migrator in ftw.upgrade
def install_pac(context=None):
"""Run this in Plone 5.2
"""
portal = api.portal.get()
request = getRequest()
installer = api.portal.get_view('installer', portal, request)
installer.install_product('plone.app.contenttypes')
def migrate_all(context=None):
"""Run this in Plone 5.2
"""
migrate_folders()
migrate_files()
migrate_images()
migrate_documents()
migrate_collections()
migrate_events()
migrate_links()
migrate_newsitems()
migrate_topics()
def migrate_folders(context=None):
portal = api.portal.get()
request = getRequest()
pac_migration = api.content.get_view('migrate_from_atct', portal, request)
content_types = ['Folder']
pac_migration(
migrate=True,
content_types=content_types,
migrate_schemaextended_content=True,
reindex_catalog=False,
patch_searchabletext=True,
)
def migrate_files(context=None):
portal = api.portal.get()
request = getRequest()
pac_migration = api.content.get_view(
'migrate_from_atct', portal, request)
content_types = ['BlobFile', 'File']
pac_migration(
migrate=True,
content_types=content_types,
migrate_schemaextended_content=True,
reindex_catalog=False,
patch_searchabletext=True,
)
def migrate_images(context=None):
portal = api.portal.get()
request = getRequest()
pac_migration = api.content.get_view('migrate_from_atct', portal, request)
content_types = ['BlobImage', 'Image']
pac_migration(
migrate=True,
content_types=content_types,
migrate_schemaextended_content=True,
reindex_catalog=False,
patch_searchabletext=True,
)
def migrate_documents(context=None):
portal = api.portal.get()
request = getRequest()
pac_migration = api.content.get_view('migrate_from_atct', portal, request)
content_types = ['Document']
pac_migration(
migrate=True,
content_types=content_types,
migrate_schemaextended_content=True,
reindex_catalog=False,
patch_searchabletext=True,
)
def migrate_collections(context=None):
portal = api.portal.get()
request = getRequest()
pac_migration = api.content.get_view('migrate_from_atct', portal, request)
content_types = ['Collection']
pac_migration(
migrate=True,
content_types=content_types,
migrate_schemaextended_content=True,
reindex_catalog=False,
patch_searchabletext=True,
)
def migrate_events(context=None):
portal = api.portal.get()
request = getRequest()
pac_migration = api.content.get_view('migrate_from_atct', portal, request)
content_types = ['Event']
pac_migration(
migrate=True,
content_types=content_types,
migrate_schemaextended_content=True,
reindex_catalog=False,
patch_searchabletext=True,
)
def migrate_links(context=None):
portal = api.portal.get()
request = getRequest()
pac_migration = api.content.get_view('migrate_from_atct', portal, request)
content_types = ['Link']
pac_migration(
migrate=True,
content_types=content_types,
migrate_schemaextended_content=True,
reindex_catalog=False,
patch_searchabletext=True,
)
def migrate_newsitems(context=None):
portal = api.portal.get()
request = getRequest()
pac_migration = api.content.get_view('migrate_from_atct', portal, request)
content_types = ['News Item']
pac_migration(
migrate=True,
content_types=content_types,
migrate_schemaextended_content=True,
reindex_catalog=False,
patch_searchabletext=True,
)
def migrate_topics(context=None):
portal = api.portal.get()
request = getRequest()
pac_migration = api.content.get_view('migrate_from_atct', portal, request)
content_types = ['Topic']
pac_migration(
migrate=True,
content_types=content_types,
migrate_schemaextended_content=True,
reindex_catalog=False,
patch_searchabletext=True,
)
def migrate_ATBTreeFolder(context=None):
"""Replace very old containers for news, events and Members
"""
portal = api.portal.get()
# unlock all locked items in 'news'
from plone.locking.interfaces import ILockable
for obj in portal['news'].contentValues():
lockable = ILockable(obj)
if lockable.locked():
lockable.unlock()
# create new containers:
if not portal['news'].__class__.__name__ == 'ATBTreeFolder':
log.info('Migrating ATBTreeFolder not needed')
return
log.info('Migrating ATBTreeFolders')
news_new = api.content.create(
container=portal,
type='Folder',
id='news_new',
title=u'Nachrichten',
)
for item in portal.news.contentValues():
api.content.move(
source=item,
target=news_new,
)
api.content.delete(obj=portal['news'], check_linkintegrity=False)
if 'events' in portal and portal['events'].__class__.__name__ == 'ATBTreeFolder':
api.content.delete(obj=portal['events'], check_linkintegrity=False)
if 'Members' in portal and portal['Members'].__class__.__name__ == 'ATBTreeFolder':
api.content.delete(obj=portal['Members'], check_linkintegrity=False)
api.content.rename(obj=portal['news_new'], new_id='news')