feat: flag to delete attached files permanently
This commit is contained in:
parent
f97cc370cf
commit
e40892fdb6
2 changed files with 7 additions and 6 deletions
|
|
@ -718,7 +718,7 @@ def delete_file(path):
|
|||
os.remove(path)
|
||||
|
||||
|
||||
def remove_file(fid=None, attached_to_doctype=None, attached_to_name=None, from_delete=False):
|
||||
def remove_file(fid=None, attached_to_doctype=None, attached_to_name=None, from_delete=False, delete_permanently=False):
|
||||
"""Remove file and File entry"""
|
||||
file_name = None
|
||||
if not (attached_to_doctype and attached_to_name):
|
||||
|
|
@ -736,7 +736,7 @@ def remove_file(fid=None, attached_to_doctype=None, attached_to_name=None, from_
|
|||
if not file_name:
|
||||
file_name = frappe.db.get_value("File", fid, "file_name")
|
||||
comment = doc.add_comment("Attachment Removed", _("Removed {0}").format(file_name))
|
||||
frappe.delete_doc("File", fid, ignore_permissions=ignore_permissions)
|
||||
frappe.delete_doc("File", fid, ignore_permissions=ignore_permissions, delete_permanently=delete_permanently)
|
||||
|
||||
return comment
|
||||
|
||||
|
|
@ -745,17 +745,18 @@ def get_max_file_size():
|
|||
return cint(conf.get('max_file_size')) or 10485760
|
||||
|
||||
|
||||
def remove_all(dt, dn, from_delete=False):
|
||||
def remove_all(dt, dn, from_delete=False, delete_permanently=False):
|
||||
"""remove all files in a transaction"""
|
||||
try:
|
||||
for fid in frappe.db.sql_list("""select name from `tabFile` where
|
||||
attached_to_doctype=%s and attached_to_name=%s""", (dt, dn)):
|
||||
if from_delete:
|
||||
# If deleting a doc, directly delete files
|
||||
frappe.delete_doc("File", fid, ignore_permissions=True)
|
||||
frappe.delete_doc("File", fid, ignore_permissions=True, delete_permanently=delete_permanently)
|
||||
else:
|
||||
# Removes file and adds a comment in the document it is attached to
|
||||
remove_file(fid=fid, attached_to_doctype=dt, attached_to_name=dn, from_delete=from_delete)
|
||||
remove_file(fid=fid, attached_to_doctype=dt, attached_to_name=dn,
|
||||
from_delete=from_delete, delete_permanently=delete_permanently)
|
||||
except Exception as e:
|
||||
if e.args[0]!=1054: raise # (temp till for patched)
|
||||
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ def delete_doc(doctype=None, name=None, force=0, ignore_doctypes=None, for_reloa
|
|||
doc.run_method("after_delete")
|
||||
|
||||
# delete attachments
|
||||
remove_all(doctype, name, from_delete=True)
|
||||
remove_all(doctype, name, from_delete=True, delete_permanently=delete_permanently)
|
||||
|
||||
if not for_reload:
|
||||
# Enqueued at the end, because it gets committed
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue