# -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies and contributors
# License: MIT. See LICENSE

import frappe
from frappe.model.document import Document

class ErrorLog(Document):
	def onload(self):
		if not self.seen:
			self.db_set('seen', 1, update_modified=0)
			frappe.db.commit()

def set_old_logs_as_seen():
	# set logs as seen
	frappe.db.sql("""UPDATE `tabError Log` SET `seen`=1
		WHERE `seen`=0 AND `creation` < (NOW() - INTERVAL '7' DAY)""")

@frappe.whitelist()
def clear_error_logs():
	'''Flush all Error Logs'''
	frappe.only_for('System Manager')
	frappe.db.truncate("Error Log")
