From f88214f319fcbc6b47f46f61d4cd61bfdb73ef56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20D=C3=ADaz?= Date: Thu, 5 Nov 2026 13:31:04 +0100 Subject: [PATCH] [LTI] fix: allow deleting tools whose objects no longer exist --- components/ILIAS/LTI/classes/Object/class.ilLTITool.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/ILIAS/LTI/classes/Object/class.ilLTITool.php b/components/ILIAS/LTI/classes/Object/class.ilLTITool.php index 564009b4dc15..af560b829d05 100644 --- a/components/ILIAS/LTI/classes/Object/class.ilLTITool.php +++ b/components/ILIAS/LTI/classes/Object/class.ilLTITool.php @@ -567,14 +567,16 @@ public static function delete(array $ids): void } /** - * Number of LTI objects using one of the given tools. A tool in use must not be deleted. + * Number of LTI objects, in the repository or in the trash, using one of the given tools. + * A tool in use must not be deleted. Settings of objects that no longer exist are not usages. */ public static function countUsages(array $ids): int { $db = self::db(); $result = $db->query( - 'SELECT COUNT(*) cnt FROM ' . ilObjLTITool::TABLE_NAME - . ' WHERE ' . $db->in('provider_id', $ids, false, 'integer') + 'SELECT COUNT(DISTINCT s.obj_id) cnt FROM ' . ilObjLTITool::TABLE_NAME . ' s' + . ' JOIN object_reference r ON r.obj_id = s.obj_id' + . ' WHERE ' . $db->in('s.provider_id', $ids, false, 'integer') ); return (int) $db->fetchAssoc($result)['cnt'];