View | Details | Raw Unified | Return to bug 25078
Collapse All | Expand All

(-)a/C4/Installer.pm (-27 / +17 lines)
Lines 724-733 sub update { Link Here
724
724
725
        my $error;
725
        my $error;
726
726
727
        my $out = '';
728
        open my $outfh, '>', \$out;
727
        try {
729
        try {
728
            $schema->txn_do(
730
            $schema->txn_do(
729
                sub {
731
                sub {
730
                    $db_rev->{up}->();
732
                    $db_rev->{up}->({ dbh => $schema->storage->dbh, out => $outfh });
731
                }
733
                }
732
            );
734
            );
733
        } catch {
735
        } catch {
Lines 736-748 sub update { Link Here
736
738
737
        my $db_entry = {
739
        my $db_entry = {
738
            bug_number  => $db_rev->{bug_number},
740
            bug_number  => $db_rev->{bug_number},
739
            description => ( ref $db_rev->{description} eq 'CODE' )
741
            description => $db_rev->{description},
740
              ? $db_rev->{description}->()
741
              : $db_rev->{description},
742
            version     => version_from_file($file),
742
            version     => version_from_file($file),
743
            time        => POSIX::strftime( "%H:%M:%S", localtime ),
743
            time        => POSIX::strftime( "%H:%M:%S", localtime ),
744
        };
744
        };
745
        $db_entry->{output} = output_version( { %$db_entry, done => !$error } );
745
        $db_entry->{output} = output_version( { %$db_entry, done => !$error, report => $out } );
746
746
747
        if ( $error ) {
747
        if ( $error ) {
748
            push @errors, { %$db_entry, error => $error };
748
            push @errors, { %$db_entry, error => $error };
Lines 759-765 sub update { Link Here
759
sub output_version {
759
sub output_version {
760
    my ( $db_entry ) = @_;
760
    my ( $db_entry ) = @_;
761
761
762
    my $descriptions = $db_entry->{description};
762
    my $description = $db_entry->{description};
763
    my $report = $db_entry->{report};
763
    my $DBversion = $db_entry->{version};
764
    my $DBversion = $db_entry->{version};
764
    my $bug_number = $db_entry->{bug_number};
765
    my $bug_number = $db_entry->{bug_number};
765
    my $time = $db_entry->{time};
766
    my $time = $db_entry->{time};
Lines 769-799 sub output_version { Link Here
769
                    : " failed"
770
                    : " failed"
770
                : ""; # For old versions, we don't know if we succeed or failed
771
                : ""; # For old versions, we don't know if we succeed or failed
771
772
772
    unless ( ref($descriptions) ) {
773
    my @output;
773
        $descriptions = [ $descriptions ];
774
775
    if ($bug_number) {
776
        push @output, sprintf('Upgrade to %s %s [%s]: Bug %5s - %s', $DBversion, $done, $time, $bug_number, $description);
777
    } else {
778
        push @output, sprintf('Upgrade to %s %s [%s]: %s', $DBversion, $done, $time, $description);
774
    }
779
    }
775
780
776
    my $first = 1;
781
    if ($report) {
777
    my @output;
782
        foreach my $line (split /\n/, $report) {
778
    for my $description ( @$descriptions ) {
783
            push @output, sprintf "\t\t\t\t\t\t   - %s", $line;
779
        if ( @$descriptions > 1 ) {
780
            if ( $first ) {
781
                unless ( $bug_number ) {
782
                    push @output, sprintf "Upgrade to %s%s [%s]:", $DBversion, $done, $time;
783
                } else {
784
                    push @output, sprintf "Upgrade to %s%s [%s]: Bug %5s", $DBversion, $done, $time, $bug_number;
785
                }
786
            }
787
            push @output, sprintf "\t\t\t\t\t\t   - %s", $description;
788
        } else {
789
            unless ( $bug_number ) {
790
                push @output, sprintf "Upgrade to %s%s [%s]: %s", $DBversion, $done, $time, $description;
791
            } else {
792
                push @output, sprintf "Upgrade to %s%s [%s]: Bug %5s - %s", $DBversion, $done, $time, $bug_number, $description;
793
            }
794
        }
784
        }
795
        $first = 0;
796
    }
785
    }
786
797
    return \@output;
787
    return \@output;
798
}
788
}
799
789
(-)a/installer/data/mysql/db_revs/210600000.pl (-2 / +10 lines)
Lines 3-8 use utf8; Link Here
3
3
4
{
4
{
5
    bug_number => undef,
5
    bug_number => undef,
6
    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."],
6
    description => 'Increase DBRev for 21.06',
7
    up => sub {},
7
    up => sub {
8
        my ($args) = @_;
9
        my ($dbh, $out) = @$args{qw(dbh out)};
10
11
        say $out '🎵 Run, rabbit run. 🎶';
12
        say $out 'Dig that hole, forget the sun,';
13
        say $out 'And when at last the work is done';
14
        say $out "Don't sit down it's time to dig another one.";
15
    },
8
}
16
}
(-)a/installer/data/mysql/db_revs/210600081.pl (-1 / +1 lines)
Lines 2-7 use Modern::Perl; Link Here
2
2
3
{
3
{
4
    bug_number => 42322,
4
    bug_number => 42322,
5
    description => "Single line description",
5
    description => "Single line description, no report",
6
    up => sub {},
6
    up => sub {},
7
}
7
}
(-)a/installer/data/mysql/db_revs/210600082.pl (-4 / +6 lines)
Lines 1-11 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
my $nb_patrons;
4
{
3
{
5
    bug_number => 42422,
4
    bug_number => 42422,
6
    description => sub { ["Testing number of patrons: $nb_patrons"] },
5
    description => 'Testing number of patrons',
7
    up => sub {
6
    up => sub {
8
        my $dbh = C4::Context->dbh;
7
        my ($args) = @_;
9
        $nb_patrons = $dbh->selectrow_array(q{SELECT COUNT(*) FROM borrowers;});
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
10
        my $nb_patrons = $dbh->selectrow_array(q{SELECT COUNT(*) FROM borrowers;});
11
        say $out "Number of patrons: $nb_patrons";
10
    },
12
    },
11
}
13
}
(-)a/installer/data/mysql/db_revs/210600083.pl (-2 / +9 lines)
Lines 2-7 use Modern::Perl; Link Here
2
2
3
{
3
{
4
    bug_number => 42323,
4
    bug_number => 42323,
5
    description => [qw(Multi lines description)],
5
    description => 'Multi lines report',
6
    up => sub {},
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
10
        say $out 'Multi';
11
        say $out 'lines';
12
        say $out 'report';
13
    },
7
}
14
}
(-)a/installer/data/mysql/db_revs/210600090.pl (-2 / +3 lines)
Lines 2-10 use Modern::Perl; Link Here
2
2
3
{
3
{
4
    bug_number => 42420,
4
    bug_number => 42420,
5
    description => ["Testing failure"],
5
    description => 'Testing failure',
6
    up => sub {
6
    up => sub {
7
        my $dbh = C4::Context->dbh;
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
8
        $dbh->do(q{ALTER TABLE Foo});
9
        $dbh->do(q{ALTER TABLE Foo});
9
    },
10
    },
10
}
11
}
(-)a/installer/data/mysql/db_revs/210600091.pl (-1 / +1 lines)
Lines 2-8 use Modern::Perl; Link Here
2
2
3
{
3
{
4
    bug_number => 42421,
4
    bug_number => 42421,
5
    description => ["don't compile"],
5
    description => "don't compile",
6
    up => sub {
6
    up => sub {
7
        my $dbh = C4::NoContext->dbh; # NoContext does not exist
7
        my $dbh = C4::NoContext->dbh; # NoContext does not exist
8
        $dbh->do(q{ALTER TABLE Foo});
8
        $dbh->do(q{ALTER TABLE Foo});
(-)a/installer/data/mysql/db_revs/210600092.pl (-2 / +9 lines)
Lines 2-10 use Modern::Perl; Link Here
2
2
3
{
3
{
4
    bug_number => 42423,
4
    bug_number => 42423,
5
    description => ["Testing", "multi lines", " failure"],
5
    description => 'Testing multi lines failure',
6
    up => sub {
6
    up => sub {
7
        my $dbh = C4::Context->dbh;
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
10
        say $out 'Testing';
11
        say $out 'multi lines';
12
8
        $dbh->do(q{ALTER TABLE Foo});
13
        $dbh->do(q{ALTER TABLE Foo});
14
15
        say $out 'failure'; # this won't be printed
9
    },
16
    },
10
}
17
}
(-)a/installer/data/mysql/db_revs/210600094.pl (-2 / +3 lines)
Lines 2-10 use Modern::Perl; Link Here
2
2
3
{
3
{
4
    bug_number => 42424,
4
    bug_number => 42424,
5
    description => ["Testing transaction"],
5
    description => 'Testing transaction',
6
    up => sub {
6
    up => sub {
7
        my $dbh = C4::Context->dbh;
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
8
        $dbh->do(q{INSERT INTO cities(city_name) VALUES ('new_city');});
9
        $dbh->do(q{INSERT INTO cities(city_name) VALUES ('new_city');});
9
        $dbh->do(q{INSERT INTO cities(city_XX) VALUES ('new_XX');}); # This will fail
10
        $dbh->do(q{INSERT INTO cities(city_XX) VALUES ('new_XX');}); # This will fail
10
    },
11
    },
(-)a/installer/data/mysql/db_revs/skeleton.pl (-4 / +4 lines)
Lines 3-13 use Modern::Perl; Link Here
3
{
3
{
4
    bug_number => "BUG_NUMBER",
4
    bug_number => "BUG_NUMBER",
5
    description => "A single line description",
5
    description => "A single line description",
6
    # description => ["Multi", "lines", "description"],
7
    # description => sub { return ["Your dynamic description"] },
8
    up => sub {
6
    up => sub {
9
        my $dbh = C4::Context->dbh;
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
10
        # Do you stuffs here
9
        # Do you stuffs here
11
        $dbh->do(q{});
10
        $dbh->do(q{});
11
        # Print useful stuff here
12
        say $out "Update is going well so far";
12
    },
13
    },
13
}
14
}
14
- 

Return to bug 25078