Commit dd1d49cf authored by Vincent Pelletier's avatar Vincent Pelletier Committed by Tatuya Kamada

Do not rely on module "initialize" being called.

Provide migration ability from persistent Control Panel if present.
Drop destructive "backward-compatibility" code (delete object if old
version).
Fixes Zope 2.13 .
parent 2b53e495
...@@ -15,26 +15,16 @@ cp_id = 'timer_service' ...@@ -15,26 +15,16 @@ cp_id = 'timer_service'
def getTimerService(context): def getTimerService(context):
""" returns the SMTP srevice instance """ """ returns the SMTP srevice instance """
return context.Control_Panel.timer_service root = context.getPhysicalRoot()
try:
def make_timer_service(cp): timer_service = getattr(root, cp_id)
"""Control_Panel smtp service""" except AttributeError:
timer_service = TimerService(cp_id) try:
cp._setObject(cp_id, timer_service) control_panel = root.Control_Panel
return getattr(cp, cp_id) timer_service = getattr(control_panel, cp_id)
except AttributeError:
def initialize(context): timer_service = TimerService(cp_id)
# hook into the Control Panel else:
cp = context._ProductContext__app.Control_Panel control_panel._delObject(cp_id)
if cp_id in cp.objectIds(): root._setObject(cp_id, timer_service)
#cp._delObject(cp_id) return timer_service
timer = getattr(cp, cp_id)
timer_service = timer
if not isinstance(timer_service, TimerService):
timer = make_timer_service(cp)
else:
timer = make_timer_service(cp)
if timer._version < current_version:
cp._delObject(cp_id)
timer = make_timer_service(cp)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment