diff --git a/frappe/patches.txt b/frappe/patches.txt index a678367b90..a23f61b899 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -48,3 +48,4 @@ execute:frappe.db.sql("""update `tabSingles` set `value`=`doctype` where `field` frappe.patches.v4_1.enable_print_as_pdf #2014-06-17 execute:frappe.db.sql("""update `tabDocPerm` set email=1 where parent='User' and permlevel=0 and `role`='All' and `read`=1 and apply_user_permissions=1""") #2014-07-15 execute:frappe.db.sql("""update `tabPrint Format` set print_format_type='Client' where ifnull(print_format_type, '')=''""") #2014-07-28 +frappe.patches.v4_1.file_manager_fix diff --git a/frappe/patches/v4_1/file_manager_fix.py b/frappe/patches/v4_1/file_manager_fix.py new file mode 100644 index 0000000000..8831af94bb --- /dev/null +++ b/frappe/patches/v4_1/file_manager_fix.py @@ -0,0 +1,31 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# MIT License. See license.txt + +from __future__ import unicode_literals + +import frappe +import os +from frappe.utils import get_files_path +from frappe.utils.file_manager import get_content_hash, get_file + + +def execute(): + for name, file_name, file_url in frappe.db.sql( + """select name, file_name, file_url from `tabFile Data` + where file_name is not null and content_hash is null"""): + b = frappe.get_doc('File Data', name) + old_file_name = b.file_name + b.file_name = os.path.basename(old_file_name) + if old_file_name.startswith('files/') or old_file_name.startswith('/files/'): + b.file_url = os.path.normpath('/' + old_file_name) + else: + b.file_url = os.path.normpath('/files/' + old_file_name) + 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 + + b.save()