From 91adb074791eac657bc119445df3ac21b6d4d908 Mon Sep 17 00:00:00 2001 From: Mohammed Haris Date: Mon, 9 Sep 2024 18:16:10 +0530 Subject: [PATCH] feat: file changes for v15 migration --- frappe/installer.py | 28 ++++++++++++++------------ frappe/model/delete_doc.py | 40 ++++++++++++++++++++------------------ frappe/patches.txt | 2 -- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/frappe/installer.py b/frappe/installer.py index 81f107dc1169..af578f541a48 100644 --- a/frappe/installer.py +++ b/frappe/installer.py @@ -445,12 +445,14 @@ def _delete_modules(modules: list[str], dry_run: bool) -> list[str]: def _delete_linked_documents(module_name: str, doctype_linkfield_map: dict[str, str], dry_run: bool) -> None: """Deleted all records linked with module def""" - for doctype, fieldname in doctype_linkfield_map.items(): - for record in frappe.get_all(doctype, filters={fieldname: module_name}, pluck="name"): - print(f"* removing {doctype} '{record}'...") - if not dry_run: - frappe.delete_doc(doctype, record, ignore_on_trash=True, force=True) - + try: + for doctype, fieldname in doctype_linkfield_map.items(): + for record in frappe.get_all(doctype, filters={fieldname: module_name}, pluck="name"): + print(f"* removing {doctype} '{record}'...") + if not dry_run: + frappe.delete_doc(doctype, record, ignore_on_trash=True, force=True) + except Exception: + print("Error while deleting linked documents") def _get_module_linked_doctype_field_map() -> dict[str, str]: """Get all the doctypes which have module linked with them. @@ -482,12 +484,14 @@ def _get_module_linked_doctype_field_map() -> dict[str, str]: def _delete_doctypes(doctypes: list[str], dry_run: bool) -> None: - for doctype in set(doctypes): - print(f"* dropping Table for '{doctype}'...") - if not dry_run: - frappe.delete_doc("DocType", doctype, ignore_on_trash=True, force=True) - frappe.db.sql_ddl(f"DROP TABLE IF EXISTS `tab{doctype}`") - + try: + for doctype in set(doctypes): + print(f"* dropping Table for '{doctype}'...") + if not dry_run: + frappe.delete_doc("DocType", doctype, ignore_on_trash=True, force=True) + frappe.db.sql_ddl(f"DROP TABLE IF EXISTS `tab{doctype}`") + except Exception: + print("Error while deleting doctypes") def post_install(rebuild_website=False): from frappe.website.utils import clear_website_cache diff --git a/frappe/model/delete_doc.py b/frappe/model/delete_doc.py index 8dd37fa80d4b..423f651ea5bd 100644 --- a/frappe/model/delete_doc.py +++ b/frappe/model/delete_doc.py @@ -203,27 +203,29 @@ def update_naming_series(doc): def delete_from_table(doctype: str, name: str, ignore_doctypes: list[str], doc): - if doctype != "DocType" and doctype == name: - frappe.db.delete("Singles", {"doctype": name}) - else: - frappe.db.delete(doctype, {"name": name}) - if doc: - child_doctypes = [ - d.options for d in doc.meta.get_table_fields() if frappe.get_meta(d.options).is_virtual == 0 - ] - - else: - child_doctypes = frappe.get_all( - "DocField", - fields="options", - filters={"fieldtype": ["in", frappe.model.table_fields], "parent": doctype}, - pluck="options", - ) + try: + if doctype != "DocType" and doctype == name: + frappe.db.delete("Singles", {"doctype": name}) + else: + frappe.db.delete(doctype, {"name": name}) + if doc: + child_doctypes = [ + d.options for d in doc.meta.get_table_fields() if frappe.get_meta(d.options).is_virtual == 0 + ] - child_doctypes_to_delete = set(child_doctypes) - set(ignore_doctypes) - for child_doctype in child_doctypes_to_delete: - frappe.db.delete(child_doctype, {"parenttype": doctype, "parent": name}) + else: + child_doctypes = frappe.get_all( + "DocField", + fields="options", + filters={"fieldtype": ["in", frappe.model.table_fields], "parent": doctype}, + pluck="options", + ) + child_doctypes_to_delete = set(child_doctypes) - set(ignore_doctypes) + for child_doctype in child_doctypes_to_delete: + frappe.db.delete(child_doctype, {"parenttype": doctype, "parent": name}) + except Exception: + print("Error deleting from table", doctype, name) def update_flags(doc, flags=None, ignore_permissions=False): if ignore_permissions: diff --git a/frappe/patches.txt b/frappe/patches.txt index decd513c2d91..a373e1fca83f 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -167,7 +167,6 @@ execute:frappe.delete_doc_if_exists('Page', 'workspace') execute:frappe.delete_doc_if_exists('Page', 'dashboard', force=1) frappe.core.doctype.page.patches.drop_unused_pages frappe.patches.v13_0.remove_chat -frappe.patches.v13_0.rename_desk_page_to_workspace # 02.02.2021 frappe.patches.v13_0.delete_package_publish_tool frappe.patches.v13_0.rename_list_view_setting_to_list_view_settings frappe.patches.v13_0.remove_twilio_settings @@ -188,7 +187,6 @@ frappe.patches.v14_0.reset_creation_datetime frappe.patches.v14_0.remove_is_first_startup frappe.patches.v14_0.clear_long_pending_stale_logs frappe.patches.v14_0.log_settings_migration -frappe.patches.v14_0.setup_likes_from_feedback frappe.patches.v14_0.update_webforms frappe.patches.v14_0.delete_payment_gateways frappe.patches.v15_0.remove_event_streaming