Skip to content

Instantly share code, notes, and snippets.

@thet
Created March 15, 2018 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thet/716ec91b7a0e97e917466095a2ad0d9c to your computer and use it in GitHub Desktop.
Save thet/716ec91b7a0e97e917466095a2ad0d9c to your computer and use it in GitHub Desktop.
Remove a broken contentrule after deinstalling ``collective.contentrules.comingsoon``
"""Remove a broken contentrule after deinstalling ``collective.contentrules.comingsoon``
"""
# Create Fake Interface
from zope.component.interfaces import IObjectEvent
class IComingSoon(IObjectEvent): pass
# Create Fake Module
import sys
from types import ModuleType
sys.modules['collective.contentrules'] = ModuleType('collective.contentrules')
sys.modules['collective.contentrules.comingsoon'] = ModuleType('collective.contentrules.comingsoon')
sys.modules['collective.contentrules.comingsoon.interfaces'] = ModuleType('collective.contentrules.comingsoon.interfaces')
sys.modules['collective.contentrules.comingsoon.interfaces'].IComingSoon = IComingSoon
# Delete from persistent utility
from plone.contentrules.engine.interfaces import IRuleStorage
from zope.component import getUtility
storage = getUtility(IRuleStorage, context=app.Plone)
# Find out, which contentrule was broken. In my case it was ``rule-8``
del storage['rule-8']
# finally commit.
import transaction; transaction.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment