From e2550f2337771bad02684f81aef52800faace1bb Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 21 Jul 2023 12:50:05 +0200 Subject: [PATCH] Fix upgrade step --- CHANGES.rst | 3 ++- src/design/plone/policy/upgrades.py | 34 +++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 75ab377..449e16a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,8 @@ Changelog 5.0.5 (unreleased) ------------------ -- Nothing changed yet. +- Fix bad upgrade step. + [folix-01] 5.0.4 (2023-07-04) diff --git a/src/design/plone/policy/upgrades.py b/src/design/plone/policy/upgrades.py index d078b30..3514edb 100644 --- a/src/design/plone/policy/upgrades.py +++ b/src/design/plone/policy/upgrades.py @@ -27,7 +27,9 @@ def update_profile(context, profile, run_dependencies=True): - context.runImportStepFromProfile(DEFAULT_PROFILE, profile, run_dependencies) + context.runImportStepFromProfile( + DEFAULT_PROFILE, profile, run_dependencies + ) def update_types(context): @@ -64,7 +66,9 @@ def fix_field_name(blocks): installOrReinstallProduct(api.portal.get(), "collective.volto.formsupport") logger.info("Changing form block fields.") i = 0 - brains = api.content.find(object_provides="plone.restapi.behaviors.IBlocks") + brains = api.content.find( + object_provides="plone.restapi.behaviors.IBlocks" + ) tot = len(brains) fixed_items = [] for brain in brains: @@ -93,7 +97,9 @@ def to_1300(context): def to_1400(context): - old = api.portal.get_registry_record(name="design.plone.policy.twitter_token") + old = api.portal.get_registry_record( + name="design.plone.policy.twitter_token" + ) context.runAllImportStepsFromProfile("profile-design.plone.policy:to_1400") update_registry(context) @@ -174,7 +180,9 @@ def to_1910(context): else: new_sizes.append(size) if "midi 300:65536" not in new_sizes: - new_sizes.insert(new_sizes.index("mini 200:65536") + 1, "midi 300:65536") + new_sizes.insert( + new_sizes.index("mini 200:65536") + 1, "midi 300:65536" + ) api.portal.set_registry_record("plone.allowed_sizes", new_sizes) @@ -235,7 +243,9 @@ def fix_block(blocks): blocks = value.get("blocks", {}) except AttributeError: logger.warning( - "[RICHTEXT] - {} (not converted)".format(brain.getURL()) + "[RICHTEXT] - {} (not converted)".format( + brain.getURL() + ) ) if blocks: res = fix_block(blocks) @@ -263,7 +273,9 @@ def update_folders(context, CHANGES=[], NEW_ITEMS=[]): portal_name = portal.getId() for item in CHANGES: try: - folder = portal.restrictedTraverse("{}{}".format(portal_name, item)) + folder = portal.restrictedTraverse( + "{}{}".format(portal_name, item) + ) old_title = folder.title old_path = "/".join(folder.getPhysicalPath()) api.content.rename(obj=folder, new_id=CHANGES[item][1]) @@ -277,7 +289,9 @@ def update_folders(context, CHANGES=[], NEW_ITEMS=[]): ) ) except KeyError: - logger.info("{} Impossibile modificare {}{}".format(RED, item, ENDC)) + logger.info( + "{} Impossibile modificare {}{}".format(RED, item, ENDC) + ) for item in NEW_ITEMS: folder = portal.restrictedTraverse("{}{}".format(portal_name, item[0])) @@ -370,7 +384,7 @@ def to_3100(context): def to_3101(context): def remove_twitter(blocks_orig): blocks = deepcopy(blocks_orig) - for key, block in blocks.items(): + for key, block in deepcopy(blocks).items(): if block.get("@type", "") == "twitter_posts": del blocks[key] @@ -391,7 +405,9 @@ def remove_twitter(blocks_orig): blocks = value.get("blocks", {}) except AttributeError: logger.warning( - "[BLOCK] - {} (not converted)".format(brain.getURL()) + "[BLOCK] - {} (not converted)".format( + brain.getURL() + ) ) if blocks: item.blocks = remove_twitter(blocks)