From 07eefca650a4ce6e2b74fa75974139588bbfffb5 Mon Sep 17 00:00:00 2001 From: Pinga <121483313+getpinga@users.noreply.github.com> Date: Fri, 26 Jul 2024 13:23:32 +0300 Subject: [PATCH] Added script to purge all contacts after migration to minimal data mode --- tests/purge-contacts.php | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/purge-contacts.php diff --git a/tests/purge-contacts.php b/tests/purge-contacts.php new file mode 100644 index 0000000..e93dcce --- /dev/null +++ b/tests/purge-contacts.php @@ -0,0 +1,65 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +} catch (PDOException $e) { + echo 'DB Connection failed: ' . $e->getMessage(); +} + +// Warning message +echo "Warning: This will delete all contacts in the registry. USE ONLY AFTER switch to minimal data mode completed. Are you sure you want to continue? (y/n): "; + +// Read user input from the terminal +$handle = fopen("php://stdin", "r"); +$line = fgets($handle); +if(trim($line) != 'y'){ + echo "Aborted.\n"; + exit; +} + +// Close the handle +fclose($handle); + +try { + $dbh->beginTransaction(); + + $dbh->prepare("UPDATE domain SET registrant = NULL")->execute(); + $dbh->prepare("UPDATE application SET registrant = NULL")->execute(); + $dbh->prepare("UPDATE domain_auto_approve_transfer SET registrant = NULL")->execute(); + + $dbh->prepare("DELETE FROM domain_contact_map")->execute(); + $dbh->prepare("DELETE FROM application_contact_map")->execute(); + $dbh->prepare("DELETE FROM contact_status")->execute(); + $dbh->prepare("DELETE FROM contact_postalInfo")->execute(); + $dbh->prepare("DELETE FROM contact_auto_approve_transfer")->execute(); + $dbh->prepare("DELETE FROM contact_authInfo")->execute(); + $dbh->prepare("DELETE FROM contact")->execute(); + + $dbh->commit(); + echo 'job finished successfully'.PHP_EOL; + +} catch (Exception $e) { + $dbh->rollBack(); + echo 'Database error: ' . $e->getMessage(); +} catch (PDOException $e) { + $dbh->rollBack(); + echo 'Database error: ' . $e->getMessage(); +} catch (Throwable $e) { + $dbh->rollBack(); + echo 'Error: ' . $e->getMessage(); +} \ No newline at end of file