From 746b6f8cefe77ef56cac68be91e0c74db135f23c Mon Sep 17 00:00:00 2001 From: Simone De Santis Date: Fri, 6 Mar 2026 17:12:21 +0100 Subject: [PATCH 01/15] Add mime_type indexer and upgrade step for Modulo reindexing --- src/design/plone/contenttypes/indexers/configure.zcml | 4 ++++ src/design/plone/contenttypes/indexers/modulo.py | 9 +++++++++ .../plone/contenttypes/profiles/default/metadata.xml | 2 +- src/design/plone/contenttypes/upgrades/configure.zcml | 7 +++++++ src/design/plone/contenttypes/upgrades/to_730x.py | 8 ++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/design/plone/contenttypes/indexers/modulo.py diff --git a/src/design/plone/contenttypes/indexers/configure.zcml b/src/design/plone/contenttypes/indexers/configure.zcml index 7a660671..75018257 100644 --- a/src/design/plone/contenttypes/indexers/configure.zcml +++ b/src/design/plone/contenttypes/indexers/configure.zcml @@ -81,6 +81,10 @@ factory=".punto_di_contatto.PuntoDiContattoMoreTextToIndex" name="IPuntoDiContatto" /> + - 7320 + 7321 profile-redturtle.bandi:default profile-collective.venue:default diff --git a/src/design/plone/contenttypes/upgrades/configure.zcml b/src/design/plone/contenttypes/upgrades/configure.zcml index 5e9842d7..81108469 100644 --- a/src/design/plone/contenttypes/upgrades/configure.zcml +++ b/src/design/plone/contenttypes/upgrades/configure.zcml @@ -969,4 +969,11 @@ destination="7320" handler=".to_730x.to_7320" /> + diff --git a/src/design/plone/contenttypes/upgrades/to_730x.py b/src/design/plone/contenttypes/upgrades/to_730x.py index af406683..1ad6e093 100644 --- a/src/design/plone/contenttypes/upgrades/to_730x.py +++ b/src/design/plone/contenttypes/upgrades/to_730x.py @@ -301,3 +301,11 @@ def to_7320(context): links = retriever.retrieveLinks() refs = getObjectsFromLinks(servizio, links) updateReferences(servizio, refs) + + +def to_7321(context): + update_catalog(context) + brains = api.content.find(portal_type="Modulo") + logger.info("Reindexing mime_type for {} Modulo objects".format(len(brains))) + for brain in brains: + brain.getObject().reindexObject(idxs=["mime_type"]) From 6313cf56d1bd0ba379c6e568a2660fcb193e17a8 Mon Sep 17 00:00:00 2001 From: Simone De Santis Date: Mon, 9 Mar 2026 15:14:47 +0100 Subject: [PATCH 02/15] Add link refresh logic for Modulo objects in upgrade script --- .../plone/contenttypes/upgrades/to_730x.py | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/design/plone/contenttypes/upgrades/to_730x.py b/src/design/plone/contenttypes/upgrades/to_730x.py index 1ad6e093..491c6b34 100644 --- a/src/design/plone/contenttypes/upgrades/to_730x.py +++ b/src/design/plone/contenttypes/upgrades/to_730x.py @@ -1,4 +1,7 @@ # -*- coding: utf-8 -*- +from Acquisition import aq_base +from collective.volto.blocksfield.field import BlocksField +from copy import deepcopy from design.plone.contenttypes.events.common import createStructure from design.plone.contenttypes.events.common import SUBFOLDERS_MAPPING from design.plone.contenttypes.utils import create_default_blocks @@ -7,8 +10,12 @@ from plone.app.linkintegrity.handlers import updateReferences from plone.app.linkintegrity.interfaces import IRetriever from plone.app.upgrade.utils import installOrReinstallProduct +from plone.app.uuid.utils import uuidToObject +from plone.dexterity.utils import iterSchemata from Products.CMFPlone.interfaces import ISelectableConstrainTypes +from zope.schema import getFields +import json import logging import transaction @@ -309,3 +316,64 @@ def to_7321(context): logger.info("Reindexing mime_type for {} Modulo objects".format(len(brains))) for brain in brains: brain.getObject().reindexObject(idxs=["mime_type"]) + + logger.info("### START REFRESH MODULE LINKS ###") + + portal_enhancedlinks = api.portal.get_tool("portal_enhancedlinks") + + def refresh_module_links(blocks, url): + for block in blocks.values(): + if block.get("@type", "") != "slate": + continue + for row in block.get("value", []): + for child in row.get("children", []): + # find slate links with resolveuid + if child.get("type") != "link": + continue + link_url = child.get("data", {}).get("url", "") + if "resolveuid/" not in link_url: + continue + + # extract UID + uid = link_url.split("resolveuid/", 1)[1].split("/", 1)[0] + target = uuidToObject(uid, unrestricted=True) + if not target or target.portal_type != "Modulo": + continue + + portal_enhancedlinks.get_enhanced_link(uid, force_reload=True) + logger.info("- {} -> {}".format(url, uid)) + + # fix root + portal = api.portal.get() + if getattr(portal, "blocks", ""): + portal_blocks = json.loads(portal.blocks) + refresh_module_links(portal_blocks, portal.absolute_url()) + + # fix blocks in contents + pc = api.portal.get_tool(name="portal_catalog") + brains = pc() + tot = len(brains) + i = 0 + for brain in brains: + i += 1 + if i % 1000 == 0: + logger.info("Progress: {}/{}".format(i, tot)) + item = aq_base(brain.getObject()) + if getattr(item, "blocks", {}): + blocks = deepcopy(item.blocks) + if blocks: + refresh_module_links(blocks, brain.getURL()) + for schema in iterSchemata(item): + # fix blocks in blocksfields + for name, field in getFields(schema).items(): + if name == "blocks": + blocks = deepcopy(item.blocks) + if blocks: + refresh_module_links(blocks, brain.getURL()) + elif isinstance(field, BlocksField): + value = deepcopy(field.get(item)) + if not value or not isinstance(value, dict): + continue + blocks = value.get("blocks", {}) + if blocks: + refresh_module_links(blocks, brain.getURL()) From 0d66d9bf72a10002f2494f8a9f7238d5b118140c Mon Sep 17 00:00:00 2001 From: Simone De Santis Date: Mon, 9 Mar 2026 15:52:12 +0100 Subject: [PATCH 03/15] Fix portal blocks handling by using deepcopy to prevent mutation --- src/design/plone/contenttypes/upgrades/to_730x.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/design/plone/contenttypes/upgrades/to_730x.py b/src/design/plone/contenttypes/upgrades/to_730x.py index 491c6b34..82c9a7ea 100644 --- a/src/design/plone/contenttypes/upgrades/to_730x.py +++ b/src/design/plone/contenttypes/upgrades/to_730x.py @@ -346,7 +346,7 @@ def refresh_module_links(blocks, url): # fix root portal = api.portal.get() if getattr(portal, "blocks", ""): - portal_blocks = json.loads(portal.blocks) + portal_blocks = deepcopy(portal.blocks) refresh_module_links(portal_blocks, portal.absolute_url()) # fix blocks in contents From 96570bfbddf5540cda34c8466fce295b4d18cb25 Mon Sep 17 00:00:00 2001 From: Simone De Santis Date: Mon, 9 Mar 2026 17:01:55 +0100 Subject: [PATCH 04/15] Add logging for re-aligning mime-types in to_7321 upgrade step --- src/design/plone/contenttypes/upgrades/to_730x.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/design/plone/contenttypes/upgrades/to_730x.py b/src/design/plone/contenttypes/upgrades/to_730x.py index 82c9a7ea..ac4f114e 100644 --- a/src/design/plone/contenttypes/upgrades/to_730x.py +++ b/src/design/plone/contenttypes/upgrades/to_730x.py @@ -311,6 +311,9 @@ def to_7320(context): def to_7321(context): + + logger.info("### RE-ALIGN MODULES MIME-TYPES ###") + update_catalog(context) brains = api.content.find(portal_type="Modulo") logger.info("Reindexing mime_type for {} Modulo objects".format(len(brains))) From 99f55802ed62d45f75cb9ce60e1d42c60dc46e66 Mon Sep 17 00:00:00 2001 From: Simone De Santis Date: Mon, 9 Mar 2026 17:03:39 +0100 Subject: [PATCH 05/15] Remove unused json import in to_730x upgrade script --- src/design/plone/contenttypes/upgrades/to_730x.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/design/plone/contenttypes/upgrades/to_730x.py b/src/design/plone/contenttypes/upgrades/to_730x.py index ac4f114e..18b912a4 100644 --- a/src/design/plone/contenttypes/upgrades/to_730x.py +++ b/src/design/plone/contenttypes/upgrades/to_730x.py @@ -15,10 +15,10 @@ from Products.CMFPlone.interfaces import ISelectableConstrainTypes from zope.schema import getFields -import json import logging import transaction + logger = logging.getLogger(__name__) DEFAULT_PROFILE = "profile-design.plone.contenttypes:default" From f2058ccb9985078058e191062a7836c6c7b86309 Mon Sep 17 00:00:00 2001 From: Simone De Santis Date: Mon, 9 Mar 2026 17:12:47 +0100 Subject: [PATCH 06/15] black --- src/design/plone/contenttypes/upgrades/to_730x.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/design/plone/contenttypes/upgrades/to_730x.py b/src/design/plone/contenttypes/upgrades/to_730x.py index 18b912a4..aa9e498d 100644 --- a/src/design/plone/contenttypes/upgrades/to_730x.py +++ b/src/design/plone/contenttypes/upgrades/to_730x.py @@ -18,7 +18,6 @@ import logging import transaction - logger = logging.getLogger(__name__) DEFAULT_PROFILE = "profile-design.plone.contenttypes:default" From 63532dbbc9687b1da1c2fdf160412a235087f56a Mon Sep 17 00:00:00 2001 From: Simone De Santis Date: Tue, 10 Mar 2026 10:32:29 +0100 Subject: [PATCH 07/15] Remove unnecessary deepcopy for blocks in to_7321 upgrade step --- src/design/plone/contenttypes/upgrades/to_730x.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/design/plone/contenttypes/upgrades/to_730x.py b/src/design/plone/contenttypes/upgrades/to_730x.py index aa9e498d..e788d5d6 100644 --- a/src/design/plone/contenttypes/upgrades/to_730x.py +++ b/src/design/plone/contenttypes/upgrades/to_730x.py @@ -369,9 +369,7 @@ def refresh_module_links(blocks, url): # fix blocks in blocksfields for name, field in getFields(schema).items(): if name == "blocks": - blocks = deepcopy(item.blocks) - if blocks: - refresh_module_links(blocks, brain.getURL()) + continue elif isinstance(field, BlocksField): value = deepcopy(field.get(item)) if not value or not isinstance(value, dict): From 0ec005280a202e76d2f407518f7a6a272cbb5cbe Mon Sep 17 00:00:00 2001 From: Simone De Santis Date: Tue, 10 Mar 2026 11:21:32 +0100 Subject: [PATCH 08/15] Remove update_catalog call from to_7321 upgrade step --- src/design/plone/contenttypes/upgrades/to_730x.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/design/plone/contenttypes/upgrades/to_730x.py b/src/design/plone/contenttypes/upgrades/to_730x.py index e788d5d6..0a5716ce 100644 --- a/src/design/plone/contenttypes/upgrades/to_730x.py +++ b/src/design/plone/contenttypes/upgrades/to_730x.py @@ -313,7 +313,6 @@ def to_7321(context): logger.info("### RE-ALIGN MODULES MIME-TYPES ###") - update_catalog(context) brains = api.content.find(portal_type="Modulo") logger.info("Reindexing mime_type for {} Modulo objects".format(len(brains))) for brain in brains: From 59f630c49f036e73c0bcb500b30264f58a2118ab Mon Sep 17 00:00:00 2001 From: Simone De Santis Date: Tue, 10 Mar 2026 11:42:04 +0100 Subject: [PATCH 09/15] Refactor to_7321 upgrade step: streamline module link refresh logic and remove unnecessary deepcopy --- .../plone/contenttypes/upgrades/to_730x.py | 64 +++---------------- 1 file changed, 8 insertions(+), 56 deletions(-) diff --git a/src/design/plone/contenttypes/upgrades/to_730x.py b/src/design/plone/contenttypes/upgrades/to_730x.py index 0a5716ce..26b03dab 100644 --- a/src/design/plone/contenttypes/upgrades/to_730x.py +++ b/src/design/plone/contenttypes/upgrades/to_730x.py @@ -1,7 +1,4 @@ # -*- coding: utf-8 -*- -from Acquisition import aq_base -from collective.volto.blocksfield.field import BlocksField -from copy import deepcopy from design.plone.contenttypes.events.common import createStructure from design.plone.contenttypes.events.common import SUBFOLDERS_MAPPING from design.plone.contenttypes.utils import create_default_blocks @@ -11,9 +8,7 @@ from plone.app.linkintegrity.interfaces import IRetriever from plone.app.upgrade.utils import installOrReinstallProduct from plone.app.uuid.utils import uuidToObject -from plone.dexterity.utils import iterSchemata from Products.CMFPlone.interfaces import ISelectableConstrainTypes -from zope.schema import getFields import logging import transaction @@ -321,58 +316,15 @@ def to_7321(context): logger.info("### START REFRESH MODULE LINKS ###") portal_enhancedlinks = api.portal.get_tool("portal_enhancedlinks") - - def refresh_module_links(blocks, url): - for block in blocks.values(): - if block.get("@type", "") != "slate": - continue - for row in block.get("value", []): - for child in row.get("children", []): - # find slate links with resolveuid - if child.get("type") != "link": - continue - link_url = child.get("data", {}).get("url", "") - if "resolveuid/" not in link_url: - continue - - # extract UID - uid = link_url.split("resolveuid/", 1)[1].split("/", 1)[0] - target = uuidToObject(uid, unrestricted=True) - if not target or target.portal_type != "Modulo": - continue - - portal_enhancedlinks.get_enhanced_link(uid, force_reload=True) - logger.info("- {} -> {}".format(url, uid)) - - # fix root - portal = api.portal.get() - if getattr(portal, "blocks", ""): - portal_blocks = deepcopy(portal.blocks) - refresh_module_links(portal_blocks, portal.absolute_url()) - - # fix blocks in contents - pc = api.portal.get_tool(name="portal_catalog") - brains = pc() - tot = len(brains) + uids = portal_enhancedlinks._enhanced_links.keys() + tot = len(uids) i = 0 - for brain in brains: + for uid in uids: i += 1 if i % 1000 == 0: logger.info("Progress: {}/{}".format(i, tot)) - item = aq_base(brain.getObject()) - if getattr(item, "blocks", {}): - blocks = deepcopy(item.blocks) - if blocks: - refresh_module_links(blocks, brain.getURL()) - for schema in iterSchemata(item): - # fix blocks in blocksfields - for name, field in getFields(schema).items(): - if name == "blocks": - continue - elif isinstance(field, BlocksField): - value = deepcopy(field.get(item)) - if not value or not isinstance(value, dict): - continue - blocks = value.get("blocks", {}) - if blocks: - refresh_module_links(blocks, brain.getURL()) + target = uuidToObject(uid, unrestricted=True) + if not target or target.portal_type != "Modulo": + continue + portal_enhancedlinks.get_enhanced_link(uid, force_reload=True) + logger.info("- {}".format(uid)) From 2e67bdd88ecc4a73273de351705e26c0c0ecae6d Mon Sep 17 00:00:00 2001 From: TheSaintSimon Date: Tue, 10 Mar 2026 12:17:00 +0100 Subject: [PATCH 10/15] changes.srt --- CHANGES.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 75150f9b..9e2544e3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,8 @@ Changelog 6.3.16 (unreleased) ------------------- -- Nothing changed yet. +- Reindex mime_type for Modulo items and refresh cached enhanced link data so links to module files show the correct file type. + [TheSaintSimon] 6.3.15 (2026-01-29) From a5bd66b3cee7e8a7679e812064c3edb031db0fcf Mon Sep 17 00:00:00 2001 From: TheSaintSimon Date: Tue, 10 Mar 2026 19:43:34 +0100 Subject: [PATCH 11/15] Add unit test for upgrade to_7321 --- .../tests/test_upgrade_to_7321.py | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/design/plone/contenttypes/tests/test_upgrade_to_7321.py diff --git a/src/design/plone/contenttypes/tests/test_upgrade_to_7321.py b/src/design/plone/contenttypes/tests/test_upgrade_to_7321.py new file mode 100644 index 00000000..1b0dfecd --- /dev/null +++ b/src/design/plone/contenttypes/tests/test_upgrade_to_7321.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +from design.plone.contenttypes.testing import ( + DESIGN_PLONE_CONTENTTYPES_INTEGRATION_TESTING, +) +from design.plone.contenttypes.upgrades.to_730x import to_7321 +from plone import api +from plone.app.testing import setRoles +from plone.app.testing import TEST_USER_ID +from plone.namedfile.file import NamedBlobFile + +import os +import unittest + + +class TestUpgradeTo7321(unittest.TestCase): + layer = DESIGN_PLONE_CONTENTTYPES_INTEGRATION_TESTING + + def setUp(self): + self.portal = self.layer["portal"] + setRoles(self.portal, TEST_USER_ID, ["Manager"]) + + filename = os.path.join(os.path.dirname(__file__), "example.pdf") + with open(filename, "rb") as pdf_file: + pdf_data = pdf_file.read() + + # Build a real Modulo with a PDF as main file. + self.documento = api.content.create( + container=self.portal, + type="Documento", + title="Documento", + ) + self.modulo = api.content.create( + container=self.documento, + type="Modulo", + title="Modulo", + file_principale=NamedBlobFile( + data=pdf_data, + filename="example.pdf", + contentType="application/pdf", + ), + ) + self.enhancedlinks_tool = api.portal.get_tool("portal_enhancedlinks") + # Simulate the stale cache entry that the upgrade has to refresh. + self.enhancedlinks_tool._enhanced_links[self.modulo.UID()] = { + "getObjSize": "1 KB", + "mime_type": "text/plain", + } + + def test_to_7321_refreshes_modulo_mime_type_cache(self): + # Start from the broken cached mime type. + self.assertEqual( + self.enhancedlinks_tool.get_enhanced_link(self.modulo.UID())["mime_type"], + "text/plain", + ) + + # The upgrade reindexes Modulo mime_type and refreshes enhanced links. + to_7321(self.portal) + + # After the refresh the cache must reflect the PDF mime type. + self.assertEqual( + self.enhancedlinks_tool.get_enhanced_link(self.modulo.UID())["mime_type"], + "application/pdf", + ) From 12843ae819fb4f1b78ae47d48678ca0c21b3c0ac Mon Sep 17 00:00:00 2001 From: TheSaintSimon Date: Wed, 11 Mar 2026 09:45:25 +0100 Subject: [PATCH 12/15] Add unit tests for Modulo mime type handling and cache refresh --- ...de_to_7321.py => test_modulo_mime_type.py} | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) rename src/design/plone/contenttypes/tests/{test_upgrade_to_7321.py => test_modulo_mime_type.py} (75%) diff --git a/src/design/plone/contenttypes/tests/test_upgrade_to_7321.py b/src/design/plone/contenttypes/tests/test_modulo_mime_type.py similarity index 75% rename from src/design/plone/contenttypes/tests/test_upgrade_to_7321.py rename to src/design/plone/contenttypes/tests/test_modulo_mime_type.py index 1b0dfecd..a9a8cfa6 100644 --- a/src/design/plone/contenttypes/tests/test_upgrade_to_7321.py +++ b/src/design/plone/contenttypes/tests/test_modulo_mime_type.py @@ -12,7 +12,7 @@ import unittest -class TestUpgradeTo7321(unittest.TestCase): +class TestModuloMimeType(unittest.TestCase): layer = DESIGN_PLONE_CONTENTTYPES_INTEGRATION_TESTING def setUp(self): @@ -39,6 +39,16 @@ def setUp(self): contentType="application/pdf", ), ) + self.modulo_2 = api.content.create( + container=self.documento, + type="Modulo", + title="Modulo_2", + file_principale=NamedBlobFile( + data=pdf_data, + filename="example.pdf", + contentType="application/pdf", + ), + ) self.enhancedlinks_tool = api.portal.get_tool("portal_enhancedlinks") # Simulate the stale cache entry that the upgrade has to refresh. self.enhancedlinks_tool._enhanced_links[self.modulo.UID()] = { @@ -61,3 +71,12 @@ def test_to_7321_refreshes_modulo_mime_type_cache(self): self.enhancedlinks_tool.get_enhanced_link(self.modulo.UID())["mime_type"], "application/pdf", ) + + def test_modulo_mime_type_indexer(self): + # The indexer should return the correct mime type for the Modulo. + + catalog = api.portal.get_tool("portal_catalog") + results = catalog(UID=self.modulo_2.UID()) + brain = results[0] + + self.assertEqual(brain.mime_type, "application/pdf") From d954035b2576f92676a29c1728cc9eb51bdb187e Mon Sep 17 00:00:00 2001 From: TheSaintSimon Date: Thu, 26 Mar 2026 17:04:33 +0100 Subject: [PATCH 13/15] Refine modulo mime type upgrade and tests --- CHANGES.rst | 2 +- src/design/plone/contenttypes/upgrades/to_730x.py | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 9e2544e3..90b34468 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,7 @@ Changelog 6.3.16 (unreleased) ------------------- -- Reindex mime_type for Modulo items and refresh cached enhanced link data so links to module files show the correct file type. +- Fixed file type shown for links to Modulo files. [TheSaintSimon] diff --git a/src/design/plone/contenttypes/upgrades/to_730x.py b/src/design/plone/contenttypes/upgrades/to_730x.py index 26b03dab..3eea297d 100644 --- a/src/design/plone/contenttypes/upgrades/to_730x.py +++ b/src/design/plone/contenttypes/upgrades/to_730x.py @@ -7,7 +7,6 @@ from plone.app.linkintegrity.handlers import updateReferences from plone.app.linkintegrity.interfaces import IRetriever from plone.app.upgrade.utils import installOrReinstallProduct -from plone.app.uuid.utils import uuidToObject from Products.CMFPlone.interfaces import ISelectableConstrainTypes import logging @@ -316,15 +315,13 @@ def to_7321(context): logger.info("### START REFRESH MODULE LINKS ###") portal_enhancedlinks = api.portal.get_tool("portal_enhancedlinks") - uids = portal_enhancedlinks._enhanced_links.keys() - tot = len(uids) - i = 0 - for uid in uids: - i += 1 + cached_uids = portal_enhancedlinks._enhanced_links + tot = len(brains) + for i, brain in enumerate(brains, start=1): if i % 1000 == 0: logger.info("Progress: {}/{}".format(i, tot)) - target = uuidToObject(uid, unrestricted=True) - if not target or target.portal_type != "Modulo": + uid = brain.UID + if uid not in cached_uids: continue portal_enhancedlinks.get_enhanced_link(uid, force_reload=True) logger.info("- {}".format(uid)) From 55c63da4a1d5ba6c1662c6316a668839cc29dfb2 Mon Sep 17 00:00:00 2001 From: TheSaintSimon Date: Fri, 27 Mar 2026 09:40:59 +0100 Subject: [PATCH 14/15] Refine modulo mime type upgrade step --- src/design/plone/contenttypes/upgrades/to_730x.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/design/plone/contenttypes/upgrades/to_730x.py b/src/design/plone/contenttypes/upgrades/to_730x.py index 3eea297d..e87f750d 100644 --- a/src/design/plone/contenttypes/upgrades/to_730x.py +++ b/src/design/plone/contenttypes/upgrades/to_730x.py @@ -309,17 +309,13 @@ def to_7321(context): brains = api.content.find(portal_type="Modulo") logger.info("Reindexing mime_type for {} Modulo objects".format(len(brains))) - for brain in brains: - brain.getObject().reindexObject(idxs=["mime_type"]) - - logger.info("### START REFRESH MODULE LINKS ###") - portal_enhancedlinks = api.portal.get_tool("portal_enhancedlinks") cached_uids = portal_enhancedlinks._enhanced_links tot = len(brains) for i, brain in enumerate(brains, start=1): if i % 1000 == 0: logger.info("Progress: {}/{}".format(i, tot)) + brain.getObject().reindexObject(idxs=["mime_type"]) uid = brain.UID if uid not in cached_uids: continue From 99dd06aa712d373f5e8f6adb3c95b823c388a5c5 Mon Sep 17 00:00:00 2001 From: TheSaintSimon Date: Fri, 3 Apr 2026 11:45:55 +0200 Subject: [PATCH 15/15] Update changelog for Modulo mime type indexing and cache refresh improvements --- CHANGES.rst | 5 ++++- .../tests/test_modulo_mime_type.py | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 90b34468..47d0662a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,10 @@ Changelog 6.3.16 (unreleased) ------------------- -- Fixed file type shown for links to Modulo files. +- Modulo: ``mime_type`` is now indexed as the mime type of ``file_principale`` + (the main attached file). The ``to_7321`` upgrade step re-aligns the catalog + index and refreshes stale ``portal_enhancedlinks`` cache entries for existing + Modulo objects. [TheSaintSimon] diff --git a/src/design/plone/contenttypes/tests/test_modulo_mime_type.py b/src/design/plone/contenttypes/tests/test_modulo_mime_type.py index a9a8cfa6..ba0239a5 100644 --- a/src/design/plone/contenttypes/tests/test_modulo_mime_type.py +++ b/src/design/plone/contenttypes/tests/test_modulo_mime_type.py @@ -49,17 +49,18 @@ def setUp(self): contentType="application/pdf", ), ) - self.enhancedlinks_tool = api.portal.get_tool("portal_enhancedlinks") + + def test_to_7321_refreshes_modulo_mime_type_cache(self): + enhancedlinks_tool = api.portal.get_tool("portal_enhancedlinks") # Simulate the stale cache entry that the upgrade has to refresh. - self.enhancedlinks_tool._enhanced_links[self.modulo.UID()] = { + enhancedlinks_tool._enhanced_links[self.modulo.UID()] = { "getObjSize": "1 KB", "mime_type": "text/plain", } - def test_to_7321_refreshes_modulo_mime_type_cache(self): # Start from the broken cached mime type. self.assertEqual( - self.enhancedlinks_tool.get_enhanced_link(self.modulo.UID())["mime_type"], + enhancedlinks_tool.get_enhanced_link(self.modulo.UID())["mime_type"], "text/plain", ) @@ -68,10 +69,17 @@ def test_to_7321_refreshes_modulo_mime_type_cache(self): # After the refresh the cache must reflect the PDF mime type. self.assertEqual( - self.enhancedlinks_tool.get_enhanced_link(self.modulo.UID())["mime_type"], + enhancedlinks_tool.get_enhanced_link(self.modulo.UID())["mime_type"], "application/pdf", ) + def test_modulo_base_tool_mime_type(self): + # Without any stale cache, the tool should already have the correct + # mime type for the Modulo (taken from file_principale). + enhancedlinks_tool = api.portal.get_tool("portal_enhancedlinks") + result = enhancedlinks_tool.get_enhanced_link(self.modulo.UID()) + self.assertEqual(result["mime_type"], "application/pdf") + def test_modulo_mime_type_indexer(self): # The indexer should return the correct mime type for the Modulo.