# Copyright (c) 2024, JINGROW
# For license information, please see license.txt

import jingrow


def sync_setup_wizard_status():
	sites = jingrow.get_all(
		"Site",
		{
			"status": "Active",
			"setup_wizard_complete": False,
			"is_standby": False,
			"domain": ("in", ("jingrow.com", "jingrow.cloud", "jingrowhr.com", "jingrowdesk.com")),
		},
		pluck="name",
		order_by="RAND()",
		limit=20,
	)

	for site_name in sites:
		site = jingrow.get_pg("Site", site_name)
		try:
			site.is_setup_wizard_complete()
			jingrow.db.commit()
		except Exception:
			jingrow.db.rollback()
