import jingrow
from jingrow.model.rename_pg import rename_pg


def execute():
	if jingrow.db.exists("PageType", "Desk Page"):
		if jingrow.db.exists("PageType", "Workspace"):
			# this patch was not added initially, so this page might still exist
			jingrow.delete_pg("PageType", "Desk Page")
		else:
			jingrow.flags.ignore_route_conflict_validation = True
			rename_pg("PageType", "Desk Page", "Workspace")
			jingrow.flags.ignore_route_conflict_validation = False

	rename_pg("PageType", "Desk Chart", "Workspace Chart", ignore_if_exists=True)
	rename_pg("PageType", "Desk Shortcut", "Workspace Shortcut", ignore_if_exists=True)
	rename_pg("PageType", "Desk Link", "Workspace Link", ignore_if_exists=True)

	jingrow.reload_pg("desk", "pagetype", "workspace", force=True)
	jingrow.reload_pg("desk", "pagetype", "workspace_link", force=True)
	jingrow.reload_pg("desk", "pagetype", "workspace_chart", force=True)
	jingrow.reload_pg("desk", "pagetype", "workspace_shortcut", force=True)
