Skip to content

Commit

Permalink
Fixed title and description of plone.resource.maxage.
Browse files Browse the repository at this point in the history
This had the title and description from shared maxage, due to a wrong reference.
See plone/Products.CMFPlone#1989

Backported from master.
  • Loading branch information
mauritsvanrees committed Apr 6, 2017
1 parent c779589 commit b2c015f
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ New features:

Bug fixes:

- *add item here*
- Fixed title and description of plone.resource.maxage.
This had the title and description from shared maxage,
due to a wrong reference.
See https://github.com/plone/Products.CMFPlone/issues/1989
[maurits]


1.4.1 (2017-03-16)
Expand Down
9 changes: 4 additions & 5 deletions plone/app/upgrade/v43/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,10 @@
destination="4317"
profile="Products.CMFPlone:plone">

<genericsetup:upgradeStep
title="Miscellaneous"
description=""
handler="..utils.null_upgrade_step"
/>
<genericsetup:upgradeStep
title="Fix double shared maxage"
handler=".final.fix_double_smaxage"
/>

</genericsetup:upgradeSteps>

Expand Down
28 changes: 28 additions & 0 deletions plone/app/upgrade/v43/final.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,31 @@ def addSortOnProperty(context):
site_properties.manage_addProperty('sort_on', 'relevance', 'string')
logger.log(logging.INFO,
"Added 'sort_on' property to site_properties.")


def fix_double_smaxage(context):
"""Fix caching definition.
plone.resource.maxage has title and description from shared maxage.
See https://github.com/plone/Products.CMFPlone/issues/1989
"""
from plone.registry.record import Record
from plone.registry import FieldRef
from plone.registry.interfaces import IRegistry
from zope.component import getUtility
registry = getUtility(IRegistry)
# If these three registry records are not defined,
# we do no fix.
maxage = 'plone.app.caching.strongCaching.plone.resource.maxage'
def_maxage = 'plone.app.caching.strongCaching.maxage'
def_smaxage = 'plone.app.caching.strongCaching.smaxage'
for name in (maxage, def_maxage, def_smaxage):
if name not in registry:
return
if registry.records[maxage].field.recordName != def_smaxage:
# no fix needed
return
field_ref = FieldRef(def_maxage, registry.records[def_maxage].field)
old_value = registry[maxage]
registry.records[maxage] = Record(field_ref, old_value)
logger.info('Fixed {0} to refer to {1}.'.format(maxage, def_maxage))
84 changes: 83 additions & 1 deletion plone/app/upgrade/v43/tests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from zope.component import getAdapters, queryMultiAdapter
from zope.component import getAdapters
from zope.component import getUtility
from zope.component import getSiteManager
from zope.component import queryMultiAdapter
from zope.configuration import xmlconfig
from zope.contentprovider.interfaces import IContentProvider
from zope.interface import implementer
from zope.viewlet.interfaces import IViewlet

from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import PloneSandboxLayer
from plone.app.testing import IntegrationTesting
from plone.app.upgrade.tests.base import MigrationTest
from plone.app.upgrade.utils import loadMigrationProfile
from Products.CMFCore.utils import getToolByName
Expand All @@ -13,6 +19,7 @@
from Products.GenericSetup.interfaces import EXTENSION

import alphas
import unittest

PLONE5 = getFSVersionTuple()[0] >= 5

Expand Down Expand Up @@ -380,3 +387,78 @@ def testCleanupUninstalledProducts(self):
profile_registry.unregisterProfile('default', 'newproduct')
profile_registry.unregisterProfile('default', 'installed')
profile_registry.unregisterProfile('default', 'uninstalled')


class PloneAppCachingUpgrade(PloneSandboxLayer):

defaultBases = (PLONE_FIXTURE,)

def setUpZope(self, app, configurationContext):

# Load ZCML
import plone.app.caching
xmlconfig.file(
'configure.zcml', plone.app.caching, context=configurationContext)


PLONE_APP_CACHING_UPGRADE_FIXTURE = PloneAppCachingUpgrade()
PLONE_APP_CACHING_UPGRADE_INTEGRATION_TESTING = IntegrationTesting(
bases=(PLONE_APP_CACHING_UPGRADE_FIXTURE,),
name="PloneAppCachingUpgrade:Integration")


class TestCaching(unittest.TestCase):

layer = PLONE_APP_CACHING_UPGRADE_INTEGRATION_TESTING

def test_fix_double_smaxage(self):
from plone.registry.interfaces import IRegistry
from plone.registry.record import Record
from plone.registry import FieldRef
from plone.app.upgrade.v43.final import fix_double_smaxage
maxage = 'plone.app.caching.strongCaching.plone.resource.maxage'
def_maxage = 'plone.app.caching.strongCaching.maxage'
def_smaxage = 'plone.app.caching.strongCaching.smaxage'
# Run the upgrade before plone.app.caching is installed,
# to check that it does not harm.
portal_setup = self.layer['portal'].portal_setup
fix_double_smaxage(portal_setup)
registry = getUtility(IRegistry)
self.assertFalse(def_maxage in registry)
self.assertFalse(def_smaxage in registry)
# Install default caching profile.
portal_setup.runAllImportStepsFromProfile(
'plone.app.caching:default'
)
self.assertTrue(def_maxage in registry)
self.assertTrue(def_smaxage in registry)
# Run upgrade.
fix_double_smaxage(portal_setup)
# Install the with-caching-proxy settings.
portal_setup.runAllImportStepsFromProfile(
'plone.app.caching:with-caching-proxy'
)
# Run upgrade.
fix_double_smaxage(portal_setup)

# Old situation had maxage referencing the s-maxage definition:
field_ref = FieldRef(def_smaxage, registry.records[def_smaxage].field)
registry.records[maxage] = Record(field_ref, 999)
self.assertEqual(
registry.records[maxage].field.recordName, def_smaxage)
self.assertEqual(registry[maxage], 999)
self.assertTrue(
'shared' in registry.records[maxage].field.title.lower())
# Run upgrade.
fix_double_smaxage(portal_setup)
# Test that this fixes the reference and keeps the value.
self.assertEqual(
registry.records[maxage].field.recordName, def_maxage)
self.assertEqual(registry[maxage], 999)
self.assertFalse(
'shared' in registry.records[maxage].field.title.lower())
# Run upgrade.
fix_double_smaxage(portal_setup)
self.assertEqual(
registry.records[maxage].field.recordName, def_maxage)
self.assertEqual(registry[maxage], 999)

0 comments on commit b2c015f

Please sign in to comment.