|
1 | 1 | # -*- coding: utf-8 -*- |
2 | | -from Acquisition import aq_base |
3 | | -from collective.volto.blocksfield.field import BlocksField |
4 | | -from copy import deepcopy |
5 | 2 | from design.plone.contenttypes.events.common import createStructure |
6 | 3 | from design.plone.contenttypes.events.common import SUBFOLDERS_MAPPING |
7 | 4 | from design.plone.contenttypes.utils import create_default_blocks |
|
11 | 8 | from plone.app.linkintegrity.interfaces import IRetriever |
12 | 9 | from plone.app.upgrade.utils import installOrReinstallProduct |
13 | 10 | from plone.app.uuid.utils import uuidToObject |
14 | | -from plone.dexterity.utils import iterSchemata |
15 | 11 | from Products.CMFPlone.interfaces import ISelectableConstrainTypes |
16 | | -from zope.schema import getFields |
17 | 12 |
|
18 | 13 | import logging |
19 | 14 | import transaction |
@@ -321,58 +316,15 @@ def to_7321(context): |
321 | 316 | logger.info("### START REFRESH MODULE LINKS ###") |
322 | 317 |
|
323 | 318 | portal_enhancedlinks = api.portal.get_tool("portal_enhancedlinks") |
324 | | - |
325 | | - def refresh_module_links(blocks, url): |
326 | | - for block in blocks.values(): |
327 | | - if block.get("@type", "") != "slate": |
328 | | - continue |
329 | | - for row in block.get("value", []): |
330 | | - for child in row.get("children", []): |
331 | | - # find slate links with resolveuid |
332 | | - if child.get("type") != "link": |
333 | | - continue |
334 | | - link_url = child.get("data", {}).get("url", "") |
335 | | - if "resolveuid/" not in link_url: |
336 | | - continue |
337 | | - |
338 | | - # extract UID |
339 | | - uid = link_url.split("resolveuid/", 1)[1].split("/", 1)[0] |
340 | | - target = uuidToObject(uid, unrestricted=True) |
341 | | - if not target or target.portal_type != "Modulo": |
342 | | - continue |
343 | | - |
344 | | - portal_enhancedlinks.get_enhanced_link(uid, force_reload=True) |
345 | | - logger.info("- {} -> {}".format(url, uid)) |
346 | | - |
347 | | - # fix root |
348 | | - portal = api.portal.get() |
349 | | - if getattr(portal, "blocks", ""): |
350 | | - portal_blocks = deepcopy(portal.blocks) |
351 | | - refresh_module_links(portal_blocks, portal.absolute_url()) |
352 | | - |
353 | | - # fix blocks in contents |
354 | | - pc = api.portal.get_tool(name="portal_catalog") |
355 | | - brains = pc() |
356 | | - tot = len(brains) |
| 319 | + uids = portal_enhancedlinks._enhanced_links.keys() |
| 320 | + tot = len(uids) |
357 | 321 | i = 0 |
358 | | - for brain in brains: |
| 322 | + for uid in uids: |
359 | 323 | i += 1 |
360 | 324 | if i % 1000 == 0: |
361 | 325 | logger.info("Progress: {}/{}".format(i, tot)) |
362 | | - item = aq_base(brain.getObject()) |
363 | | - if getattr(item, "blocks", {}): |
364 | | - blocks = deepcopy(item.blocks) |
365 | | - if blocks: |
366 | | - refresh_module_links(blocks, brain.getURL()) |
367 | | - for schema in iterSchemata(item): |
368 | | - # fix blocks in blocksfields |
369 | | - for name, field in getFields(schema).items(): |
370 | | - if name == "blocks": |
371 | | - continue |
372 | | - elif isinstance(field, BlocksField): |
373 | | - value = deepcopy(field.get(item)) |
374 | | - if not value or not isinstance(value, dict): |
375 | | - continue |
376 | | - blocks = value.get("blocks", {}) |
377 | | - if blocks: |
378 | | - refresh_module_links(blocks, brain.getURL()) |
| 326 | + target = uuidToObject(uid, unrestricted=True) |
| 327 | + if not target or target.portal_type != "Modulo": |
| 328 | + continue |
| 329 | + portal_enhancedlinks.get_enhanced_link(uid, force_reload=True) |
| 330 | + logger.info("- {}".format(uid)) |
0 commit comments