From 3c49620164d6424a0b5e8b144bbe653f095adc5a Mon Sep 17 00:00:00 2001 From: Andy Baugh Date: Thu, 25 Jul 2024 18:36:45 +0000 Subject: [PATCH] Move up the recording of the active remote MySQL profile case RE-34: Fixes an issue where it was not recorded when the `try` block actually succeeded. TODO: Fix test Changelog: Fix minor bug in original RE-34 fix where it would not always record the active profile. --- elevate-cpanel | 8 +++++--- lib/Elevate/Components/DatabaseUpgrade.pm | 10 +++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/elevate-cpanel b/elevate-cpanel index ff9bd6e6a..9256ffc6c 100755 --- a/elevate-cpanel +++ b/elevate-cpanel @@ -5505,6 +5505,11 @@ EOS my $profile_manager = Cpanel::MysqlUtils::RemoteMySQL::ProfileManager->new(); + File::Slurper::write_text( + MYSQL_PROFILE_FILE, + $profile_manager->get_active_profile('dont_die'), + ); + try { $profile_manager->validate_profile('localhost'); $self->_activate_localhost_profile($profile_manager); @@ -5526,9 +5531,6 @@ EOS sub _create_new_localhost_profile ( $self, $profile_manager ) { - my $active_profile = $profile_manager->get_active_profile('dont_die'); - File::Slurper::write_text( MYSQL_PROFILE_FILE, $active_profile ); - my $password = Cpanel::PasswdStrength::Generate::generate_password( 16, no_othersymbols => 1 ); try { diff --git a/lib/Elevate/Components/DatabaseUpgrade.pm b/lib/Elevate/Components/DatabaseUpgrade.pm index ff014b9c8..30de81f4e 100644 --- a/lib/Elevate/Components/DatabaseUpgrade.pm +++ b/lib/Elevate/Components/DatabaseUpgrade.pm @@ -82,6 +82,13 @@ sub _ensure_localhost_mysql_profile_is_active ( $self, $should_create_localhost_ my $profile_manager = Cpanel::MysqlUtils::RemoteMySQL::ProfileManager->new(); + # Immediately record the currently active profile, as othrewise you can + # miss it in the try/catch below. + File::Slurper::write_text( + MYSQL_PROFILE_FILE, + $profile_manager->get_active_profile('dont_die'), + ); + # Validate that the current “localhost” profile exists, and contains valid settings. try { $profile_manager->validate_profile('localhost'); @@ -105,9 +112,6 @@ sub _ensure_localhost_mysql_profile_is_active ( $self, $should_create_localhost_ sub _create_new_localhost_profile ( $self, $profile_manager ) { - my $active_profile = $profile_manager->get_active_profile('dont_die'); - File::Slurper::write_text( MYSQL_PROFILE_FILE, $active_profile ); - my $password = Cpanel::PasswdStrength::Generate::generate_password( 16, no_othersymbols => 1 ); try {