|
@@ -25,19 +25,24 @@ end
|
|
|
|
|
|
--- Return org when given its id or name
|
|
|
-- @function modpol.orgs.get_org
|
|
|
--- @param arg string for name of org or id of org
|
|
|
+-- @param arg string for name of org or id of org, or nil if no org
|
|
|
-- @return org specified by id or name
|
|
|
function modpol.orgs.get_org(arg)
|
|
|
- if type(arg) == 'string' then
|
|
|
- for id, org in ipairs(modpol.orgs.array) do
|
|
|
+ local output = nil
|
|
|
+ if type(arg) == 'string' then
|
|
|
+ for id, org in ipairs(modpol.orgs.array) do
|
|
|
+ if org ~= "deleted" then
|
|
|
if org.name == arg then
|
|
|
- return org
|
|
|
+ output = org
|
|
|
end
|
|
|
- end
|
|
|
- elseif type(arg) == 'number' then
|
|
|
- return modpol.orgs.array[arg]
|
|
|
- end
|
|
|
- return nil
|
|
|
+ end
|
|
|
+ end
|
|
|
+ elseif type(arg) == 'number' then
|
|
|
+ if modpol.orgs.array[arg] ~= "deleted" then
|
|
|
+ output = modpol.orgs.array[arg]
|
|
|
+ end
|
|
|
+ end
|
|
|
+ return output
|
|
|
end
|
|
|
|
|
|
--- Return a table list of all org names
|
|
@@ -80,7 +85,7 @@ function modpol.orgs.reset()
|
|
|
modpol.util.copy_table(modpol.instance.members)
|
|
|
for id, org in ipairs(modpol.orgs.array) do
|
|
|
if id > 1 then
|
|
|
- modpol.orgs.array[id] = "removed"
|
|
|
+ modpol.orgs.array[id] = "deleted"
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -214,7 +219,18 @@ function modpol.orgs:delete()
|
|
|
modpol.ocutil.log('Error in ' .. self.name .. ':delete -> cannot delete instance')
|
|
|
return false
|
|
|
end
|
|
|
+
|
|
|
+ -- remove from parent's list
|
|
|
+ local parent = modpol.orgs.get_org(self.id)
|
|
|
+ if parent then
|
|
|
+ for k,v in ipairs(parent.children) do
|
|
|
+ if v == self.id then
|
|
|
+ v = "deleted"
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
|
|
|
+ -- remove children
|
|
|
if #self.children > 0 then
|
|
|
for i, child_id in pairs(self.children) do
|
|
|
local child = modpol.orgs.get_org(child_id)
|
|
@@ -223,7 +239,7 @@ function modpol.orgs:delete()
|
|
|
end
|
|
|
end
|
|
|
|
|
|
- modpol.orgs.array[self.id] = 'removed'
|
|
|
+ modpol.orgs.array[self.id] = 'deleted'
|
|
|
modpol.orgs.count = modpol.orgs.count - 1
|
|
|
modpol.ocutil.log('Deleted org ' .. self.name .. ': ' .. self.id)
|
|
|
|