fixes to filemanager patch deleting files with duplicate entries

This commit is contained in:
Pratik Vyas 2014-05-10 22:06:05 +05:30
parent 417cec89cb
commit 9ee4649ee4
2 changed files with 14 additions and 5 deletions

View file

@ -44,8 +44,8 @@ class FileData(Document):
pass
# if file not attached to any other record, delete it
if self.file_name and not frappe.db.count("File Data",
{"content_hash": self.content_hash, "name": ["!=", self.name]}):
if self.file_name and self.content_hash and (not frappe.db.count("File Data",
{"content_hash": self.content_hash, "name": ["!=", self.name]})):
delete_file_data_content(self)
def on_rollback(self):

View file

@ -21,7 +21,16 @@ def execute():
b.file_url = os.path.normpath('/' + old_file_name)
else:
b.file_url = os.path.normpath('/files/' + old_file_name)
_file_name, content = get_file(name)
b.content_hash = get_content_hash(content)
b.save()
try:
_file_name, content = get_file(name)
b.content_hash = get_content_hash(content)
except IOError:
print 'Warning: Error processing ', name
_file_name = old_file_name
b.content_hash = None
try:
b.save()
except frappe.DuplicateEntryError:
frappe.delete_doc(b.doctype, b.name)