fix: remove orphan workspace sidebars
This commit is contained in:
parent
0390c8d933
commit
5c81a34cbb
1 changed files with 23 additions and 0 deletions
|
|
@ -201,13 +201,16 @@ def remove_orphan_doctypes():
|
|||
|
||||
def remove_orphan_entities():
|
||||
entites = ["Workspace", "Dashboard", "Page", "Report"]
|
||||
app_level_entities = ["Workspace Sidebar"]
|
||||
entity_filter_map = {
|
||||
"Workspace": {"public": 1},
|
||||
"Page": {"standard": "Yes"},
|
||||
"Report": {"is_standard": "Yes"},
|
||||
"Dashboard": {"is_standard": True},
|
||||
"Workspace Sidebar": {"standard": True},
|
||||
}
|
||||
entity_file_map = create_entity_file_map(entites)
|
||||
|
||||
for entity in entites:
|
||||
print(f"Removing orphan {entity}s")
|
||||
all_enitities = frappe.get_all(
|
||||
|
|
@ -228,6 +231,26 @@ def remove_orphan_entities():
|
|||
print(e)
|
||||
# save the deleted icons
|
||||
frappe.db.commit() # nosemgrep
|
||||
# Remove app level entities
|
||||
for app_entity in app_level_entities:
|
||||
print(f"Removing orphan {app_entity}s")
|
||||
all_enitities = frappe.get_all(
|
||||
app_entity, filters=entity_filter_map.get(app_entity), fields=["name", "app"]
|
||||
)
|
||||
for i, w in enumerate(all_enitities):
|
||||
if w.app and not check_if_record_exists("app", frappe.get_app_path(w.app), app_entity, w.name):
|
||||
try:
|
||||
print(f"Deleting entity {app_entity} {w.name}")
|
||||
frappe.delete_doc(app_entity, w.name, force=True, ignore_missing=True)
|
||||
update_progress_bar(f"Deleting orphaned {app_entity}", i, len(all_enitities))
|
||||
print()
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error occurred while deleting entity: {app_entity} {w.name}")
|
||||
print(e)
|
||||
|
||||
# save the deleted icons
|
||||
frappe.db.commit() # nosemgrep
|
||||
|
||||
|
||||
def create_entity_file_map(entities):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue