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