Skip to content

Commit

Permalink
Delete user function
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcon authored and gregcorbett committed May 27, 2022
1 parent a77ecc1 commit 437bc03
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions resources/RemoveInactiveUsersRunner.php
Expand Up @@ -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";
Expand All @@ -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){
Expand Down

0 comments on commit 437bc03

Please sign in to comment.