From a835799e110a5963650832abf75ab77aa479f274 Mon Sep 17 00:00:00 2001 From: Luke Miller <millerluke1364@gmail.com> Date: Thu, 6 Jan 2022 20:17:38 -0500 Subject: [PATCH] added delete process tree function, updated remove process module --- modpol_core/modules/remove_process.lua | 4 ++-- modpol_core/orgs/process.lua | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/modpol_core/modules/remove_process.lua b/modpol_core/modules/remove_process.lua index f8997ff..39cf40c 100644 --- a/modpol_core/modules/remove_process.lua +++ b/modpol_core/modules/remove_process.lua @@ -64,7 +64,7 @@ function remove_process:initiate(result) function(input) if input == "Yes" then if process_mine then - self.org:delete_process(process_id) + self.org:delete_process_tree(process_id) modpol.interactions.message( self.initiator, "Removed process: "..process_choice) @@ -86,7 +86,7 @@ function remove_process:initiate(result) self.org.id, "Removing process: ".. process_choice) - self.org:delete_process(process_id) + self.org:delete_process_tree(process_id) modpol.interactions.org_dashboard( self.initiator, self.org.id) if result then result() end diff --git a/modpol_core/orgs/process.lua b/modpol_core/orgs/process.lua index 25c7ba6..f00ad2c 100644 --- a/modpol_core/orgs/process.lua +++ b/modpol_core/orgs/process.lua @@ -48,6 +48,14 @@ function modpol.orgs:call_module(module_slug, initiator, config, result, parent_ return index end +function modpol.orgs:get_root_process(id) + local process = self.processes[id] + while (process.parent_id) do + process = self.processes[process.parent_id] + end + return process +end + function modpol.orgs:delete_process(id) local process = self.processes[id] if process and process ~= "deleted" then @@ -66,6 +74,10 @@ function modpol.orgs:delete_process(id) end end +function modpol.orgs:delete_process_tree(id) + self:delete_process(self:get_root_process(id).id) +end + function modpol.orgs:add_pending_action(process_id, user, callback) self.pending[user] = self.pending[user] or {} self.pending[user][process_id] = callback