Skip to content

Commit

Permalink
Merge pull request #37 from eea/develop
Browse files Browse the repository at this point in the history
fix: Create a content upgrade script to fix SVGs display [@dobri1408 - refs #276995]
  • Loading branch information
avoinea authored Oct 9, 2024
2 parents 84a5a97 + d702774 commit 4b4e7ba
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 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.4 - (2024-10-09)
---------------------------
* Fix: Create a content upgrade script to fix SVGs display
[@dobri1408 - refs #276995]

5.3 - (2024-08-23)
---------------------------
* Change: Develop
Expand Down
2 changes: 1 addition & 1 deletion eea/volto/policy/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<version>5.0</version>
<version>5.4</version>
<dependencies>
<dependency>profile-plone.volto:default</dependency>
</dependencies>
Expand Down
12 changes: 12 additions & 0 deletions eea/volto/policy/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,16 @@

</genericsetup:upgradeSteps>

<genericsetup:upgradeSteps
source="5.0"
destination="5.4"
profile="eea.volto.policy:default">

<genericsetup:upgradeStep
title="Fix Svg width and height"
handler="eea.volto.policy.upgrades.upgrade_svgs.upgrade_svg.upgrade_svgs"
/>

</genericsetup:upgradeSteps>

</configure>
43 changes: 43 additions & 0 deletions eea/volto/policy/upgrades/upgrade_svgs/upgrade_svg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Upgrade step for svgs to fix width and height"""

import logging
import transaction
from plone.namedfile.utils import getImageInfo
from zope.lifecycleevent import modified

logger = logging.getLogger("upgrade_svgs")
logger.setLevel(logging.INFO)


def upgrade_svgs(portal):
"""Upgrade SVG dimensions"""
i = 0
for brain in portal.portal_catalog():
obj = brain.getObject()
if (
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":
obj.image._width = width
obj.image._height = height
modified(obj.image)
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":
obj.preview_image._width = width
obj.preview_image._height = height
modified(obj.preview_image)
i += 1
if not i % 100:
logger.info(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.3
5.4

0 comments on commit 4b4e7ba

Please sign in to comment.