Skip to content

Commit

Permalink
Move up the recording of the active remote MySQL profile
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
troglodyne committed Jul 25, 2024
1 parent 5ef8705 commit 3c49620
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 5 additions & 3 deletions elevate-cpanel
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down
10 changes: 7 additions & 3 deletions lib/Elevate/Components/DatabaseUpgrade.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 {
Expand Down

0 comments on commit 3c49620

Please sign in to comment.