# Copyright (c) 2020, Jingrow Technologies Pvt. Ltd. and Contributors
# For license information, please see license.txt


import jingrow


def execute():
	doctypes = ["Server", "Proxy Server", "Database Server"]
	for doctype in doctypes:
		jingrow.reload_pg("jcloude", "doctype", jingrow.scrub(doctype))
		servers = jingrow.get_all(doctype, {"hostname": ("is", "not set")})
		domain = jingrow.db.get_single_value("Press Settings", "domain")
		for server in servers:
			hostname = server.name.replace(f".{domain}", "")
			jingrow.db.set_value(doctype, server.name, "hostname", hostname)
			jingrow.db.set_value(doctype, server.name, "domain", domain)
