Skip to content

Commit

Permalink
Upgrade: set compilation date of easyform bundle, and combine bundles.
Browse files Browse the repository at this point in the history
This is a follow-up on #247
and replaces #248
  • Loading branch information
mauritsvanrees committed Sep 9, 2020
1 parent e15cd7d commit 0a3c44a
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions src/collective/easyform/upgrades/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
from plone import api

import logging


logger = logging.getLogger(__name__)


def update_last_compilation(context):
# Let's do the imports inline, so they are not needlessly done at startup.
# Should not really matter, but oh well.
Expand All @@ -11,19 +19,24 @@ def update_last_compilation(context):
# Technically we only need year, month and day.
# But keep this in sync with registry.xml.
records.last_compilation = datetime(2020, 9, 8, 17, 52, 0)
# TODO: run the combine-bundles import step or its handler
# Products.CMFPlone.resources.exportimport.bundles.combine.
# But that only does something when there is a registry.xml,
# so I don't think it works for an upgrade step.
#
# But this is a wrapper around
# Products.CMFPlone.resources.browser.combine.combine_bundles
# which we could call directly, but then we need to do the same
# extra handling of the response contenttype.
#
# We could also re-apply our whole registry.xml,
# by doing an upgradeDepends with plone.app.registry and combine-bundles,
# but that restores our factory defaults, which we should not do.
#
# Easiest is to add an upgrade profile.
# I always consider that overkill, but so be it.
logger.info("Updated the last_compilation date of the easyform bundle.")

# Run the combine-bundles import step or its handler.
# Can be done with an upgrade step:
# <gs:upgradeDepends
# title="combine bundles"
# import_steps="combine-bundles"
# run_deps="false"
# />
# But directly calling the basic function works fine.
# See also comment here:
# https://github.com/collective/collective.easyform/pull/248#issuecomment-689365240
# Also, here we can do a try/except so it does not fail on Plone 5.0,
# which I think does not have the import step, not the function.
try:
from Products.CMFPlone.resources.browser.combine import combine_bundles
except ImportError:
logger.warning("Could not call combine_bundles. You should do that yourself.")
return
portal = api.portal.get()
combine_bundles(portal)

0 comments on commit 0a3c44a

Please sign in to comment.