From 7ef8f5f7a2560740797faeec8898aaa90a5904b0 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 16 Aug 2016 10:00:58 +0530 Subject: [PATCH] [minor] fixes to patches, ignore validate if in patch, move some events to hourly --- .../communication/communication_list.js | 2 +- .../property_setter/property_setter.py | 3 +++ frappe/hooks.py | 9 ++++--- frappe/model/delete_doc.py | 10 ++++---- frappe/modules/patch_handler.py | 25 +++++++++++++++---- frappe/patches.txt | 6 ++--- 6 files changed, 37 insertions(+), 18 deletions(-) diff --git a/frappe/core/doctype/communication/communication_list.js b/frappe/core/doctype/communication/communication_list.js index 521004f838..b352317e2d 100644 --- a/frappe/core/doctype/communication/communication_list.js +++ b/frappe/core/doctype/communication/communication_list.js @@ -1,5 +1,5 @@ frappe.listview_settings['Communication'] = { add_fields: ["sent_or_received", "recipients", "subject", "communication_medium", "communication_type"], - default_filters: [["Communication", "communication_type", "=", "Communication"]], + //default_filters: [["Communication", "communication_type", "=", "Communication"]], filters: [["status", "=", "Open"]] }; diff --git a/frappe/custom/doctype/property_setter/property_setter.py b/frappe/custom/doctype/property_setter/property_setter.py index 8766cfa3d0..ebbdc7162a 100644 --- a/frappe/custom/doctype/property_setter/property_setter.py +++ b/frappe/custom/doctype/property_setter/property_setter.py @@ -50,6 +50,9 @@ class PropertySetter(Document): (self.field_name, self.doc_type), as_dict = 1)[0] def on_update(self): + if frappe.flags.in_patch: + self.flags.validate_fields_for_doctype = False + if not self.flags.ignore_validate and self.flags.validate_fields_for_doctype: from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype validate_fields_for_doctype(self.doc_type) diff --git a/frappe/hooks.py b/frappe/hooks.py index 7f8f1ecaa0..5361cea661 100755 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -125,9 +125,11 @@ scheduler_events = { "frappe.email.queue.flush", "frappe.email.doctype.email_account.email_account.pull", "frappe.email.doctype.email_account.email_account.notify_unreplied", - "frappe.utils.error.collect_error_snapshots", + ], + "hourly": [ "frappe.model.utils.link_count.update_link_count", - 'frappe.model.utils.list_settings.sync_list_settings' + 'frappe.model.utils.list_settings.sync_list_settings', + "frappe.utils.error.collect_error_snapshots" ], "daily": [ "frappe.email.queue.clear_outbox", @@ -139,8 +141,7 @@ scheduler_events = { "frappe.async.remove_old_task_logs", "frappe.utils.scheduler.disable_scheduler_on_expiry", "frappe.utils.scheduler.restrict_scheduler_events_if_dormant", - "frappe.limits.update_space_usage" - + "frappe.limits.update_space_usage", ], "daily_long": [ "frappe.integrations.doctype.dropbox_backup.dropbox_backup.take_backups_daily" diff --git a/frappe/model/delete_doc.py b/frappe/model/delete_doc.py index c1e6b8cf91..d9efc3155c 100644 --- a/frappe/model/delete_doc.py +++ b/frappe/model/delete_doc.py @@ -53,10 +53,10 @@ def delete_doc(doctype=None, name=None, force=0, ignore_doctypes=None, for_reloa else: doc = frappe.get_doc(doctype, name) - + update_flags(doc, flags, ignore_permissions) check_permission_and_not_submitted(doc) - + frappe.db.sql("delete from `tabCustom Field` where dt = %s", name) frappe.db.sql("delete from `tabCustom Script` where dt = %s", name) frappe.db.sql("delete from `tabProperty Setter` where doc_type = %s", name) @@ -97,7 +97,7 @@ def delete_doc(doctype=None, name=None, force=0, ignore_doctypes=None, for_reloa delete_from_table(doctype, name, ignore_doctypes, doc) doc.run_method("after_delete") - if doc: + if doc and not frappe.flags.in_patch: try: doc.notify_update() insert_feed(doc) @@ -139,14 +139,14 @@ def delete_from_table(doctype, name, ignore_doctypes, doc): for t in list(set(tables)): if t not in ignore_doctypes: frappe.db.sql("delete from `tab%s` where parenttype=%s and parent = %s" % (t, '%s', '%s'), (doctype, name)) - + def update_flags(doc, flags=None, ignore_permissions=False): if ignore_permissions: if not flags: flags = {} flags["ignore_permissions"] = ignore_permissions if flags: - doc.flags.update(flags) + doc.flags.update(flags) def check_permission_and_not_submitted(doc): # permission diff --git a/frappe/modules/patch_handler.py b/frappe/modules/patch_handler.py index 0b7502ed46..a499133163 100644 --- a/frappe/modules/patch_handler.py +++ b/frappe/modules/patch_handler.py @@ -12,7 +12,7 @@ from __future__ import unicode_literals where patch1, patch2 is module name """ -import frappe, os, frappe.permissions +import frappe, frappe.permissions class PatchError(Exception): pass @@ -20,12 +20,20 @@ def run_all(): """run all pending patches""" executed = [p[0] for p in frappe.db.sql("""select patch from `tabPatch Log`""")] + frappe.flags.final_patches = [] for patch in get_all_patches(): if patch and (patch not in executed): if not run_single(patchmodule = patch): log(patch + ': failed: STOPPED') raise PatchError(patch) + # patches to be run in the end + for patch in frappe.flags.final_patches: + patch = patch.replace('finally:', '') + if not run_single(patchmodule = patch): + log(patch + ': failed: STOPPED') + raise PatchError(patch) + def get_all_patches(): patches = [] for app in frappe.get_installed_apps(): @@ -62,11 +70,15 @@ def execute_patch(patchmodule, method=None, methodargs=None): log('Executing {patch} in {site} ({db})'.format(patch=patchmodule or str(methodargs), site=frappe.local.site, db=frappe.db.cur_db_name)) if patchmodule: - if patchmodule.startswith("execute:"): - exec patchmodule.split("execute:")[1] in globals() + if patchmodule.startswith("finally:"): + # run run patch at the end + frappe.flags.final_patches.append(patchmodule) else: - frappe.get_attr(patchmodule.split()[0] + ".execute")() - update_patch_log(patchmodule) + if patchmodule.startswith("execute:"): + exec patchmodule.split("execute:")[1] in globals() + else: + frappe.get_attr(patchmodule.split()[0] + ".execute")() + update_patch_log(patchmodule) elif method: method(**methodargs) @@ -87,6 +99,9 @@ def update_patch_log(patchmodule): def executed(patchmodule): """return True if is executed""" + if patchmodule.startswith('finally:'): + # patches are saved without the finally: tag + patchmodule = patchmodule.replace('finally:', '') done = frappe.db.get_value("Patch Log", {"patch": patchmodule}) # if done: # print "Patch %s already executed in %s" % (patchmodule, frappe.db.cur_db_name) diff --git a/frappe/patches.txt b/frappe/patches.txt index 02d546040a..9044ed4c4c 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -1,6 +1,8 @@ execute:frappe.db.sql("""update `tabPatch Log` set patch=replace(patch, '.4_0.', '.v4_0.')""") #2014-05-12 frappe.patches.v5_0.convert_to_barracuda_and_utf8mb4 +frappe.patches.v7_0.update_auth frappe.patches.v6_1.rename_file_data +frappe.patches.v7_0.re_route #2016-06-27 execute:frappe.reload_doc('core', 'doctype', 'doctype', force=True) #2016-07-11 execute:frappe.reload_doc('core', 'doctype', 'docfield', force=True) #2016-02-26 execute:frappe.reload_doc('core', 'doctype', 'docperm') #2014-06-24 @@ -16,7 +18,6 @@ execute:frappe.reload_doc('custom', 'doctype', 'property_setter') #2014-12-31-1 execute:frappe.reload_doc('core', 'doctype', 'patch_log') #2016-10-31 execute:frappe.reload_doctype("File") # 2015-10-19 execute:frappe.reload_doc('core', 'doctype', 'error_snapshot') -frappe.patches.v7_0.update_auth frappe.patches.v7_0.rename_bulk_email_to_email_queue execute:frappe.db.sql("alter table `tabSessions` modify `user` varchar(255), engine=InnoDB") @@ -122,7 +123,7 @@ frappe.patches.v6_16.feed_doc_owner frappe.patches.v6_21.print_settings_repeat_header_footer frappe.patches.v6_24.set_language_as_code frappe.patches.v6_20x.update_insert_after -frappe.patches.v6_24.sync_desktop_icons +finally:frappe.patches.v6_24.sync_desktop_icons frappe.patches.v6_20x.set_allow_draft_for_print frappe.patches.v6_20x.remove_roles_from_website_user frappe.patches.v7_0.set_user_fullname @@ -132,7 +133,6 @@ frappe.patches.v7_0.update_send_after_in_bulk_email frappe.patches.v7_0.setup_list_settings execute:frappe.db.sql('''delete from `tabSingles` where doctype="Email Settings"''') # 2016-06-13 execute:frappe.db.sql("delete from `tabWeb Page` where ifnull(template_path, '')!=''") -frappe.patches.v7_0.re_route #2016-06-27 frappe.patches.v7_0.rename_newsletter_list_to_email_group frappe.patches.v7_0.replace_upgrade_link_limit frappe.patches.v7_0.set_email_group \ No newline at end of file