import jingrow


def execute():
	jingrow.reload_pagetype("Comment")

	if jingrow.db.count("Feedback") > 20000:
		jingrow.db.auto_commit_on_many_writes = True

	for feedback in jingrow.get_all("Feedback", fields=["*"]):
		if feedback.like:
			new_comment = jingrow.new_pg("Comment")
			new_comment.comment_type = "Like"
			new_comment.comment_email = feedback.owner
			new_comment.content = "Liked by: " + feedback.owner
			new_comment.reference_pagetype = feedback.reference_pagetype
			new_comment.reference_name = feedback.reference_name
			new_comment.creation = feedback.creation
			new_comment.modified = feedback.modified
			new_comment.owner = feedback.owner
			new_comment.modified_by = feedback.modified_by
			new_comment.ip_address = feedback.ip_address
			new_comment.db_insert()

	if jingrow.db.auto_commit_on_many_writes:
		jingrow.db.auto_commit_on_many_writes = False

	# clean up
	jingrow.db.delete("Feedback")
	jingrow.db.commit()

	jingrow.delete_pg("PageType", "Feedback")
