Skip to content

Commit

Permalink
Merge pull request #183 from plone/remove-legacy-resource-registries-2
Browse files Browse the repository at this point in the history
Products.ResourceRegistries made conditional
  • Loading branch information
jensens authored Feb 10, 2019
2 parents 1863db3 + 8dd4e29 commit 95b9e3f
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 53 deletions.
2 changes: 2 additions & 0 deletions news/183.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Tolerate lack of legacy resource registry
[ksuess]
7 changes: 7 additions & 0 deletions plone/app/upgrade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
import sys


try:
pkg_resources.get_distribution('Products.ResourceRegistries')
except pkg_resources.DistributionNotFound:
IS_PRODUCT_RESOURCE_REGISTRIES_INSTALLED = False
else:
IS_PRODUCT_RESOURCE_REGISTRIES_INSTALLED = True

try:
from zope.app.cache.interfaces.ram import IRAMCache # noqa F401
except ImportError:
Expand Down
19 changes: 11 additions & 8 deletions plone/app/upgrade/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import transaction
import warnings

from plone.app.upgrade import IS_PRODUCT_RESOURCE_REGISTRIES_INSTALLED

#
# Base TestCase for upgrades
Expand Down Expand Up @@ -67,16 +68,18 @@ def removeActionFromTool(
tool._delOb(action_id)

def addResourceToJSTool(self, resource_name):
# Registers a resource with the javascripts tool
tool = getToolByName(self.portal, 'portal_javascripts')
if resource_name not in tool.getResourceIds():
tool.registerScript(resource_name)
if IS_PRODUCT_RESOURCE_REGISTRIES_INSTALLED:
# Registers a resource with the javascripts tool
tool = getToolByName(self.portal, 'portal_javascripts')
if resource_name not in tool.getResourceIds():
tool.registerScript(resource_name)

def addResourceToCSSTool(self, resource_name):
# Registers a resource with the css tool
tool = getToolByName(self.portal, 'portal_css')
if resource_name not in tool.getResourceIds():
tool.registerStylesheet(resource_name)
if IS_PRODUCT_RESOURCE_REGISTRIES_INSTALLED:
# Registers a resource with the css tool
tool = getToolByName(self.portal, 'portal_css')
if resource_name not in tool.getResourceIds():
tool.registerStylesheet(resource_name)

def removeSiteProperty(self, property_id):
# Removes a site property from portal_properties
Expand Down
11 changes: 8 additions & 3 deletions plone/app/upgrade/v40/alphas.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from Products.CMFCore.Expression import Expression
from Products.CMFCore.interfaces import ICachingPolicyManager
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.setuphandlers import addCacheForResourceRegistry
from Products.CMFPlone.setuphandlers import addCacheHandlers
from Products.MailHost.interfaces import IMailHost
from Products.MailHost.MailHost import MailHost
Expand Down Expand Up @@ -352,7 +351,12 @@ def removeBrokenCacheFu(context):
transaction.savepoint(optimistic=True)
manage_addCachingPolicyManager(portal)
addCacheHandlers(portal)
addCacheForResourceRegistry(portal)
try:
from Products.CMFPlone.setuphandlers import addCacheForResourceRegistry
addCacheForResourceRegistry(portal)
except:
# legacy resource registries replaced by new type
pass
logger.info('Removed CacheSetup tools.')


Expand Down Expand Up @@ -381,7 +385,8 @@ def cleanUpToolRegistry(context):
required = toolset._required.copy()
existing = portal.keys()
changed = False
for name, info in required.items():
items = list(required.items())
for name, info in items:
if name not in existing:
del required[name]
changed = True
Expand Down
4 changes: 3 additions & 1 deletion plone/app/upgrade/v42/final.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from plone.app.upgrade import IS_PRODUCT_RESOURCE_REGISTRIES_INSTALLED
from plone.app.upgrade.utils import loadMigrationProfile
from Products.CMFCore.utils import getToolByName

Expand Down Expand Up @@ -34,7 +35,8 @@ def to421(context):
def to422(context):
"""4.2.1 -> 4.2.2
"""
loadMigrationProfile(context, 'profile-plone.app.upgrade.v42:to422')
if IS_PRODUCT_RESOURCE_REGISTRIES_INSTALLED:
loadMigrationProfile(context, 'profile-plone.app.upgrade.v42:to422')


def to423(context):
Expand Down
4 changes: 3 additions & 1 deletion plone/app/upgrade/v42/profiles/to_422/registry.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<registry>
<record interface="Products.ResourceRegistries.interfaces.settings.IResourceRegistriesSettings" field="resourceBundlesForThemes">
<record
interface="Products.ResourceRegistries.interfaces.settings.IResourceRegistriesSettings"
field="resourceBundlesForThemes">
<value purge="false">
<element key="(default)">
<element>jquery</element>
Expand Down
8 changes: 0 additions & 8 deletions plone/app/upgrade/v43/profiles/to_alpha2/registry.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
<registry>
<record interface="Products.ResourceRegistries.interfaces.settings.IResourceRegistriesSettings" field="resourceBundlesForThemes">
<value purge="false">
<element key="(default)">
<element>jquery</element>
<element>default</element>
</element>
</value>
</record>
<record name="plone.app.layout.globals.bodyClass.depth">
<field type="plone.registry.field.Int">
<title>Body class path depth</title>
Expand Down
3 changes: 2 additions & 1 deletion plone/app/upgrade/v43/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from plone.app.upgrade.tests.base import MigrationTest
from plone.app.upgrade.utils import loadMigrationProfile
from plone.app.upgrade.utils import plone_version
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.interfaces import INonInstallable
from Products.CMFPlone.utils import getFSVersionTuple
Expand Down Expand Up @@ -174,7 +175,7 @@ def testAddDefaultPlonePasswordPolicy(self):
# now it has been added...
self.assertTrue('password_policy' in portal.acl_users.objectIds())


@unittest.skipIf(plone_version >= '5.2', 'Plone >=5.2')
class TestFakeKupuMigration(MigrationTest):

def afterSetUp(self):
Expand Down
8 changes: 0 additions & 8 deletions plone/app/upgrade/v50/profiles/to_alpha3/registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
prefix="plone" />
<records interface="Products.CMFPlone.interfaces.IDateAndTimeSchema"
prefix="plone" />
<record interface="Products.ResourceRegistries.interfaces.settings.IResourceRegistriesSettings" field="resourceBundlesForThemes">
<value purge="false">
<element key="(default)">
<element>jquery</element>
<element>default</element>
</element>
</value>
</record>
<record name="Products.CMFPlone.i18nl10n.override_dateformat.Enabled">
<field type="plone.registry.field.Bool">
<title>Enabled</title>
Expand Down
8 changes: 3 additions & 5 deletions plone/app/upgrade/v50/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import PloneSandboxLayer
from plone.app.upgrade.utils import loadMigrationProfile
from plone.app.upgrade.utils import plone_version
from plone.testing.z2 import FunctionalTesting
from plone.testing.z2 import login
from zope.component.hooks import setSite
Expand Down Expand Up @@ -29,26 +30,23 @@ def setUpZope(self, app, configurationContext):
def setUpPloneSite(self, portal):
app = portal.aq_parent
login(app['acl_users'], 'admin')

# import old ZEXP
try:
path = os.path.join(os.path.abspath(
os.path.dirname(__file__)), 'data', 'test-full.zexp')
app._importObjectFromFile(path, verify=0)
except BaseException:
except Exception:
logger.exception('Failed to import ZEXP from old site.')
else:
# run upgrades
self['portal'] = portal = app.test
setSite(portal)
try:
if plone_version >= '5.2':
# for 5.2 we need tools as utilities
loadMigrationProfile(
portal.portal_setup,
'profile-plone.app.upgrade.v52:to52alpha1',
steps=['componentregistry'])
except KeyError:
pass
portal.portal_migration.upgrade(swallow_errors=False)
setSite(None)

Expand Down
13 changes: 7 additions & 6 deletions plone/app/upgrade/v50/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import six
import unittest


try:
from Products.CMFPlone.factory import _IMREALLYPLONE5
_IMREALLYPLONE5 # pyflakes
Expand Down Expand Up @@ -92,6 +91,9 @@ def test_migrate_members_default_layout(self):
self.assertEqual(members.getLayout(), '@@member-search')


@unittest.skipIf(
not six.PY2 or not PLONE_5,
"not Plone 5.0, 5.1 or 5.2 / Python 2")
class TestFunctionalMigrations(unittest.TestCase):
"""Run an upgrade from a real Plone 4.0 ZEXP dump.
Expand Down Expand Up @@ -179,13 +181,12 @@ def test_fix_double_smaxage(self):


def test_suite():
# Skip these tests on Plone 4
from unittest import TestSuite, makeSuite
suite = TestSuite()
suite.addTest(makeSuite(PASUpgradeTest))
suite.addTest(makeSuite(VariousTest))
if not six.PY2 or not PLONE_5:
return TestSuite()
else:
suite = TestSuite()
suite.addTest(makeSuite(PASUpgradeTest))
suite.addTest(makeSuite(TestFunctionalMigrations))
suite.addTest(makeSuite(VariousTest))
return suite
return suite
3 changes: 2 additions & 1 deletion plone/app/upgrade/v51/profiles/to_alpha1/registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<registry>
<records
interface="Products.ResourceRegistries.interfaces.settings.IResourceRegistriesSettings"
prefix="plone">
prefix="plone"
condition="installed Products.ResourceRegistries">
<value
key="lessvariables"
purge="False">
Expand Down
1 change: 1 addition & 0 deletions plone/app/upgrade/v52/alphas.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def fix_core_behaviors_in_ftis(context):
def to52alpha1(context):
loadMigrationProfile(context, 'profile-plone.app.upgrade.v52:to52alpha1')
portal = getToolByName(context, 'portal_url').getPortalObject()

cleanUpSkinsTool(portal)

cleanup_resources()
Expand Down
21 changes: 20 additions & 1 deletion plone/app/upgrade/v52/betas.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
from Products.CMFCore.utils import getToolByName
from plone.app.upgrade.utils import loadMigrationProfile
from plone.app.upgrade.v40.alphas import cleanUpToolRegistry
from zc.relation.interfaces import ICatalog
from zope import component
from zope.intid.interfaces import IntIdMissingError


import logging


Expand All @@ -29,6 +29,24 @@ def add_exclude_from_nav_index(context):
catalog.manage_reindexIndex(ids=indexables)


def remove_legacy_resource_registries(context):
"""Remove portal_css and portal_javascripts."""
portal_url = getToolByName(context, 'portal_url')
portal = portal_url.getPortalObject()

tools_to_remove = [
'portal_css',
'portal_javascripts',
]

# remove obsolete tools
tools = [t for t in tools_to_remove if t in portal]
if tools:
portal.manage_delObjects(tools)

cleanUpToolRegistry(context)


def remove_interface_indexes_from_relations_catalog():
""" remove unused interface indexes from relations catalog """
catalog = component.queryUtility(ICatalog)
Expand All @@ -51,4 +69,5 @@ def remove_interface_indexes_from_relations_catalog():
def to52beta1(context):
loadMigrationProfile(context, 'profile-plone.app.upgrade.v52:to52beta1')
add_exclude_from_nav_index(context)
remove_legacy_resource_registries(context)
remove_interface_indexes_from_relations_catalog()
4 changes: 4 additions & 0 deletions plone/app/upgrade/v52/profiles/to_beta1/registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@
<value key="last_compilation">2018-10-01 23:00:00</value>
</records>

<records
interface="Products.ResourceRegistries.interfaces.settings.IResourceRegistriesSettings"
prefix="plone"
remove="True"/>
</registry>
14 changes: 4 additions & 10 deletions plone/app/upgrade/v52/tests.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
# -*- coding: utf-8 -*-
import unittest

from plone.app.upgrade.utils import plone_version
from plone.testing.z2 import Browser

try:
from Products.CMFPlone.factory import _IMREALLYPLONE5
_IMREALLYPLONE5 # pyflakes
except ImportError:
PLONE_5 = False
else:
PLONE_5 = True
import unittest


def test_suite():
# Skip these tests on Plone 4
if not PLONE_5:
if plone_version <= '5.0':
return unittest.TestSuite()

suite = unittest.TestSuite()
return suite

0 comments on commit 95b9e3f

Please sign in to comment.