From ef9aab0e597fbd81231a34f1fa900754e231cc90 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Mon, 14 Jun 2021 18:44:06 +0200 Subject: [PATCH] Bug 25078: Separate update "report" from its description Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- C4/Installer.pm | 44 +++++++++-------------- installer/data/mysql/db_revs/210600000.pl | 12 +++++-- installer/data/mysql/db_revs/skeleton.pl | 7 ++-- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/C4/Installer.pm b/C4/Installer.pm index 04e7e9f5d1..203d175c13 100644 --- a/C4/Installer.pm +++ b/C4/Installer.pm @@ -731,10 +731,12 @@ sub update { my $error; + my $out = ''; + open my $outfh, '>', \$out; try { $schema->txn_do( sub { - $db_rev->{up}->(); + $db_rev->{up}->({ dbh => $schema->storage->dbh, out => $outfh }); } ); } catch { @@ -743,13 +745,11 @@ sub update { my $db_entry = { bug_number => $db_rev->{bug_number}, - description => ( ref $db_rev->{description} eq 'CODE' ) - ? $db_rev->{description}->() - : $db_rev->{description}, + description => $db_rev->{description}, version => version_from_file($file), time => POSIX::strftime( "%H:%M:%S", localtime ), }; - $db_entry->{output} = output_version( { %$db_entry, done => !$error } ); + $db_entry->{output} = output_version( { %$db_entry, done => !$error, report => $out } ); if ( $error ) { push @errors, { %$db_entry, error => $error }; @@ -766,7 +766,8 @@ sub update { sub output_version { my ( $db_entry ) = @_; - my $descriptions = $db_entry->{description}; + my $description = $db_entry->{description}; + my $report = $db_entry->{report}; my $DBversion = $db_entry->{version}; my $bug_number = $db_entry->{bug_number}; my $time = $db_entry->{time}; @@ -776,31 +777,20 @@ sub output_version { : " failed" : ""; # For old versions, we don't know if we succeed or failed - unless ( ref($descriptions) ) { - $descriptions = [ $descriptions ]; + my @output; + + if ($bug_number) { + push @output, sprintf('Upgrade to %s %s [%s]: Bug %5s - %s', $DBversion, $done, $time, $bug_number, $description); + } else { + push @output, sprintf('Upgrade to %s %s [%s]: %s', $DBversion, $done, $time, $description); } - my $first = 1; - my @output; - for my $description ( @$descriptions ) { - if ( @$descriptions > 1 ) { - if ( $first ) { - unless ( $bug_number ) { - push @output, sprintf "Upgrade to %s%s [%s]:", $DBversion, $done, $time; - } else { - push @output, sprintf "Upgrade to %s%s [%s]: Bug %5s", $DBversion, $done, $time, $bug_number; - } - } - push @output, sprintf "\t\t\t\t\t\t - %s", $description; - } else { - unless ( $bug_number ) { - push @output, sprintf "Upgrade to %s%s [%s]: %s", $DBversion, $done, $time, $description; - } else { - push @output, sprintf "Upgrade to %s%s [%s]: Bug %5s - %s", $DBversion, $done, $time, $bug_number, $description; - } + if ($report) { + foreach my $line (split /\n/, $report) { + push @output, sprintf "\t\t\t\t\t\t - %s", $line; } - $first = 0; } + return \@output; } diff --git a/installer/data/mysql/db_revs/210600000.pl b/installer/data/mysql/db_revs/210600000.pl index fecc9f081f..2e120d4193 100644 --- a/installer/data/mysql/db_revs/210600000.pl +++ b/installer/data/mysql/db_revs/210600000.pl @@ -3,6 +3,14 @@ use utf8; { bug_number => undef, - description => ["🎵 Run, rabbit run. 🎶", "Dig that hole, forget the sun,", "And when at last the work is done", "Don't sit down it's time to dig another one."], - up => sub {}, + description => 'Increase DBRev for 21.06', + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + + say $out '🎵 Run, rabbit run. 🎶'; + say $out 'Dig that hole, forget the sun,'; + say $out 'And when at last the work is done'; + say $out "Don't sit down it's time to dig another one."; + }, } diff --git a/installer/data/mysql/db_revs/skeleton.pl b/installer/data/mysql/db_revs/skeleton.pl index 76b4991ad2..082f47e024 100644 --- a/installer/data/mysql/db_revs/skeleton.pl +++ b/installer/data/mysql/db_revs/skeleton.pl @@ -3,11 +3,12 @@ use Modern::Perl; { bug_number => "BUG_NUMBER", description => "A single line description", - # description => ["Multi", "lines", "description"], - # description => sub { return ["Your dynamic description"] }, up => sub { - my $dbh = C4::Context->dbh; + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; # Do you stuffs here $dbh->do(q{}); + # Print useful stuff here + say $out "Update is going well so far"; }, } -- 2.39.5