From 725b3c95f706a3115e20719d2d5cf8cafa12e671 Mon Sep 17 00:00:00 2001 From: tvv28669 Date: Thu, 28 Oct 2021 12:11:11 +0100 Subject: [PATCH] Delete user function --- resources/RemoveInactiveUsersRunner.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/resources/RemoveInactiveUsersRunner.php b/resources/RemoveInactiveUsersRunner.php index 203d78dc7..73b9787e9 100644 --- a/resources/RemoveInactiveUsersRunner.php +++ b/resources/RemoveInactiveUsersRunner.php @@ -36,7 +36,7 @@ if ($elapsedMonths > 18){ // Delete user echo "Deleting user\n"; - deleteUser($user); + deleteUser($user, $em); } elseif ($elapsedMonths > 17){ // Warn user echo "Requesting user warning email.\n"; @@ -52,8 +52,19 @@ $em->flush(); echo "Completed ok: ".date('D, d M Y H:i:s'); -function deleteUser($user){ - echo "User deleted."; +function deleteUser($user, $em){ + $em->getConnection()->beginTransaction(); + try { + $em->remove($user); + $em->flush(); + $em->getConnection()->commit(); + echo "User deleted.\n"; + } catch (\Exception $e) { + $em->getConnection()->rollback(); + $em->close(); + echo "User not deleted.\n"; + throw $e; + } } function sendWarningEmail($user){