Skip to content

Commit

Permalink
Add a migrate browserview to migrate content to V3 (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
sneridagh authored Mar 12, 2024
1 parent 6cd141c commit 176e07f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/kitconcept/voltolighttheme/browser/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from plone.protect.interfaces import IDisableCSRFProtection
from plone.restapi.blocks import visit_blocks
from Products.Five.browser import BrowserView
from zope.interface import alsoProvides

import logging
import transaction


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

# If you updated or extended the colors mappings, you should update this with the new values
COLOR_MAP = {
"grey": {
"--background-color": "#ecebeb",
},
"transparent": {
"--background-color": "transparent",
},
}


def migrate_backgroundColor(portal):
i = 0
output = ""
for brain in portal.portal_catalog(
object_provides="plone.restapi.behaviors.IBlocks"
):
obj = brain.getObject()
blocks = obj.blocks
output += f"Processing {obj.absolute_url()}\n"
for block in visit_blocks(obj, blocks):
if block.get("styles", False) and block["styles"].get(
"backgroundColor", False
):
new_block = block.copy()
color = block["styles"]["backgroundColor"]
new_block["styles"]["backgroundColor:noprefix"] = COLOR_MAP[color]
del new_block["styles"]["backgroundColor"]
block.clear()
block.update(new_block)
output += f'{obj.absolute_url()} - Updated "backgroundColor" to "backgroundColor:noprefix"\n'

i += 1
if not i % 100:
logger.info(i)
transaction.commit()
transaction.commit()
return output


class MigrateToV3(BrowserView):
def __call__(self):
alsoProvides(self.request, IDisableCSRFProtection)
return migrate_backgroundColor(self.context)
17 changes: 17 additions & 0 deletions src/kitconcept/voltolighttheme/browser/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:plone="http://namespaces.plone.org/plone"
i18n_domain="dlr.internet"
>

<!-- Return all news item not located in /de/aktuelles/nachrichten and /en/latest -->

<browser:page
name="migratev3"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
class=".MigrateToV3"
permission="cmf.ManagePortal"
/>

</configure>
1 change: 1 addition & 0 deletions src/kitconcept/voltolighttheme/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<include package=".serializers" />
<include package=".indexers" />
<include package=".vocabularies" />
<include package=".browser" />

<include package="plone.volto.cors" />

Expand Down

0 comments on commit 176e07f

Please sign in to comment.