import jingrow


def execute():
	jingrow.reload_pagetype("Event")
	# Rename "Cancel" to "Cancelled"
	jingrow.db.sql("""UPDATE tabEvent set event_type='Cancelled' where event_type='Cancel'""")
	# Move references to Participants table
	events = jingrow.db.sql(
		"""SELECT name, ref_type, ref_name FROM tabEvent WHERE ref_type!=''""", as_dict=True
	)
	for event in events:
		if event.ref_type and event.ref_name:
			try:
				e = jingrow.get_pg("Event", event.name)
				e.append(
					"event_participants",
					{"reference_pagetype": event.ref_type, "reference_pagename": event.ref_name},
				)
				e.flags.ignore_mandatory = True
				e.flags.ignore_permissions = True
				e.save()
			except Exception:
				jingrow.log_error(jingrow.get_traceback())
