Просмотр исходного кода

[fix] delete attachments last, fixes #978

version-14
Rushabh Mehta 8 лет назад
Родитель
Сommit
05268603cf
2 измененных файлов: 9 добавлений и 9 удалений
  1. +4
    -4
      frappe/model/delete_doc.py
  2. +5
    -5
      frappe/utils/file_manager.py

+ 4
- 4
frappe/model/delete_doc.py Просмотреть файл

@@ -34,9 +34,6 @@ def delete_doc(doctype=None, name=None, force=0, ignore_doctypes=None, for_reloa
if not frappe.db.exists(doctype, name): if not frappe.db.exists(doctype, name):
return return


# delete attachments
remove_all(doctype, name)

# delete passwords # delete passwords
delete_all_passwords_for(doctype, name) delete_all_passwords_for(doctype, name)


@@ -97,6 +94,9 @@ def delete_doc(doctype=None, name=None, force=0, ignore_doctypes=None, for_reloa
delete_from_table(doctype, name, ignore_doctypes, doc) delete_from_table(doctype, name, ignore_doctypes, doc)
doc.run_method("after_delete") doc.run_method("after_delete")


# delete attachments
remove_all(doctype, name, from_delete=True)

if doc and not frappe.flags.in_patch: if doc and not frappe.flags.in_patch:
try: try:
doc.notify_update() doc.notify_update()
@@ -182,7 +182,7 @@ def check_if_doc_is_linked(doc, method="Delete"):
def check_if_doc_is_dynamically_linked(doc, method="Delete"): def check_if_doc_is_dynamically_linked(doc, method="Delete"):
'''Raise `frappe.LinkExistsError` if the document is dynamically linked''' '''Raise `frappe.LinkExistsError` if the document is dynamically linked'''
for df in get_dynamic_link_map().get(doc.doctype, []): for df in get_dynamic_link_map().get(doc.doctype, []):
if df.parent in ("Communication", "ToDo", "DocShare", "Email Unsubscribe"):
if df.parent in ("Communication", "ToDo", "DocShare", "Email Unsubscribe", 'File'):
# don't check for communication and todo! # don't check for communication and todo!
continue continue




+ 5
- 5
frappe/utils/file_manager.py Просмотреть файл

@@ -6,7 +6,7 @@ import frappe
import os, base64, re import os, base64, re
import hashlib import hashlib
import mimetypes import mimetypes
from frappe.utils import get_site_path, get_hook_method, get_files_path, random_string, encode, cstr, call_hook_method, cint
from frappe.utils import get_hook_method, get_files_path, random_string, encode, cstr, call_hook_method, cint
from frappe import _ from frappe import _
from frappe import conf from frappe import conf
from copy import copy from copy import copy
@@ -229,12 +229,12 @@ def write_file(content, fname, is_private=0):


return get_files_path(fname, is_private=is_private) return get_files_path(fname, is_private=is_private)


def remove_all(dt, dn):
def remove_all(dt, dn, from_delete=False):
"""remove all files in a transaction""" """remove all files in a transaction"""
try: try:
for fid in frappe.db.sql_list("""select name from `tabFile` where for fid in frappe.db.sql_list("""select name from `tabFile` where
attached_to_doctype=%s and attached_to_name=%s""", (dt, dn)): attached_to_doctype=%s and attached_to_name=%s""", (dt, dn)):
remove_file(fid, dt, dn)
remove_file(fid, dt, dn, from_delete)
except Exception, e: except Exception, e:
if e.args[0]!=1054: raise # (temp till for patched) if e.args[0]!=1054: raise # (temp till for patched)


@@ -248,7 +248,7 @@ def remove_file_by_url(file_url, doctype=None, name=None):
if fid: if fid:
return remove_file(fid) return remove_file(fid)


def remove_file(fid, attached_to_doctype=None, attached_to_name=None):
def remove_file(fid, attached_to_doctype=None, attached_to_name=None, from_delete=False):
"""Remove file and File entry""" """Remove file and File entry"""
file_name = None file_name = None
if not (attached_to_doctype and attached_to_name): if not (attached_to_doctype and attached_to_name):
@@ -258,7 +258,7 @@ def remove_file(fid, attached_to_doctype=None, attached_to_name=None):
attached_to_doctype, attached_to_name, file_name = attached attached_to_doctype, attached_to_name, file_name = attached


ignore_permissions, comment = False, None ignore_permissions, comment = False, None
if attached_to_doctype and attached_to_name:
if attached_to_doctype and attached_to_name and not from_delete:
doc = frappe.get_doc(attached_to_doctype, attached_to_name) doc = frappe.get_doc(attached_to_doctype, attached_to_name)
ignore_permissions = doc.has_permission("write") or False ignore_permissions = doc.has_permission("write") or False
if frappe.flags.in_web_form: if frappe.flags.in_web_form:


Загрузка…
Отмена
Сохранить