Skip to content

Commit

Permalink
Merge pull request #158 from plone/issue155_show_migrateable_types
Browse files Browse the repository at this point in the history
Use meta_type instead of interface to show migrateable types (fix #155)
  • Loading branch information
pbauer committed Jun 3, 2014
2 parents d1d16e7 + 3b9e0f6 commit 6ccf94f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 27 deletions.
6 changes: 6 additions & 0 deletions docs/CHANGES.rst
Expand Up @@ -4,6 +4,12 @@ Changelog
1.2a4 (unreleased)
------------------

- Only show migrateable types (fixes #155)
[pbauer]

- Add logging during and after migration (fixes #156)
[pbauer]

- When replacing the default news and events collections, reverse the
sort order correctly.
[maurits]
Expand Down
6 changes: 3 additions & 3 deletions plone/app/contenttypes/migration/browser.py
Expand Up @@ -142,7 +142,7 @@ def __call__(self,
logger.info("Start migrating %s objects from %s to %s" % (
amount_to_be_migrated,
v['old_meta_type'],
v['new_type_name']))
v['type_name']))

# call the migrator
v['migrator'](portal)
Expand All @@ -153,14 +153,14 @@ def __call__(self,
logger.info("Finished migrating %s objects from %s to %s in %s" % (
amount_to_be_migrated,
v['old_meta_type'],
v['new_type_name'],
v['type_name'],
duration_human))

# some data for the results-page
migrated_types[k] = {}
migrated_types[k]['amount_migrated'] = amount_to_be_migrated
migrated_types[k]['old_meta_type'] = v['old_meta_type']
migrated_types[k]['new_type_name'] = v['new_type_name']
migrated_types[k]['type_name'] = v['type_name']

# if there are blobnewsitems we just migrate them silently.
migration.migrate_blobnewsitems(portal)
Expand Down
30 changes: 16 additions & 14 deletions plone/app/contenttypes/migration/utils.py
Expand Up @@ -32,64 +32,66 @@
'iface': IATFolder,
'migrator': migration.migrate_folders,
'extended_fields': [],
'new_type_name': 'Folder',
'type_name': 'Folder',
'old_meta_type': 'ATFolder',
},
"Document": {
'iface': IATDocument,
'migrator': migration.migrate_documents,
'extended_fields': [],
'new_type_name': 'Document',
'type_name': 'Document',
'old_meta_type': 'ATDocument',
},
# File without blobs
"File": {
'iface': IATFile,
'migrator': migration.migrate_files,
'extended_fields': ['file'],
'new_type_name': 'File',
'extended_fields': [],
'type_name': 'File',
'old_meta_type': 'ATFile',
},
# Image without blobs
"Image": {
'iface': IATImage,
'migrator': migration.migrate_images,
'extended_fields': ['image'],
'new_type_name': 'Image',
'extended_fields': [],
'type_name': 'Image',
'old_meta_type': 'ATImage',
},
"News Item": {
'iface': IATNewsItem,
'migrator': migration.migrate_newsitems,
'extended_fields': [],
'new_type_name': 'News Item',
'type_name': 'News Item',
'old_meta_type': 'ATNewsItem',
},
"Link": {
'iface': IATLink,
'migrator': migration.migrate_links,
'extended_fields': [],
'new_type_name': 'Link',
'type_name': 'Link',
'old_meta_type': 'ATLink',
},
"Event": {
'iface': IATEvent,
'migrator': migration.migrate_events,
'extended_fields': [],
'new_type_name': 'Event',
'type_name': 'Event',
'old_meta_type': 'ATEvent',
},
"BlobImage": {
'iface': IATBlobImage,
'migrator': migration.migrate_blobimages,
'extended_fields': ['image'],
'new_type_name': 'Image',
'old_meta_type': 'ATBlobImage',
'type_name': 'Image',
'old_meta_type': 'ATBlob',
},
"BlobFile": {
'iface': IATBlobFile,
'migrator': migration.migrate_blobfiles,
'extended_fields': ['file'],
'new_type_name': 'File',
'old_meta_type': 'ATBlobFile',
'type_name': 'File',
'old_meta_type': 'ATBlob',
},
}

Expand All @@ -98,7 +100,7 @@
'iface': ICollection,
'migrator': migration.migrate_collections,
'extended_fields': [],
'new_type_name': 'Collection',
'type_name': 'Collection',
'old_meta_type': 'Collection',
}

Expand Down
31 changes: 21 additions & 10 deletions plone/app/contenttypes/migration/vocabularies.py
Expand Up @@ -9,6 +9,12 @@


def get_terms(context, counter, ext_dict, show_extended):
"""Takes dicts of types and their numbers and their extended fields
Returns a list of SimpleVocabularyTerms:
value = meta_type,
token = meta_type,
title = translated_meta_type (number_of_instances) - extended fields: list
"""
results = []
for k, v in counter.iteritems():
if not show_extended:
Expand All @@ -29,17 +35,21 @@ def get_terms(context, counter, ext_dict, show_extended):


def count(brains):
"""Turns a list of brains into a dict {<meta_type>:<number_of_instances>,}
Since Image and File both have the meta_type 'ATBlob' they are handled
differently.
"""
counter = {}
for i in brains:
pt = i.portal_type
if "Blob" in i.meta_type:
for brain in brains:
pt = brain.portal_type
if "Blob" in brain.meta_type:
if pt == "File":
pt = "BlobFile"
else:
pt = "BlobImage"
if not counter.get(pt):
counter[pt] = 0
if not i.meta_type or 'dexterity' in i.meta_type.lower():
if not brain.meta_type or 'dexterity' in brain.meta_type.lower():
# There might be DX types with same iface and meta_type than AT
continue
counter[pt] += 1
Expand All @@ -48,26 +58,27 @@ def count(brains):

def results(context, show_extended=False):
"""Helper method to create the vocabularies used below.
Searches the catalog for AT-meta_types to get all Archetypes content.
If show_extended is true the returned SimpleVocabulary will include
types that are extended beyond what is expected.
"""
ext_dict = {}
ifaces = []
meta_types = []
for k, v in ATCT_LIST.items():
iface = v['iface'].__identifier__
extendend_fields = isSchemaExtended(v['iface'])
expected = v['extended_fields']
is_extended = len(extendend_fields) > len(expected)
if is_extended and show_extended:
ifaces.append(iface)
meta_types.append(v['old_meta_type'])
ext_dict[k] = {}
if expected:
extendend_fields.remove(expected[0])
ext_dict[k]['fields'] = extendend_fields

elif not show_extended and not is_extended:
ifaces.append(iface)

meta_types.append(v['old_meta_type'])
catalog = getToolByName(context, "portal_catalog")
brains = catalog.search({'object_provides': ifaces})
brains = catalog.search({'meta_type': meta_types})
counter = count(brains)

return SimpleVocabulary(get_terms(context,
Expand Down

1 comment on commit 6ccf94f

@mister-roboto
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TESTS FAILED
Mr.Roboto url : http://jenkins.plone.org/roboto/get_info?push=e87ef07f13a243f4bbe99674ea64e773
[SUCCESS] kgs-plone.app.contenttypes-plone-5.0-python-2.7 kgs
[FAILURE] kgs-plone.app.contenttypes-plone-4.3-python-2.6 kgs
[FAILURE] kgs-plone.app.contenttypes-plone-4.3-python-2.7 kgs

Please sign in to comment.