Skip to content

Commit

Permalink
Merge pull request #40 from eea/develop
Browse files Browse the repository at this point in the history
Fix broken brain error at the upgrade svg step - refs #276995
  • Loading branch information
avoinea authored Oct 18, 2024
2 parents 4b4e7ba + 95b42d0 commit cbe6eb3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
5 changes: 5 additions & 0 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

5.5 - (2024-10-18)
---------------------------
* Change: Fix broken brain error at the upgrade svg step - refs #276995
[avoinea]

5.4 - (2024-10-09)
---------------------------
* Fix: Create a content upgrade script to fix SVGs display
Expand Down
33 changes: 25 additions & 8 deletions eea/volto/policy/upgrades/upgrade_svgs/upgrade_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import transaction
from plone.namedfile.utils import getImageInfo
from zope.lifecycleevent import modified
from zope.annotation.interfaces import IAnnotations

logger = logging.getLogger("upgrade_svgs")
logger.setLevel(logging.INFO)
Expand All @@ -12,32 +13,48 @@
def upgrade_svgs(portal):
"""Upgrade SVG dimensions"""
i = 0
for brain in portal.portal_catalog():
obj = brain.getObject()
brains = portal.portal_catalog()
total = len(brains)
for idx, brain in enumerate(brains):
obj = dict()
try:
obj = brain.getObject()
except Exception:
continue # Skip to the next item if there's an error

if (
hasattr(obj, "image") and hasattr(obj.image, "_width") and
hasattr(obj, "image") and
hasattr(obj.image, "_width") and
hasattr(obj.image, "_height")
):
logger.info("Processing %s", obj.absolute_url())

contentType, width, height = getImageInfo(obj.image.data)
if contentType == "image/svg+xml":
logger.info("Processing %s", obj.absolute_url())
obj.image._width = width
obj.image._height = height
modified(obj.image)
anno = IAnnotations(obj)
if "plone.scale" in anno:
del anno["plone.scale"]
modified(obj)
i += 1
if (
hasattr(obj, "preview_image") and
hasattr(obj.preview_image, "_width") and
hasattr(obj.preview_image, "_height")
):
logger.info("Processing %s", obj.absolute_url())
contentType, width, height = getImageInfo(obj.preview_image.data)
if contentType == "image/svg+xml":
logger.info("Processing %s", obj.absolute_url())
obj.preview_image._width = width
obj.preview_image._height = height
modified(obj.preview_image)
anno = IAnnotations(obj)
if "plone.scale" in anno:
del anno["plone.scale"]
modified(obj)
i += 1
if not i % 100:
logger.info(i)
logger.warning("Progress %s/%s", idx, total)
logger.warning("Modified %s items", i)
transaction.commit()
transaction.commit()
2 changes: 1 addition & 1 deletion eea/volto/policy/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.4
5.5

0 comments on commit cbe6eb3

Please sign in to comment.