From 20565df739bd4b59f342b856def8e1544828f16a Mon Sep 17 00:00:00 2001 From: Pinga <121483313+getpinga@users.noreply.github.com> Date: Tue, 5 Mar 2024 15:56:52 +0200 Subject: [PATCH] Small automation script improvements --- automation/auto-approve-transfer.php | 2 +- automation/auto-clean-unused-contact-and-host.php | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/automation/auto-approve-transfer.php b/automation/auto-approve-transfer.php index 54280d8..792a7a5 100644 --- a/automation/auto-approve-transfer.php +++ b/automation/auto-approve-transfer.php @@ -222,7 +222,7 @@ try { $stmt_contact = null; $dbh->commit(); $log->info('job finished successfully.'); -} catch (PDOException $e) { +} catch (Exception $e) { $dbh->rollBack(); $log->error('Database error: ' . $e->getMessage()); } catch (PDOException $e) { diff --git a/automation/auto-clean-unused-contact-and-host.php b/automation/auto-clean-unused-contact-and-host.php index 49456f6..0df8132 100644 --- a/automation/auto-clean-unused-contact-and-host.php +++ b/automation/auto-clean-unused-contact-and-host.php @@ -17,6 +17,8 @@ try { } try { + $dbh->beginTransaction(); + // Prepare and execute the SQL statement to select unused hosts $stmt = $dbh->prepare("SELECT h.id, h.name FROM host AS h LEFT JOIN domain_host_map AS m ON h.id = m.host_id @@ -56,11 +58,17 @@ try { $dbh->prepare("DELETE FROM contact_authInfo WHERE contact_id IN ($placeholders)")->execute($contact_ids); $dbh->prepare("DELETE FROM contact WHERE id IN ($placeholders)")->execute($contact_ids); } - + + $dbh->commit(); $log->info('job finished successfully.'); +} catch (Exception $e) { + $dbh->rollBack(); + $log->error('Database error: ' . $e->getMessage()); } catch (PDOException $e) { + $dbh->rollBack(); $log->error('Database error: ' . $e->getMessage()); } catch (Throwable $e) { + $dbh->rollBack(); $log->error('Error: ' . $e->getMessage()); } \ No newline at end of file