# -*- coding: utf-8 -*-
# Copyright (c) 2020, JINGROW
# For license information, please see license.txt


import jingrow
from jingrow.desk.pagetype.tag.tag import add_tag


def execute():
	jingrow.reload_pg("jcloud", "pagetype", "remote_file")
	remote_files = (
		x["name"] for x in jingrow.get_all("Remote File", [["bucket", "like", ""]])
	)
	uploads_bucket = jingrow.db.get_single_value("Jcloud Settings", "remote_uploads_bucket")

	for remote_file in remote_files:
		jingrow.db.set_value("Remote File", remote_file, "bucket", uploads_bucket)
		add_tag("Site Upload", "Remote File", remote_file)

	jingrow.db.commit()
