Revert "feat: removal of orphan entities"
This commit is contained in:
parent
2b9f1e08a7
commit
6f4b28d29e
3 changed files with 0 additions and 81 deletions
|
|
@ -127,8 +127,6 @@ class Workspace(Document):
|
|||
def on_trash(self):
|
||||
if self.public and not is_workspace_manager():
|
||||
frappe.throw(_("You need to be Workspace Manager to delete a public workspace."))
|
||||
self.delete_desktop_icon()
|
||||
self.delete_workspace_sidebar()
|
||||
self.delete_from_my_workspaces()
|
||||
|
||||
def delete_from_my_workspaces(self):
|
||||
|
|
@ -145,25 +143,6 @@ class Workspace(Document):
|
|||
if self.module and frappe.conf.developer_mode:
|
||||
delete_folder(self.module, "Workspace", self.title)
|
||||
|
||||
def delete_desktop_icon(self):
|
||||
if self.public:
|
||||
desktop_icon = frappe.get_all(
|
||||
"Desktop Icon",
|
||||
filters=[{"link_type": "Workspace"}, {"link_to": self.name}],
|
||||
limit=1,
|
||||
pluck="name",
|
||||
)
|
||||
if desktop_icon:
|
||||
frappe.delete_doc("Desktop Icon", desktop_icon[0])
|
||||
|
||||
def delete_workspace_sidebar(self):
|
||||
if self.public:
|
||||
workspace_sidebar = frappe.get_all(
|
||||
"Workspace Sidebar", filters=[{"name": self.name}], limit=1, pluck="name"
|
||||
)
|
||||
if workspace_sidebar:
|
||||
frappe.delete_doc("Workspace Sidebar", workspace_sidebar[0])
|
||||
|
||||
@staticmethod
|
||||
def get_module_wise_workspaces():
|
||||
workspaces = frappe.get_all(
|
||||
|
|
|
|||
|
|
@ -182,9 +182,6 @@ class SiteMigration:
|
|||
print("Removing orphan doctypes...")
|
||||
frappe.model.sync.remove_orphan_doctypes()
|
||||
|
||||
frappe.model.sync.remove_orphan_entities()
|
||||
|
||||
frappe.model.sync.delete_duplicate_icons()
|
||||
print("Syncing portal menu...")
|
||||
frappe.get_single("Portal Settings").sync_menu()
|
||||
|
||||
|
|
|
|||
|
|
@ -197,60 +197,3 @@ def remove_orphan_doctypes():
|
|||
update_progress_bar("Deleting orphaned DocTypes", i, len(orphan_doctypes))
|
||||
frappe.db.commit()
|
||||
print()
|
||||
|
||||
|
||||
def remove_orphan_entities():
|
||||
entites = ["Workspace", "Dashboard", "Page", "Report"]
|
||||
entity_filter_map = {
|
||||
"Workspace": {"public": 1},
|
||||
"Page": {"standard": "Yes"},
|
||||
"Report": {"is_standard": "Yes"},
|
||||
"Dashboard": {"is_standard": True},
|
||||
}
|
||||
for entity in entites:
|
||||
print(f"Removing orphan {entity}s")
|
||||
all_enitities = frappe.get_all(
|
||||
entity, filters=entity_filter_map.get(entity), fields=["name", "module"]
|
||||
)
|
||||
for i, w in enumerate(all_enitities):
|
||||
if w.module:
|
||||
try:
|
||||
module_path = frappe.get_module_path(w.module)
|
||||
if not check_if_record_exists(
|
||||
type="module", path=module_path, entity_type=entity, name=w.name
|
||||
):
|
||||
print(f"Deleting entity {entity} {w.name}")
|
||||
frappe.delete_doc(entity, w.name, force=True, ignore_missing=True)
|
||||
update_progress_bar(f"Deleting orphaned {entity}", i, len(all_enitities))
|
||||
print()
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
# save the deleted icons
|
||||
frappe.db.commit() # nosemgrep
|
||||
|
||||
|
||||
def check_if_record_exists(type=None, path=None, entity_type=None, name=None):
|
||||
scrubbed_name = frappe.scrub(name.lower())
|
||||
scrubbed_entity_type = frappe.scrub(entity_type.lower())
|
||||
if type == "app":
|
||||
entity_path = os.path.join(path, scrubbed_entity_type, f"{scrubbed_name}.json")
|
||||
else:
|
||||
entity_path = os.path.join(path, scrubbed_entity_type, scrubbed_name, f"{scrubbed_name}.json")
|
||||
return os.path.exists(entity_path)
|
||||
|
||||
|
||||
def delete_duplicate_icons():
|
||||
# This handles app icons which are renamed. Removes the old entry from db.
|
||||
for app in frappe.get_installed_apps():
|
||||
icons = frappe.get_all("Desktop Icon", filters=[{"icon_type": "App"}, {"app": app}], pluck="name")
|
||||
|
||||
if len(icons) > 1:
|
||||
for i in icons:
|
||||
app_path = frappe.get_app_path(app)
|
||||
if not check_if_record_exists(type="app", path=app_path, entity_type="Desktop Icon", name=i):
|
||||
print(f"Deleting icon {i}")
|
||||
frappe.delete_doc("Desktop Icon", i)
|
||||
|
||||
# save the deleted icons
|
||||
frappe.db.commit() # nosemgrep
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue