diff --git a/patches/april_2013/p05_update_file_data.py b/patches/april_2013/p05_update_file_data.py index d3877417e2..a5d2f7a07a 100644 --- a/patches/april_2013/p05_update_file_data.py +++ b/patches/april_2013/p05_update_file_data.py @@ -8,7 +8,7 @@ def execute(): singles = get_single_doctypes() for doctype in webnotes.conn.sql_list("""select parent from tabDocField where - fieldname='file_list' and fieldtype='Text'"""): + fieldname='file_list'"""): update_file_list(doctype, singles) webnotes.conn.sql("""delete from tabDocField where fieldname='file_list' @@ -32,9 +32,11 @@ def update_file_list(doctype, singles): ifnull(file_list, '')!=''""" % doctype, as_dict=True): update_for_doc(doctype, doc) webnotes.conn.commit() - webnotes.conn.sql("""alter table `tab%s` drop column file_list""" % doctype) + webnotes.conn.sql("""alter table `tab%s` drop column `file_list`""" % doctype) except Exception, e: - if e.args[0]!=1054: raise e + print webnotes.getTraceback() + if (e.args and e.args[0]!=1054) or not e.args: + raise e def update_for_doc(doctype, doc): for filedata in doc.file_list.split("\n"): @@ -60,10 +62,14 @@ def update_for_doc(doctype, doc): fd.doc.attached_to_name = doc.name fd.save() else: - fd = webnotes.bean("File Data", copy=fd.doclist) - fd.doc.attached_to_doctype = doctype - fd.doc.attached_to_name = doc.name - fd.insert() + try: + fd = webnotes.bean("File Data", copy=fd.doclist) + fd.doc.attached_to_doctype = doctype + fd.doc.attached_to_name = doc.name + fd.doc.name = None + fd.insert() + except webnotes.DuplicateEntryError: + pass else: webnotes.conn.sql("""delete from `tabFile Data` where name=%s""", fileid) \ No newline at end of file diff --git a/patches/april_2013/p07_update_file_data_2.py b/patches/april_2013/p07_update_file_data_2.py new file mode 100644 index 0000000000..7b89a9de77 --- /dev/null +++ b/patches/april_2013/p07_update_file_data_2.py @@ -0,0 +1,15 @@ +import webnotes +def execute(): + from patches.april_2013.p05_update_file_data import update_file_list, get_single_doctypes + + singles = get_single_doctypes() + for doctype in webnotes.conn.sql_list("""select table_name from `information_schema`.`columns` + where table_schema=%s and column_name='file_list'""", webnotes.conn.cur_db_name): + doctype = doctype[3:] + update_file_list(doctype, singles) + + webnotes.conn.sql("""delete from `tabCustom Field` where fieldname='file_list' + and parent=%s""", doctype) + webnotes.conn.sql("""delete from `tabDocField` where fieldname='file_list' + and parent=%s""", doctype) + \ No newline at end of file diff --git a/patches/april_2013/p07_update_file_data_custom_field.py b/patches/april_2013/p07_update_file_data_custom_field.py deleted file mode 100644 index 909df0554d..0000000000 --- a/patches/april_2013/p07_update_file_data_custom_field.py +++ /dev/null @@ -1,11 +0,0 @@ -import webnotes -def execute(): - from patches.april_2013.p05_update_file_data import update_file_list, get_single_doctypes - singles = get_single_doctypes() - for doctype in webnotes.conn.sql("""select parent from `tabCustom Field` where - fieldname='file_list' and fieldtype='Text'"""): - update_file_list(doctype, singles) - - webnotes.conn.sql("""delete from `tabCustom Field` where fieldname='file_list' - and parent=%s""", doctype) - \ No newline at end of file diff --git a/patches/patch_list.py b/patches/patch_list.py index 096fec80ab..70aeb4a6ff 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -247,5 +247,5 @@ patch_list = [ "execute:webnotes.reload_doc('Stock', 'DocType', 'Delivery Note Item')", "patches.april_2013.p06_default_cost_center", "execute:webnotes.reset_perms('File Data')", - "patches.april_2013.p07_update_file_data_custom_field", + "patches.april_2013.p07_update_file_data_2", ] \ No newline at end of file