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

(-)a/C4/Installer.pm (-27 / +17 lines)
Lines 723-732 sub update { Link Here
723
723
724
        my $error;
724
        my $error;
725
725
726
        my $out = '';
727
        open my $outfh, '>', \$out;
726
        try {
728
        try {
727
            $schema->txn_do(
729
            $schema->txn_do(
728
                sub {
730
                sub {
729
                    $db_rev->{up}->();
731
                    $db_rev->{up}->({ dbh => $schema->storage->dbh, out => $outfh });
730
                }
732
                }
731
            );
733
            );
732
        } catch {
734
        } catch {
Lines 735-747 sub update { Link Here
735
737
736
        my $db_entry = {
738
        my $db_entry = {
737
            bug_number  => $db_rev->{bug_number},
739
            bug_number  => $db_rev->{bug_number},
738
            description => ( ref $db_rev->{description} eq 'CODE' )
740
            description => $db_rev->{description},
739
              ? $db_rev->{description}->()
740
              : $db_rev->{description},
741
            version     => version_from_file($file),
741
            version     => version_from_file($file),
742
            time        => POSIX::strftime( "%H:%M:%S", localtime ),
742
            time        => POSIX::strftime( "%H:%M:%S", localtime ),
743
        };
743
        };
744
        $db_entry->{output} = output_version( { %$db_entry, done => !$error } );
744
        $db_entry->{output} = output_version( { %$db_entry, done => !$error, report => $out } );
745
745
746
        if ( $error ) {
746
        if ( $error ) {
747
            push @errors, { %$db_entry, error => $error };
747
            push @errors, { %$db_entry, error => $error };
Lines 758-764 sub update { Link Here
758
sub output_version {
758
sub output_version {
759
    my ( $db_entry ) = @_;
759
    my ( $db_entry ) = @_;
760
760
761
    my $descriptions = $db_entry->{description};
761
    my $description = $db_entry->{description};
762
    my $report = $db_entry->{report};
762
    my $DBversion = $db_entry->{version};
763
    my $DBversion = $db_entry->{version};
763
    my $bug_number = $db_entry->{bug_number};
764
    my $bug_number = $db_entry->{bug_number};
764
    my $time = $db_entry->{time};
765
    my $time = $db_entry->{time};
Lines 768-798 sub output_version { Link Here
768
                    : " failed"
769
                    : " failed"
769
                : ""; # For old versions, we don't know if we succeed or failed
770
                : ""; # For old versions, we don't know if we succeed or failed
770
771
771
    unless ( ref($descriptions) ) {
772
    my @output;
772
        $descriptions = [ $descriptions ];
773
774
    if ($bug_number) {
775
        push @output, sprintf('Upgrade to %s %s [%s]: Bug %5s - %s', $DBversion, $done, $time, $bug_number, $description);
776
    } else {
777
        push @output, sprintf('Upgrade to %s %s [%s]: %s', $DBversion, $done, $time, $description);
773
    }
778
    }
774
779
775
    my $first = 1;
780
    if ($report) {
776
    my @output;
781
        foreach my $line (split /\n/, $report) {
777
    for my $description ( @$descriptions ) {
782
            push @output, sprintf "\t\t\t\t\t\t   - %s", $line;
778
        if ( @$descriptions > 1 ) {
779
            if ( $first ) {
780
                unless ( $bug_number ) {
781
                    push @output, sprintf "Upgrade to %s%s [%s]:", $DBversion, $done, $time;
782
                } else {
783
                    push @output, sprintf "Upgrade to %s%s [%s]: Bug %5s", $DBversion, $done, $time, $bug_number;
784
                }
785
            }
786
            push @output, sprintf "\t\t\t\t\t\t   - %s", $description;
787
        } else {
788
            unless ( $bug_number ) {
789
                push @output, sprintf "Upgrade to %s%s [%s]: %s", $DBversion, $done, $time, $description;
790
            } else {
791
                push @output, sprintf "Upgrade to %s%s [%s]: Bug %5s - %s", $DBversion, $done, $time, $bug_number, $description;
792
            }
793
        }
783
        }
794
        $first = 0;
795
    }
784
    }
785
796
    return \@output;
786
    return \@output;
797
}
787
}
798
788
(-)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