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:
try:
control_panel = root.Control_Panel
timer_service = getattr(control_panel, cp_id)
except AttributeError:
timer_service = TimerService(cp_id) timer_service = TimerService(cp_id)
cp._setObject(cp_id, timer_service)
return getattr(cp, cp_id)
def initialize(context):
# hook into the Control Panel
cp = context._ProductContext__app.Control_Panel
if cp_id in cp.objectIds():
#cp._delObject(cp_id)
timer = getattr(cp, cp_id)
timer_service = timer
if not isinstance(timer_service, TimerService):
timer = make_timer_service(cp)
else: else:
timer = make_timer_service(cp) control_panel._delObject(cp_id)
root._setObject(cp_id, timer_service)
if timer._version < current_version: return timer_service
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