Fix variable references in calendar sync after refactoring
This commit is contained in:
@@ -658,8 +658,8 @@ async def handler(event, context):
|
||||
|
||||
# Phase 1: New from Advoware => Google
|
||||
logger.info("Phase 1: Processing new appointments from Advoware")
|
||||
for frnr, app in adv_map.items():
|
||||
if frnr not in db_adv_index:
|
||||
for frnr, app in state['adv_map'].items():
|
||||
if frnr not in state['db_adv_index']:
|
||||
try:
|
||||
event_id = await create_google_event(service, calendar_id, standardize_appointment_data(app, 'advoware'))
|
||||
async with conn.transaction():
|
||||
@@ -682,11 +682,11 @@ async def handler(event, context):
|
||||
|
||||
# Phase 2: New from Google => Advoware
|
||||
logger.info("Phase 2: Processing new events from Google")
|
||||
for event_id, evt in google_map.items():
|
||||
for event_id, evt in state['google_map'].items():
|
||||
# For recurring events, check if the master event (recurringEventId) is already synced
|
||||
# For regular events, check the event_id directly
|
||||
recurring_master_id = evt.get('recurringEventId')
|
||||
is_already_synced = event_id in db_google_index or (recurring_master_id and recurring_master_id in db_google_index)
|
||||
is_already_synced = event_id in state['db_google_index'] or (recurring_master_id and recurring_master_id in state['db_google_index'])
|
||||
|
||||
if not is_already_synced:
|
||||
try:
|
||||
@@ -713,20 +713,20 @@ async def handler(event, context):
|
||||
|
||||
# Phase 3: Identify deleted entries
|
||||
logger.info("Phase 3: Processing deleted entries")
|
||||
for row in rows:
|
||||
for row in state['rows']:
|
||||
frnr = row['advoware_frnr']
|
||||
event_id = row['google_event_id']
|
||||
adv_exists = str(frnr) in adv_map if frnr else False
|
||||
adv_exists = str(frnr) in state['adv_map'] if frnr else False
|
||||
|
||||
# For Google events, check if the master event or any instance exists
|
||||
google_exists = False
|
||||
if event_id:
|
||||
# Check if the stored event_id exists
|
||||
if event_id in google_map:
|
||||
if event_id in state['google_map']:
|
||||
google_exists = True
|
||||
else:
|
||||
# Check if any event has this as recurringEventId (master event still exists)
|
||||
for evt in google_map.values():
|
||||
for evt in state['google_map'].values():
|
||||
if evt.get('recurringEventId') == event_id:
|
||||
google_exists = True
|
||||
break
|
||||
@@ -755,7 +755,7 @@ async def handler(event, context):
|
||||
elif row['source_system'] == 'google' and row['advoware_write_allowed']:
|
||||
# Recreate in Advoware
|
||||
try:
|
||||
new_frnr = await safe_create_advoware_appointment(advoware, standardize_appointment_data(google_map[event_id], 'google'), kuerzel, row['advoware_write_allowed'])
|
||||
new_frnr = await safe_create_advoware_appointment(advoware, standardize_appointment_data(state['google_map'][event_id], 'google'), kuerzel, row['advoware_write_allowed'])
|
||||
if new_frnr and str(new_frnr) != 'None':
|
||||
async with conn.transaction():
|
||||
await conn.execute("UPDATE calendar_sync SET advoware_frnr = $1, sync_status = 'synced', last_sync = $3 WHERE sync_id = $2;", int(new_frnr), row['sync_id'], datetime.datetime.now(BERLIN_TZ))
|
||||
@@ -815,7 +815,7 @@ async def handler(event, context):
|
||||
elif row['source_system'] == 'advoware':
|
||||
# Recreate in Google
|
||||
try:
|
||||
new_event_id = await create_google_event(service, calendar_id, standardize_appointment_data(adv_map[str(frnr)], 'advoware'))
|
||||
new_event_id = await create_google_event(service, calendar_id, standardize_appointment_data(state['adv_map'][str(frnr)], 'advoware'))
|
||||
async with conn.transaction():
|
||||
await conn.execute("UPDATE calendar_sync SET google_event_id = $1, sync_status = 'synced', last_sync = $3 WHERE sync_id = $2;", new_event_id, row['sync_id'], datetime.datetime.now(BERLIN_TZ))
|
||||
logger.info(f"Phase 3: Recreated Google event {new_event_id} for sync_id {row['sync_id']}")
|
||||
@@ -846,20 +846,20 @@ async def handler(event, context):
|
||||
# Track which master events we've already processed to avoid duplicate updates
|
||||
processed_master_events = set()
|
||||
|
||||
for row in rows:
|
||||
for row in state['rows']:
|
||||
frnr = row['advoware_frnr']
|
||||
event_id = row['google_event_id']
|
||||
adv_data = adv_map.get(str(frnr)) if frnr else None
|
||||
adv_data = state['adv_map'].get(str(frnr)) if frnr else None
|
||||
|
||||
# For Google events, find the corresponding event (could be master or instance)
|
||||
google_data = None
|
||||
if event_id:
|
||||
# First try to find the exact event_id
|
||||
if event_id in google_map:
|
||||
google_data = google_map[event_id]
|
||||
if event_id in state['google_map']:
|
||||
google_data = state['google_map'][event_id]
|
||||
else:
|
||||
# Look for any event that has this as recurringEventId
|
||||
for evt in google_map.values():
|
||||
for evt in state['google_map'].values():
|
||||
if evt.get('recurringEventId') == event_id:
|
||||
google_data = evt
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user