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

SUP-40522: Migrate rgbsr field to multiple lines #298

Open
wants to merge 1 commit into
base: urban2.7.x
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions news/SUP-40522.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Migrate `rgbsr` field to multiple lines
[daggelpop]
4 changes: 2 additions & 2 deletions src/Products/urban/content/licence/GenericLicence.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,9 +1067,9 @@
schemata="urban_location",
default_output_type="text/x-html-safe",
),
StringField(
LinesField(
name="rgbsr",
widget=SelectionWidget(
widget=MultiSelect2Widget(
label=_("urban_label_rgbsr", default="Rgbsr"),
),
schemata="urban_location",
Expand Down
25 changes: 25 additions & 0 deletions src/Products/urban/migration/update_270.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from Acquisition import aq_parent
from OFS.interfaces import IOrderedContainer
from Products.urban.interfaces import IGenericLicence
from Products.urban.migration.utils import refresh_workflow_permissions
from imio.schedule.content.object_factories import MacroCreationConditionObject
from imio.schedule.content.object_factories import MacroEndConditionObject
Expand All @@ -28,6 +29,7 @@
from zope.component import getMultiAdapter

import logging
import six


def rename_patrimony_certificate(context):
Expand Down Expand Up @@ -213,3 +215,26 @@ def fix_config_wrong_class(context):
schedule_cfg.REQUEST.form = data

logger.info("Upgrade step done!")


def migrate_rgbsr_multiple_lines(context):
"""
Migrate rgbsr field from StringField to LinesField
"""
logger = logging.getLogger("Migrate rgbsr field to multiple lines")
logger.info("starting upgrade steps")

catalog = api.portal.get_tool("portal_catalog")
licence_brains = catalog(object_provides=IGenericLicence.__identifier__)

for brain in licence_brains:
licence = brain.getObject()

if not hasattr(licence, "rgbsr") or licence.rgbsr is None or type(licence.rgbsr) is tuple:
continue

if isinstance(licence.rgbsr, six.string_types):
new_value = () if not licence.rgbsr else (licence.rgbsr,)
licence.setRgbsr(new_value)

logger.info("Upgrade step done!")
9 changes: 9 additions & 0 deletions src/Products/urban/migration/upgrades.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -693,4 +693,13 @@
profile="Products.urban:default"
/>

<gs:upgradeStep
title="Migrate rgbsr field to multiple lines"
description="Migrate rgbsr field to multiple lines"
source="1155"
destination="1156"
handler=".update_270.migrate_rgbsr_multiple_lines"
profile="Products.urban:default"
/>

</configure>
2 changes: 1 addition & 1 deletion src/Products/urban/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<metadata>
<version>1155</version>
<version>1156</version>
<dependencies>
<dependency>profile-Products.urban:preinstall</dependency>
</dependencies>
Expand Down