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

(-)a/C4/Auth.pm (-28 / +7 lines)
Lines 31-36 use C4::Context; Link Here
31
use C4::Templates;    # to get the template
31
use C4::Templates;    # to get the template
32
use C4::Languages;
32
use C4::Languages;
33
use C4::Search::History;
33
use C4::Search::History;
34
use C4::Installer;
34
use Koha;
35
use Koha;
35
use Koha::Caches;
36
use Koha::Caches;
36
use Koha::AuthUtils qw(get_script_name hash_password);
37
use Koha::AuthUtils qw(get_script_name hash_password);
Lines 48-53 use Encode qw( encode is_utf8); Link Here
48
use C4::Auth_with_shibboleth;
49
use C4::Auth_with_shibboleth;
49
use Net::CIDR;
50
use Net::CIDR;
50
use C4::Log qw/logaction/;
51
use C4::Log qw/logaction/;
52
use Koha::Migrations;
51
53
52
# use utf8;
54
# use utf8;
53
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout);
55
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout);
Lines 597-603 sub get_template_and_user { Link Here
597
            OPACFinesTab                          => C4::Context->preference("OPACFinesTab"),
599
            OPACFinesTab                          => C4::Context->preference("OPACFinesTab"),
598
            OpacTopissue                          => C4::Context->preference("OpacTopissue"),
600
            OpacTopissue                          => C4::Context->preference("OpacTopissue"),
599
            RequestOnOpac                         => C4::Context->preference("RequestOnOpac"),
601
            RequestOnOpac                         => C4::Context->preference("RequestOnOpac"),
600
            'Version'                             => C4::Context->preference('Version'),
601
            hidelostitems                         => C4::Context->preference("hidelostitems"),
602
            hidelostitems                         => C4::Context->preference("hidelostitems"),
602
            mylibraryfirst                        => ( C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv ) ? C4::Context->userenv->{'branch'} : '',
603
            mylibraryfirst                        => ( C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv ) ? C4::Context->userenv->{'branch'} : '',
603
            opacbookbag                           => "" . C4::Context->preference("opacbookbag"),
604
            opacbookbag                           => "" . C4::Context->preference("opacbookbag"),
Lines 733-739 has authenticated. Link Here
733
sub _version_check {
734
sub _version_check {
734
    my $type  = shift;
735
    my $type  = shift;
735
    my $query = shift;
736
    my $query = shift;
736
    my $version;
737
737
738
    # If version syspref is unavailable, it means Koha is being installed,
738
    # If version syspref is unavailable, it means Koha is being installed,
739
    # and so we must redirect to OPAC maintenance page or to the WebInstaller
739
    # and so we must redirect to OPAC maintenance page or to the WebInstaller
Lines 743-749 sub _version_check { Link Here
743
        print $query->redirect("/cgi-bin/koha/maintenance.pl");
743
        print $query->redirect("/cgi-bin/koha/maintenance.pl");
744
        safe_exit;
744
        safe_exit;
745
    }
745
    }
746
    unless ( $version = C4::Context->preference('Version') ) {    # assignment, not comparison
746
    unless ( C4::Installer::TableExists('systempreferences') ) {
747
        if ( $type ne 'opac' ) {
747
        if ( $type ne 'opac' ) {
748
            warn "Install required, redirecting to Installer";
748
            warn "Install required, redirecting to Installer";
749
            print $query->redirect("/cgi-bin/koha/installer/install.pl");
749
            print $query->redirect("/cgi-bin/koha/installer/install.pl");
Lines 758-770 sub _version_check { Link Here
758
    # there is no DB version, it's a fresh install,
758
    # there is no DB version, it's a fresh install,
759
    # go to web installer
759
    # go to web installer
760
    # there is a DB version, compare it to the code version
760
    # there is a DB version, compare it to the code version
761
    my $kohaversion = Koha::version();
761
    if (Koha::Migrations->pending_migrations > 0) {
762
762
        my $warning = "Database update needed, redirecting to %s";
763
    # remove the 3 last . to have a Perl number
764
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
765
    $debug and print STDERR "kohaversion : $kohaversion\n";
766
    if ( $version < $kohaversion ) {
767
        my $warning = "Database update needed, redirecting to %s. Database is $version and Koha is $kohaversion";
768
        if ( $type ne 'opac' ) {
763
        if ( $type ne 'opac' ) {
769
            warn sprintf( $warning, 'Installer' );
764
            warn sprintf( $warning, 'Installer' );
770
            print $query->redirect("/cgi-bin/koha/installer/install.pl?step=1&op=updatestructure");
765
            print $query->redirect("/cgi-bin/koha/installer/install.pl?step=1&op=updatestructure");
Lines 1489-1503 sub check_api_auth { Link Here
1489
    my $dbh     = C4::Context->dbh;
1484
    my $dbh     = C4::Context->dbh;
1490
    my $timeout = _timeout_syspref();
1485
    my $timeout = _timeout_syspref();
1491
1486
1492
    unless ( C4::Context->preference('Version') ) {
1487
    if ( Koha::Migrations->pending_migrations > 0 ) {
1493
1494
        # database has not been installed yet
1495
        return ( "maintenance", undef, undef );
1496
    }
1497
    my $kohaversion = Koha::version();
1498
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
1499
    if ( C4::Context->preference('Version') < $kohaversion ) {
1500
1501
        # database in need of version update; assume that
1488
        # database in need of version update; assume that
1502
        # no API should be called while databsae is in
1489
        # no API should be called while databsae is in
1503
        # this condition.
1490
        # this condition.
Lines 1744-1758 sub check_cookie_auth { Link Here
1744
    my $dbh     = C4::Context->dbh;
1731
    my $dbh     = C4::Context->dbh;
1745
    my $timeout = _timeout_syspref();
1732
    my $timeout = _timeout_syspref();
1746
1733
1747
    unless ( C4::Context->preference('Version') ) {
1734
    if ( Koha::Migrations->pending_migrations > 0 ) {
1748
1749
        # database has not been installed yet
1750
        return ( "maintenance", undef );
1751
    }
1752
    my $kohaversion = Koha::version();
1753
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
1754
    if ( C4::Context->preference('Version') < $kohaversion ) {
1755
1756
        # database in need of version update; assume that
1735
        # database in need of version update; assume that
1757
        # no API should be called while databsae is in
1736
        # no API should be called while databsae is in
1758
        # this condition.
1737
        # this condition.
(-)a/C4/Context.pm (-3 / +13 lines)
Lines 55-61 BEGIN { Link Here
55
						<table>
55
						<table>
56
						<tr><th>Apache</th><td>  $versions{apacheVersion}</td></tr>
56
						<tr><th>Apache</th><td>  $versions{apacheVersion}</td></tr>
57
						<tr><th>Koha</th><td>    $versions{kohaVersion}</td></tr>
57
						<tr><th>Koha</th><td>    $versions{kohaVersion}</td></tr>
58
						<tr><th>Koha DB</th><td> $versions{kohaDbVersion}</td></tr>
59
						<tr><th>MySQL</th><td>   $versions{mysqlVersion}</td></tr>
58
						<tr><th>MySQL</th><td>   $versions{mysqlVersion}</td></tr>
60
						<tr><th>OS</th><td>      $versions{osVersion}</td></tr>
59
						<tr><th>OS</th><td>      $versions{osVersion}</td></tr>
61
						<tr><th>Perl</th><td>    $versions{perlVersion}</td></tr>
60
						<tr><th>Perl</th><td>    $versions{perlVersion}</td></tr>
Lines 410-415 sub preference { Link Here
410
409
411
    $var = lc $var;
410
    $var = lc $var;
412
411
412
    if ($var eq 'version') {
413
        my $version = Koha::version();
414
        $version =~ s/^(\d+)\.(\d+)\.(\d+)$/$1.$2$3/;
415
        return $version;
416
    }
417
413
    if ($use_syspref_cache) {
418
    if ($use_syspref_cache) {
414
        $syspref_cache = Koha::Caches->get_instance('syspref') unless $syspref_cache;
419
        $syspref_cache = Koha::Caches->get_instance('syspref') unless $syspref_cache;
415
        my $cached_var = $syspref_cache->get_from_cache("syspref_$var");
420
        my $cached_var = $syspref_cache->get_from_cache("syspref_$var");
Lines 907-913 Gets various version info, for core Koha packages, Currently called from carp ha Link Here
907
sub get_versions {
912
sub get_versions {
908
    my %versions;
913
    my %versions;
909
    $versions{kohaVersion}  = Koha::version();
914
    $versions{kohaVersion}  = Koha::version();
910
    $versions{kohaDbVersion} = C4::Context->preference('version');
911
    $versions{osVersion} = join(" ", POSIX::uname());
915
    $versions{osVersion} = join(" ", POSIX::uname());
912
    $versions{perlVersion} = $];
916
    $versions{perlVersion} = $];
913
    {
917
    {
Lines 1103-1109 This method returns a boolean representing the install status of the Koha instan Link Here
1103
1107
1104
sub needs_install {
1108
sub needs_install {
1105
    my ($self) = @_;
1109
    my ($self) = @_;
1106
    return ($self->preference('Version')) ? 0 : 1;
1110
    eval {
1111
        my $dbh = $self->dbh;
1112
        local $dbh->{PrintError} = 0;
1113
        local $dbh->{RaiseError} = 1;
1114
        $dbh->do('SELECT * FROM systempreferences WHERE 1 = 0');
1115
    };
1116
    return $@ ? 1 : 0;
1107
}
1117
}
1108
1118
1109
__END__
1119
__END__
(-)a/C4/Installer.pm (-28 lines)
Lines 46-52 C4::Installer Link Here
46
 my $list;
46
 my $list;
47
 #fill $list with list of sql files
47
 #fill $list with list of sql files
48
 my ($fwk_language, $error_list) = $installer->load_sql_in_order($all_languages, @$list);
48
 my ($fwk_language, $error_list) = $installer->load_sql_in_order($all_languages, @$list);
49
 $installer->set_version_syspref();
50
 $installer->set_marcflavour_syspref('MARC21');
49
 $installer->set_marcflavour_syspref('MARC21');
51
50
52
=head1 DESCRIPTION
51
=head1 DESCRIPTION
Lines 443-475 sub set_marcflavour_syspref { Link Here
443
    $request->execute;
442
    $request->execute;
444
}
443
}
445
444
446
=head2 set_version_syspref
447
448
  $installer->set_version_syspref();
449
450
Set or update the 'Version' system preference to the current
451
Koha software version.
452
453
=cut
454
455
sub set_version_syspref {
456
    my $self = shift;
457
458
    my $kohaversion = Koha::version();
459
    # remove the 3 last . to have a Perl number
460
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
461
    if (C4::Context->preference('Version')) {
462
        warn "UPDATE Version";
463
        my $finish=$self->{'dbh'}->prepare("UPDATE systempreferences SET value=? WHERE variable='Version'");
464
        $finish->execute($kohaversion);
465
    } else {
466
        warn "INSERT Version";
467
        my $finish=$self->{'dbh'}->prepare("INSERT into systempreferences (variable,value,explanation) values ('Version',?,'The Koha database version. WARNING: Do not change this value manually, it is maintained by the webinstaller')");
468
        $finish->execute($kohaversion);
469
    }
470
    C4::Context->clear_syspref_cache();
471
}
472
473
=head2 set_languages_syspref
445
=head2 set_languages_syspref
474
446
475
  $installer->set_languages_syspref();
447
  $installer->set_languages_syspref();
(-)a/Koha.pm (-8 / +5 lines)
Lines 22-35 use Modern::Perl; Link Here
22
22
23
use vars qw{ $VERSION };
23
use vars qw{ $VERSION };
24
24
25
#the kohaversion is divided in 4 parts :
25
#the kohaversion is divided in 3 parts :
26
# - #1 : the major number. 3 atm
26
# - #1 : the year of release
27
# - #2 : the functional release. 00 atm
27
# - #2 : the month of release (05 or 11 for stable releases, 06 or 12 for development branch)
28
# - #3 : the subnumber, moves only on a public release
28
# - #3 : the maintenance release number
29
# - #4 : the developer version. The 4th number is the database subversion.
29
$VERSION = "20.12.00";
30
#        used by developers when the database changes. updatedatabase take care of the changes itself
31
#        and is automatically called by Auth.pm when needed.
32
$VERSION = "20.12.00.021";
33
30
34
sub version {
31
sub version {
35
    return $VERSION;
32
    return $VERSION;
(-)a/Koha/Manual.pm (-1 / +2 lines)
Lines 3-11 package Koha::Manual; Link Here
3
use Modern::Perl;
3
use Modern::Perl;
4
4
5
use C4::Context;
5
use C4::Context;
6
use Koha;
6
7
7
sub _get_help_version {
8
sub _get_help_version {
8
    my $help_version = C4::Context->preference("Version");
9
    my $help_version = Koha::version();
9
    if ( $help_version =~ m|^(\d+)\.(\d{2}).*$| ) {
10
    if ( $help_version =~ m|^(\d+)\.(\d{2}).*$| ) {
10
        my $version = $1;
11
        my $version = $1;
11
        my $major = $2;
12
        my $major = $2;
(-)a/Koha/Migrations.pm (+44 lines)
Line 0 Link Here
1
package Koha::Migrations;
2
3
use Modern::Perl;
4
5
use C4::Context;
6
7
sub pending_migrations {
8
    my ($self) = @_;
9
10
    my $dbh = C4::Context->dbh;
11
12
    my @pending_migrations;
13
    my $executed_migrations = {};
14
    eval {
15
        $executed_migrations = $dbh->selectall_hashref('SELECT * FROM executed_migrations', 'name');
16
    };
17
18
    opendir(my $dh, $self->migrations_dir);
19
    foreach my $file (sort readdir $dh) {
20
        next if $file !~ /\.pl$/;
21
        next if (exists ($executed_migrations->{$file}));
22
        push @pending_migrations, $file;
23
    }
24
    closedir($dh);
25
26
    return @pending_migrations;
27
}
28
29
# Only needed for installer
30
sub mark_all_migrations_as_executed {
31
    my ($self) = @_;
32
33
    my $dbh = C4::Context->dbh;
34
35
    foreach my $migration ($self->pending_migrations) {
36
        $dbh->do('INSERT INTO executed_migrations (name) VALUES (?)', {}, $migration);
37
    }
38
}
39
40
sub migrations_dir {
41
    return C4::Context->config('intranetdir') . '/installer/data/mysql/migrations';
42
}
43
44
1;
(-)a/Koha/SharedContent.pm (-3 / +2 lines)
Lines 25-30 use LWP::UserAgent; Link Here
25
use Koha::Serials;
25
use Koha::Serials;
26
use Koha::Reports;
26
use Koha::Reports;
27
use C4::Context;
27
use C4::Context;
28
use Koha;
28
29
29
=head1 NAME
30
=head1 NAME
30
31
Lines 144-154 sub prepare_entity_data { Link Here
144
    $mana_email = C4::Context->preference('KohaAdminEmailAddress')
145
    $mana_email = C4::Context->preference('KohaAdminEmailAddress')
145
      if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
146
      if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
146
147
147
    my %versions = C4::Context::get_versions();
148
149
    my $mana_info = {
148
    my $mana_info = {
150
        language    => $lang,
149
        language    => $lang,
151
        kohaversion => $versions{'kohaVersion'},
150
        kohaversion => Koha::version(),
152
        exportemail => $mana_email
151
        exportemail => $mana_email
153
    };
152
    };
154
153
(-)a/Koha/Template/Plugin/Asset.pm (-1 / +1 lines)
Lines 142-148 sub url { Link Here
142
    );
142
    );
143
143
144
    my $version = Koha::version;
144
    my $version = Koha::version;
145
    $version =~ s/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/$1.$2$3$4/;
145
    $version =~ s/([0-9]+)\.([0-9]+)\.([0-9]+)/$1.$2${3}000/;
146
    foreach my $dir (@dirs) {
146
    foreach my $dir (@dirs) {
147
        my $abspath = File::Spec->catfile($root, $dir, $filename);
147
        my $abspath = File::Spec->catfile($root, $dir, $filename);
148
        if (-e $abspath) {
148
        if (-e $abspath) {
(-)a/Koha/Template/Plugin/Koha.pm (-2 / +1 lines)
Lines 57-70 sub Preference { Link Here
57
57
58
sub Version {
58
sub Version {
59
    my $version_string = Koha::version();
59
    my $version_string = Koha::version();
60
    my ( $major, $minor, $maintenance, $development ) = split( '\.', $version_string );
60
    my ( $major, $minor, $maintenance ) = split( '\.', $version_string );
61
61
62
    return {
62
    return {
63
        major       => $major,
63
        major       => $major,
64
        minor       => $minor,
64
        minor       => $minor,
65
        release     => $major . "." . $minor,
65
        release     => $major . "." . $minor,
66
        maintenance => $major . "." . $minor . "." . $maintenance,
66
        maintenance => $major . "." . $minor . "." . $maintenance,
67
        development => ( $development ne '000' ) ? $development : undef,
68
    };
67
    };
69
}
68
}
70
69
(-)a/installer/data/mysql/atomicupdate/skeleton.perl (-13 lines)
Lines 1-13 Link Here
1
$DBversion = 'XXX'; # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
    # you can use $dbh here like:
4
    # $dbh->do( "ALTER TABLE biblio ADD COLUMN badtaste int" );
5
6
    # or perform some test and warn
7
    # if( !column_exists( 'biblio', 'biblionumber' ) ) {
8
    #    warn "There is something wrong";
9
    # }
10
11
    # Always end with this (adjust the bug info)
12
    NewVersion( $DBversion, XXXXX, "Description");
13
}
(-)a/installer/data/mysql/kohastructure.sql (+11 lines)
Lines 2585-2590 CREATE TABLE `edifact_messages` ( Link Here
2585
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2585
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2586
/*!40101 SET character_set_client = @saved_cs_client */;
2586
/*!40101 SET character_set_client = @saved_cs_client */;
2587
2587
2588
--
2589
-- Structure for table executed_migrations
2590
--
2591
2592
DROP TABLE IF EXISTS `executed_migrations`;
2593
CREATE TABLE `executed_migrations` (
2594
    `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
2595
    `executed_at` timestamp NOT NULL DEFAULT current_timestamp(),
2596
    PRIMARY KEY (`name`)
2597
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2598
2588
--
2599
--
2589
-- Table structure for table `export_format`
2600
-- Table structure for table `export_format`
2590
--
2601
--
(-)a/installer/data/mysql/migrations/20201002135449-create-executed-migrations-table.pl (+15 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
{
4
    description => 'Create table executed_migrations',
5
    up => sub {
6
        my ($dbh) = @_;
7
        $dbh->do(q{
8
            CREATE TABLE IF NOT EXISTS `executed_migrations` (
9
                `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
10
                `executed_at` timestamp NOT NULL DEFAULT current_timestamp(),
11
                PRIMARY KEY (`name`)
12
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
13
        });
14
    },
15
}
(-)a/installer/data/mysql/updatedatabase.pl (-28 / +27 lines)
Lines 40-45 use C4::Installer; Link Here
40
use Koha::Database;
40
use Koha::Database;
41
use Koha;
41
use Koha;
42
use Koha::DateUtils;
42
use Koha::DateUtils;
43
use Koha::Migrations;
43
44
44
use MARC::Record;
45
use MARC::Record;
45
use MARC::File::XML ( BinaryEncoding => 'utf8' );
46
use MARC::File::XML ( BinaryEncoding => 'utf8' );
Lines 23634-23654 if( CheckVersion( $DBversion ) ) { Link Here
23634
    NewVersion( $DBversion, 22824, "Update syspref values for YesNo");
23635
    NewVersion( $DBversion, 22824, "Update syspref values for YesNo");
23635
}
23636
}
23636
23637
23637
# SEE bug 13068
23638
my $insert_migration_sth = $dbh->prepare('INSERT INTO executed_migrations (name) VALUES (?)');
23638
# if there is anything in the atomicupdate, read and execute it.
23639
23639
my $update_dir = C4::Context->config('intranetdir') . '/installer/data/mysql/atomicupdate/';
23640
my $migrations_dir = Koha::Migrations->migrations_dir;
23640
opendir( my $dirh, $update_dir );
23641
foreach my $file (Koha::Migrations->pending_migrations) {
23641
foreach my $file ( sort readdir $dirh ) {
23642
    my $migration = do $migrations_dir . '/' . $file;
23642
    next if $file !~ /\.(sql|perl)$/;  #skip other files
23643
    unless ($migration) {
23643
    next if $file eq 'skeleton.perl'; # skip the skeleton file
23644
        if ($@) {
23644
    print "DEV atomic update: $file\n";
23645
            warn "Could not compile $file: $@";
23645
    if ( $file =~ /\.sql$/ ) {
23646
        } elsif ($!) {
23646
        my $installer = C4::Installer->new();
23647
            warn "Could not do $file: $!";
23647
        my $rv = $installer->load_sql( $update_dir . $file ) ? 0 : 1;
23648
        } else {
23648
    } elsif ( $file =~ /\.perl$/ ) {
23649
            warn "Could not run $file";
23649
        my $code = read_file( $update_dir . $file );
23650
        }
23650
        eval $code; ## no critic (StringyEval)
23651
        next;
23651
        say "Atomic update generated errors: $@" if $@;
23652
    }
23653
23654
    eval {
23655
        $migration->{up}->($dbh);
23656
        $insert_migration_sth->execute($file);
23657
        say sprintf('Migration done: %s (%s)', $file, $migration->{description});
23658
    };
23659
    if ($@) {
23660
        die sprintf('Migration failed %s (%s): %s', $file, $migration->{description}, $@);
23652
    }
23661
    }
23653
}
23662
}
23654
23663
Lines 23691-23698 to a number, with just 1 . Link Here
23691
23700
23692
sub TransformToNum {
23701
sub TransformToNum {
23693
    my $version = shift;
23702
    my $version = shift;
23694
    # remove the 3 last . to have a Perl number
23703
    # keep only the first dot to have a Perl number
23695
    $version =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
23704
    my ($major, @rest) = split /\./, $version;
23705
    $version = join('.', $major, join('', @rest));
23696
    # three X's at the end indicate that you are testing patch with dbrev
23706
    # three X's at the end indicate that you are testing patch with dbrev
23697
    # change it into 999
23707
    # change it into 999
23698
    # prevents error on a < comparison between strings (should be: lt)
23708
    # prevents error on a < comparison between strings (should be: lt)
Lines 23707-23723 set the DBversion in the systempreferences Link Here
23707
=cut
23717
=cut
23708
23718
23709
sub SetVersion {
23719
sub SetVersion {
23710
    return if $_[0]=~ /XXX$/;
23711
      #you are testing a patch with a db revision; do not change version
23712
    my $kohaversion = TransformToNum($_[0]);
23713
    if (C4::Context->preference('Version')) {
23714
      my $finish=$dbh->prepare("UPDATE systempreferences SET value=? WHERE variable='Version'");
23715
      $finish->execute($kohaversion);
23716
    } else {
23717
      my $finish=$dbh->prepare("INSERT into systempreferences (variable,value,explanation) values ('Version',?,'The Koha database version. WARNING: Do not change this value manually, it is maintained by the webinstaller')");
23718
      $finish->execute($kohaversion);
23719
    }
23720
    C4::Context::clear_syspref_cache(); # invalidate cached preferences
23721
}
23720
}
23722
23721
23723
sub NewVersion {
23722
sub NewVersion {
(-)a/installer/install.pl (-25 / +12 lines)
Lines 32-37 use C4::Installer; Link Here
32
use C4::Installer::PerlModules;
32
use C4::Installer::PerlModules;
33
33
34
use Koha;
34
use Koha;
35
use Koha::Migrations;
35
36
36
my $query = CGI->new;
37
my $query = CGI->new;
37
my $step  = $query->param('step');
38
my $step  = $query->param('step');
Lines 228-234 elsif ( $step && $step == 3 ) { Link Here
228
        exit;
229
        exit;
229
    }
230
    }
230
    elsif ( $op && $op eq 'finish' ) {
231
    elsif ( $op && $op eq 'finish' ) {
231
        $installer->set_version_syspref();
232
        Koha::Migrations->mark_all_migrations_as_executed();
232
233
233
        my $langchoice = $query->param('fwklanguage');
234
        my $langchoice = $query->param('fwklanguage');
234
        $langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice);
235
        $langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice);
Lines 384-394 elsif ( $step && $step == 3 ) { Link Here
384
385
385
        my $now         = POSIX::strftime( "%Y-%m-%dT%H:%M:%S", localtime() );
386
        my $now         = POSIX::strftime( "%Y-%m-%dT%H:%M:%S", localtime() );
386
        my $logdir      = C4::Context->config('logdir');
387
        my $logdir      = C4::Context->config('logdir');
387
        my $dbversion   = C4::Context->preference('Version');
388
        my $kohaversion = Koha::version;
388
        my $kohaversion = Koha::version;
389
        $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
389
        $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
390
390
391
        my $filename_suffix = join '_', $now, $dbversion, $kohaversion;
391
        my $filename_suffix = join '_', $now, $kohaversion;
392
        my ( $logfilepath, $logfilepath_errors ) = (
392
        my ( $logfilepath, $logfilepath_errors ) = (
393
            chk_log( $logdir, "updatedatabase_$filename_suffix" ),
393
            chk_log( $logdir, "updatedatabase_$filename_suffix" ),
394
            chk_log( $logdir, "updatedatabase-error_$filename_suffix" )
394
            chk_log( $logdir, "updatedatabase-error_$filename_suffix" )
Lines 467-485 elsif ( $step && $step == 3 ) { Link Here
467
           # we have tables, propose to select files to upload or updatedatabase
467
           # we have tables, propose to select files to upload or updatedatabase
468
           #
468
           #
469
            $template->param( "count" => $count, "default" => 1 );
469
            $template->param( "count" => $count, "default" => 1 );
470
     #
470
471
     # 1st part of step 3 : check if there is a databaseversion systempreference
471
            # 1st part of step 3 : check if we need to install the database
472
     # if there is, then we just need to upgrade
472
            # if not, then we just need to upgrade
473
     # if there is none, then we need to install the database
473
            unless ( C4::Context->needs_install() ) {
474
     #
475
            if ( C4::Context->preference('Version') ) {
476
                my $dbversion = C4::Context->preference('Version');
477
                $dbversion =~ /(.*)\.(..)(..)(...)/;
478
                $dbversion = "$1.$2.$3.$4";
479
                $template->param(
474
                $template->param(
480
                    "upgrading"   => 1,
475
                    "upgrading"   => 1,
481
                    "dbversion"   => $dbversion,
482
                    "kohaversion" => Koha::version(),
476
                    "kohaversion" => Koha::version(),
477
                    "pending_migrations" => [ Koha::Migrations->pending_migrations ],
483
                );
478
                );
484
            }
479
            }
485
        }
480
        }
Lines 491-508 else { Link Here
491
    # using opendir + language Hash
486
    # using opendir + language Hash
492
    my $languages_loop = getTranslatedLanguages('intranet');
487
    my $languages_loop = getTranslatedLanguages('intranet');
493
    $template->param( installer_languages_loop => $languages_loop );
488
    $template->param( installer_languages_loop => $languages_loop );
494
    if ($dbh) {
489
    if (!C4::Context->needs_install) {
495
        my $rq =
490
        print $query->redirect(
496
          $dbh->prepare(
491
            "/cgi-bin/koha/installer/install.pl?step=3");
497
            "SELECT * from systempreferences WHERE variable='Version'");
492
        exit;
498
        if ( $rq->execute ) {
499
            my ($version) = $rq->fetchrow;
500
            if ($version) {
501
                print $query->redirect(
502
                    "/cgi-bin/koha/installer/install.pl?step=3");
503
                exit;
504
            }
505
        }
506
    }
493
    }
507
}
494
}
508
output_html_with_http_headers $query, $cookie, $template->output;
495
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/installer/onboarding.pl (-1 / +1 lines)
Lines 35-41 use Koha::CirculationRules; Link Here
35
#Setting variables
35
#Setting variables
36
my $input = CGI->new;
36
my $input = CGI->new;
37
37
38
unless ( C4::Context->preference('Version') ) {
38
if ( C4::Context->needs_install ) {
39
    print $input->redirect("/cgi-bin/koha/installer/install.pl");
39
    print $input->redirect("/cgi-bin/koha/installer/install.pl");
40
    exit;
40
    exit;
41
}
41
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt (-1 / +8 lines)
Lines 233-239 Link Here
233
                [% IF ( default ) %]
233
                [% IF ( default ) %]
234
                    [% IF ( upgrading ) %]
234
                    [% IF ( upgrading ) %]
235
                        <h2>Web installer &rsaquo; Update database</h2>
235
                        <h2>Web installer &rsaquo; Update database</h2>
236
                        <p>We are upgrading from Koha [% dbversion | html %] to [% kohaversion | html %]</p>
236
                        <p>
237
                            Pending migrations:
238
                            <ul>
239
                                [% FOREACH migration IN pending_migrations %]
240
                                    <li>[% migration | html %]</li>
241
                                [% END %]
242
                            </ul>
243
                        </p>
237
                        <p><a href="install.pl?step=3&amp;op=updatestructure" class="btn btn-primary">Update your database</a></p>
244
                        <p><a href="install.pl?step=3&amp;op=updatestructure" class="btn btn-primary">Update your database</a></p>
238
                    [% ELSE %]
245
                    [% ELSE %]
239
                        <h2>Web installer &rsaquo; Install basic configuration settings</h2>
246
                        <h2>Web installer &rsaquo; Install basic configuration settings</h2>
(-)a/opac/maintenance.pl (-8 / +4 lines)
Lines 19-40 use Modern::Perl; Link Here
19
19
20
use CGI qw ( -utf8 );
20
use CGI qw ( -utf8 );
21
use C4::Auth;
21
use C4::Auth;
22
use C4::Context;
22
use C4::Output;
23
use C4::Output;
23
use C4::Templates qw/gettemplate/;
24
use C4::Templates qw/gettemplate/;
24
25
25
use Koha;
26
use Koha;
27
use Koha::Migrations;
26
28
27
my $query = CGI->new;
29
my $query = CGI->new;
28
my $template = C4::Templates::gettemplate( 'maintenance.tt', 'opac', $query );
30
my $template = C4::Templates::gettemplate( 'maintenance.tt', 'opac', $query );
29
31
30
my $koha_db_version = C4::Context->preference('Version');
32
if ( C4::Context->needs_install() || # DB not populated
31
my $kohaversion     = Koha::version();
33
     Koha::Migrations->pending_migrations > 0 || # Update needed
32
# Strip dots from version
33
$kohaversion     =~ s/\.//g if defined $kohaversion;
34
$koha_db_version =~ s/\.//g if defined $koha_db_version;
35
36
if ( !defined $koha_db_version || # DB not populated
37
     $kohaversion > $koha_db_version || # Update needed
38
     C4::Context->preference('OpacMaintenance') ) { # Maintenance mode enabled
34
     C4::Context->preference('OpacMaintenance') ) { # Maintenance mode enabled
39
    output_html_with_http_headers $query, '', $template->output;
35
    output_html_with_http_headers $query, '', $template->output;
40
}
36
}
(-)a/plugins/plugins-home.pl (-1 / +5 lines)
Lines 47-54 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
47
47
48
if ($plugins_enabled) {
48
if ($plugins_enabled) {
49
49
50
    my $koha_version = Koha::version();
51
    if ($koha_version =~ /^(\d+)\.(\d+)\.(\d+)/) {
52
        $koha_version = "$1.$2$3";
53
    }
50
    $template->param(
54
    $template->param(
51
        koha_version => C4::Context->preference("Version"),
55
        koha_version => $koha_version,
52
        method       => $method,
56
        method       => $method,
53
    );
57
    );
54
58
(-)a/t/00-checkdatabase-version.t (-60 lines)
Lines 1-60 Link Here
1
# Copyright 2010 Chris Cormack
2
#
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use strict;
19
use warnings;
20
21
use Test::More;
22
use File::Spec;
23
use File::Find;
24
use IO::File;
25
26
my @files =('kohaversion.pl','installer/data/mysql/updatedatabase.pl');
27
28
foreach my $file (@files){
29
    next unless -f $file;
30
    my @name_parts = File::Spec->splitpath($file);
31
    my %dirs = map { $_ => 1 } File::Spec->splitdir($name_parts[1]);
32
    next if exists $dirs{'.git'};
33
34
    my $fh = IO::File->new($file, 'r');
35
    my $xxx_found = 0;
36
    my $line = 0;
37
    while (<$fh>) {
38
       $line++;
39
       if (/XXX/i) {
40
           #two lines are an exception for updatedatabase (routine SetVersion and TransferToNum)
41
           next
42
               if $file =~ /updatedatabase/
43
                  && (   /s\/XXX\$\/999\/;/
44
                      || /\$_\[0\]=~ \/XXX\$\/;/
45
                      || /version contains XXX/
46
                      || /\$proposed_version =~ m\/XXX\// );
47
           $xxx_found = 1;
48
          last;
49
       }
50
     }
51
     close $fh;
52
     if ($xxx_found) {
53
         fail("$file has no XXX in it");
54
        diag("XXX found in line $line");
55
     } else {
56
        pass("$file has no XXX in it");
57
    }
58
}
59
60
done_testing();
(-)a/t/Context.t (-11 lines)
Lines 52-68 subtest 'yaml_preference() tests' => sub { Link Here
52
    $context->unmock( 'preference' );
52
    $context->unmock( 'preference' );
53
};
53
};
54
54
55
subtest 'needs_install() tests' => sub {
56
57
    plan tests => 2;
58
59
    t::lib::Mocks::mock_preference( 'Version', '3.0.0' );
60
    is( C4::Context->needs_install, 0, 'Preference is defined, no need to install' );
61
62
    t::lib::Mocks::mock_preference( 'Version', undef ); # the behaviour when ->preference fails to fetch
63
    is( C4::Context->needs_install, 1, "->preference(Version) is not defined, need to install" );
64
};
65
66
my $context = Test::MockModule->new('C4::Context');
55
my $context = Test::MockModule->new('C4::Context');
67
my $userenv = {};
56
my $userenv = {};
68
57
(-)a/t/Koha_Template_Plugin_Koha.t (-6 / +2 lines)
Lines 48-62 subtest "Koha::Template::Plugin::Koha::Version tests" => sub { Link Here
48
    $major       = $rnd->randregex('\d');
48
    $major       = $rnd->randregex('\d');
49
    $minor       = $rnd->randregex('\d\d');
49
    $minor       = $rnd->randregex('\d\d');
50
    $maintenance = $rnd->randregex('\d\d');
50
    $maintenance = $rnd->randregex('\d\d');
51
    $development = $rnd->randregex('\d\d\d');
51
    my $version = "$major.$minor.$maintenance";
52
    my $version = "$major.$minor.$maintenance.$development";
53
    my $res = Koha::Template::Plugin::Koha::Version( $version );
52
    my $res = Koha::Template::Plugin::Koha::Version( $version );
54
    is_deeply( $res, {
53
    is_deeply( $res, {
55
        major       => $major,
54
        major       => $major,
56
        minor       => $minor,
55
        minor       => $minor,
57
        release     => $major . "." . $minor,
56
        release     => $major . "." . $minor,
58
        maintenance => $major . "." . $minor . "." . $maintenance,
57
        maintenance => $major . "." . $minor . "." . $maintenance,
59
        development => $development
60
    }, "Correct development version");
58
    }, "Correct development version");
61
59
62
60
Lines 64-78 subtest "Koha::Template::Plugin::Koha::Version tests" => sub { Link Here
64
    $major       = $rnd->randregex('\d');
62
    $major       = $rnd->randregex('\d');
65
    $minor       = $rnd->randregex('\d\d');
63
    $minor       = $rnd->randregex('\d\d');
66
    $maintenance = $rnd->randregex('\d\d');
64
    $maintenance = $rnd->randregex('\d\d');
67
    $development = "000";
65
    $version = "$major.$minor.$maintenance";
68
    $version = "$major.$minor.$maintenance.$development";
69
    $res = Koha::Template::Plugin::Koha::Version( $version );
66
    $res = Koha::Template::Plugin::Koha::Version( $version );
70
    is_deeply( $res, {
67
    is_deeply( $res, {
71
        major       => $major,
68
        major       => $major,
72
        minor       => $minor,
69
        minor       => $minor,
73
        release     => $major . "." . $minor,
70
        release     => $major . "." . $minor,
74
        maintenance => $major . "." . $minor . "." . $maintenance,
71
        maintenance => $major . "." . $minor . "." . $maintenance,
75
        development => undef
76
    }, "Correct maintenance version");
72
    }, "Correct maintenance version");
77
73
78
};
74
};
(-)a/t/db_dependent/Context.t (-13 lines)
Lines 134-149 my $yesno_pref = Koha::Config::SysPrefs->find('AutoEmailOpacUser'); Link Here
134
is( $yesno_pref->value(), 0, 'set_preference should have set the value to 0, instead of an empty string' );
134
is( $yesno_pref->value(), 0, 'set_preference should have set the value to 0, instead of an empty string' );
135
135
136
done_testing();
136
done_testing();
137
138
sub TransformVersionToNum {
139
    my $version = shift;
140
141
    # remove the 3 last . to have a Perl number
142
    $version =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
143
144
    # three X's at the end indicate that you are testing patch with dbrev
145
    # change it into 999
146
    # prevents error on a < comparison between strings (should be: lt)
147
    $version =~ s/XXX$/999/;
148
    return $version;
149
}
(-)a/t/db_dependent/Koha/REST/Plugin/PluginRoutes.t (-4 / +3 lines)
Lines 214-221 subtest 'needs_install use case tests' => sub { Link Here
214
    my $plugins = Koha::Plugins->new;
214
    my $plugins = Koha::Plugins->new;
215
    $plugins->InstallPlugins;
215
    $plugins->InstallPlugins;
216
216
217
    # mock Version before initializing the API class
217
    my $c4_context = Test::MockModule->new('C4::Context');
218
    t::lib::Mocks::mock_preference('Version', undef);
218
    $c4_context->mock('needs_install', sub { 1 });
219
    # initialize Koha::REST::V1 after mocking
219
    # initialize Koha::REST::V1 after mocking
220
220
221
    my $t      = Test::Mojo->new('Koha::REST::V1');
221
    my $t      = Test::Mojo->new('Koha::REST::V1');
Lines 228-234 subtest 'needs_install use case tests' => sub { Link Here
228
        'Plugin enabled, route not defined as C4::Context->needs_install is true'
228
        'Plugin enabled, route not defined as C4::Context->needs_install is true'
229
    );
229
    );
230
230
231
    t::lib::Mocks::mock_preference('Version', '3.0.0');
231
    $c4_context->mock('needs_install', sub { 0 });
232
232
233
    $schema->resultset('PluginData')->delete;
233
    $schema->resultset('PluginData')->delete;
234
    $plugins->InstallPlugins;
234
    $plugins->InstallPlugins;
235
- 

Return to bug 27880