Skip to content

Commit 9931462

Browse files
committed
Fix duplicate UID and delete orphaned bindings, fixes #255
1 parent 73b3736 commit 9931462

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ The format of this changelog is based on [Keep a Changelog](https://keepachangel
3939
* Fix deleted bindings not being deactivated immediately
4040
* Fix a potential data conflict issue when importing a profile [#252] (by [m33shoq])
4141
* Fix logic error [#270] (by [KyrosKrane])
42+
* Fix duplicate binding IDs [#255]
4243

4344
## [1.16.11] - 2024-11-07
4445

@@ -1750,6 +1751,7 @@ The format of this changelog is based on [Keep a Changelog](https://keepachangel
17501751
[#264]: https://github.com/Snakybo/Clicked/pull/264
17511752
[#263]: https://github.com/Snakybo/Clicked/issues/263
17521753
[#257]: https://github.com/Snakybo/Clicked/issues/257
1754+
[#255]: https://github.com/Snakybo/Clicked/issues/255
17531755
[#252]: https://github.com/Snakybo/Clicked/pull/252
17541756
[#251]: https://github.com/Snakybo/Clicked/issues/251
17551757
[#248]: https://github.com/Snakybo/Clicked/issues/248

Clicked/Core/Upgrader.lua

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ local Addon = select(2, ...)
55

66
Addon.DATA_VERSION = 12
77

8+
local upgradeData = {}
9+
810
-- Local support functions
911

1012
local function errorhandler(err)
@@ -890,6 +892,37 @@ local function Upgrade(db, from)
890892
binding.action.stopSpellTarget = true
891893
end
892894
end
895+
896+
if from < 13 then
897+
upgradeData[13] = upgradeData[13] or {}
898+
upgradeData[13].seen = upgradeData[13].seen or {}
899+
900+
local orphans = {}
901+
902+
for i, binding in ipairs(db.bindings) do
903+
local function HasParent(group)
904+
return binding.parent == group.uid
905+
end
906+
907+
if upgradeData[13].seen[binding.uid] then
908+
if binding.parent == nil or FindInTableIf(db.groups, HasParent) then
909+
binding.uid = Addon.db.global.nextUid
910+
Addon.db.global.nextUid = binding.uid + 1
911+
else
912+
table.insert(orphans, i)
913+
end
914+
elseif binding.parent ~= nil and not FindInTableIf(db.groups, HasParent) then
915+
binding.parent = nil
916+
end
917+
918+
upgradeData[13].seen[binding.uid] = true
919+
end
920+
921+
table.sort(orphans, function(a, b) return a > b end)
922+
for _, i in ipairs(orphans) do
923+
table.remove(db.bindings, i)
924+
end
925+
end
893926
end
894927

895928
-- Private addon API
@@ -909,6 +942,8 @@ function Addon:UpgradeDatabase(from)
909942
-- when the value of a constant changes. Always use direct values that are
910943
-- read from the database.
911944

945+
table.wipe(upgradeData)
946+
912947
if not Addon.DISABLE_GLOBAL_SCOPE then
913948
local src = from or Addon.db.global.version or Addon.DATA_VERSION
914949

0 commit comments

Comments
 (0)