import xhiveframework


def execute():
	xhiveframework.reload_doc("core", "doctype", "domain")
	xhiveframework.reload_doc("core", "doctype", "has_domain")
	active_domains = xhiveframework.get_active_domains()
	all_domains = xhiveframework.get_all("Domain")

	for d in all_domains:
		if d.name not in active_domains:
			inactive_domain = xhiveframework.get_doc("Domain", d.name)
			inactive_domain.setup_data()
			inactive_domain.remove_custom_field()
