Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a migrate browserview to migrate content to V3 #31

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading