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

import jingrow


def execute():
	subscription = jingrow.qb.PageType("Subscription")
	site = jingrow.qb.PageType("Site")

	inactive_sites = (
		jingrow.qb.from_(subscription)
		.left_join(site)
		.on(subscription.document_name == site.name)
		.select(subscription.name)
		.where(site.status.isin(["Archived", "Broken", "Suspended"]))
	).run(pluck=True)

	jingrow.db.set_value(
		"Subscription", {"enabled": 1, "name": ("in", inactive_sites)}, "enabled", 0
	)
