From 36d52861ccbd5f5dec788c243eceac01c45cbd7c Mon Sep 17 00:00:00 2001 From: memurats Date: Thu, 3 Apr 2025 14:58:07 +0200 Subject: [PATCH] added deletion query to cleanup user preferences --- appinfo/info.xml | 4 ++-- lib/Db/UserQueries.php | 16 ++++++++++++++++ lib/User/UserAccountDeletionJob.php | 6 +++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 0960729..6ddc602 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -6,7 +6,7 @@ NextMagentaCloud business functions for customer tariff evaluation This app contains business logic to evaluate provisoning info paased in as set of openid claim-like attributes - 1.1.0 + 1.2.0 agpl Bernd Rederlechner NextMagentaCloudProvisioning @@ -18,7 +18,7 @@ as set of openid claim-like attributes - + OCA\NextMagentaCloudProvisioning\User\UserAccountDeletionJob diff --git a/lib/Db/UserQueries.php b/lib/Db/UserQueries.php index 9b0cf66..ea3a3ef 100644 --- a/lib/Db/UserQueries.php +++ b/lib/Db/UserQueries.php @@ -75,4 +75,20 @@ public function countMigrated(): int { $result->closeCursor(); return $column; } + + /** + * Delete a user preference by their user ID + * + * @param string $userId + * @return bool True if deletion was successful, false otherwise + */ + public function deleteUserPreferenceById(string $userId): bool { + $qb = $this->db->getQueryBuilder(); + + $qb->delete('preferences') + ->where($qb->expr()->eq('userid', $qb->createNamedParameter($userId))) + ->execute(); + + return true; // Return true to indicate successful deletion + } } diff --git a/lib/User/UserAccountDeletionJob.php b/lib/User/UserAccountDeletionJob.php index 6829df9..9075693 100644 --- a/lib/User/UserAccountDeletionJob.php +++ b/lib/User/UserAccountDeletionJob.php @@ -66,7 +66,11 @@ public function run($arguments) { try { $user = $this->userManager->get($uid); if (!$user) { - $this->logger->warning("User $uid not found, skipping."); + $this->logger->warning("User $uid not found, removing deletion entry and cleaning up."); + + // Call deleteUserPreferenceById to ensure cleanup + $this->userQueries->deleteUserPreferenceById($uid); + continue; }