diff --git a/ftw/upgrade/migration.py b/ftw/upgrade/migration.py index e0bb6654..00d5a2ca 100644 --- a/ftw/upgrade/migration.py +++ b/ftw/upgrade/migration.py @@ -39,6 +39,14 @@ import pkg_resources +HAS_LANG_REFS = False +try: + from plone.multilingual.interfaces import ITranslationManager + HAS_LANG_REFS = True +except ImportError: + pass + + try: pkg_resources.get_distribution('archetypes.referencebrowserwidget') except pkg_resources.DistributionNotFound: @@ -56,6 +64,7 @@ class IATReferenceField(Interface): SKIP_MODIFIED_EVENT = 32 UNMAPPED_FIELDS_BACKUP_ANN_KEY = 'ftw.upgrade.migration:fields_backup' +LANGUAGE_INFORMATIONS_ANN_KEY = 'ftw.upgrade.migration:language_info' LOG = logging.getLogger('ftw.upgrade.migration') @@ -74,12 +83,9 @@ class IATReferenceField(Interface): DUBLIN_CORE_IGNORES = ( 'allowDiscussion', - 'contributors', - 'creators', 'nextPreviousEnabled', 'rights', 'language', - 'relatedItems', ) @@ -188,6 +194,7 @@ def __init__(self, self.dump_and_remove_references, ) self.steps_after_clone = ( + self.store_language_informations, self.migrate_intid, self.migrate_field_values, self.add_relations_to_relation_catalog, @@ -213,6 +220,15 @@ def migrate_object(self, old_object): list(self.final_steps)) return new_object + def store_language_informations(self, old_object, new_object): + if HAS_LANG_REFS: + languages = ITranslationManager(old_object, None) + if languages: + annotations = IAnnotations(new_object) + storage = annotations[LANGUAGE_INFORMATIONS_ANN_KEY] = PersistentMapping() + for language, obj in languages.get_translations().items(): + storage[language] = '/'.join(obj.getPhysicalPath()) + def dump_and_remove_references(self, old_object): """We can only remove the relations from the reference_catalog as long as we did not replace the object (clone_object()), @@ -379,6 +395,11 @@ def get_at_field_values(self, old_object): value = self.removed_field_values.get( fieldname, field.getRaw(old_object)) + + if field.widget.__class__.__name__ == 'LinesWidget' and len(value): + # LinesField/Widget returns a weird raw value + # Example: (u'line1\nline2', ) + value = tuple(value[0].split('\n')) value = self.normalize_at_field_value(field, fieldname, value) yield fieldname, value