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

(-)a/C4/Auth.pm (-33 / +8 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::Logger;
36
use Koha::Logger;
36
use Koha::Caches;
37
use Koha::Caches;
Lines 51-56 use Net::CIDR; Link Here
51
use C4::Log qw( logaction );
52
use C4::Log qw( logaction );
52
use Koha::CookieManager;
53
use Koha::CookieManager;
53
use Koha::Auth::Permissions;
54
use Koha::Auth::Permissions;
55
use Koha::Migrations;
54
56
55
# use utf8;
57
# use utf8;
56
58
Lines 574-580 sub get_template_and_user { Link Here
574
            OPACPrivacy                           => C4::Context->preference("OPACPrivacy"),
576
            OPACPrivacy                           => C4::Context->preference("OPACPrivacy"),
575
            OPACFinesTab                          => C4::Context->preference("OPACFinesTab"),
577
            OPACFinesTab                          => C4::Context->preference("OPACFinesTab"),
576
            OpacTopissue                          => C4::Context->preference("OpacTopissue"),
578
            OpacTopissue                          => C4::Context->preference("OpacTopissue"),
577
            'Version'                             => C4::Context->preference('Version'),
578
            hidelostitems                         => C4::Context->preference("hidelostitems"),
579
            hidelostitems                         => C4::Context->preference("hidelostitems"),
579
            mylibraryfirst                        => ( C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv ) ? C4::Context->userenv->{'branch'} : '',
580
            mylibraryfirst                        => ( C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv ) ? C4::Context->userenv->{'branch'} : '',
580
            opacbookbag                           => "" . C4::Context->preference("opacbookbag"),
581
            opacbookbag                           => "" . C4::Context->preference("opacbookbag"),
Lines 704-710 has authenticated. Link Here
704
sub _version_check {
705
sub _version_check {
705
    my $type  = shift;
706
    my $type  = shift;
706
    my $query = shift;
707
    my $query = shift;
707
    my $version;
708
708
709
    # If version syspref is unavailable, it means Koha is being installed,
709
    # If version syspref is unavailable, it means Koha is being installed,
710
    # and so we must redirect to OPAC maintenance page or to the WebInstaller
710
    # and so we must redirect to OPAC maintenance page or to the WebInstaller
Lines 714-720 sub _version_check { Link Here
714
        print $query->redirect("/cgi-bin/koha/maintenance.pl");
714
        print $query->redirect("/cgi-bin/koha/maintenance.pl");
715
        safe_exit;
715
        safe_exit;
716
    }
716
    }
717
    unless ( $version = C4::Context->preference('Version') ) {    # assignment, not comparison
717
    unless ( C4::Installer::TableExists('systempreferences') ) {
718
        if ( $type ne 'opac' ) {
718
        if ( $type ne 'opac' ) {
719
            warn "Install required, redirecting to Installer";
719
            warn "Install required, redirecting to Installer";
720
            print $query->redirect("/cgi-bin/koha/installer/install.pl");
720
            print $query->redirect("/cgi-bin/koha/installer/install.pl");
Lines 725-741 sub _version_check { Link Here
725
        safe_exit;
725
        safe_exit;
726
    }
726
    }
727
727
728
    # check that database and koha version are the same
728
    if (Koha::Migrations->pending_migrations > 0) {
729
    # there is no DB version, it's a fresh install,
729
        my $warning = "Database update needed, redirecting to %s";
730
    # go to web installer
731
    # there is a DB version, compare it to the code version
732
    my $kohaversion = Koha::version();
733
734
    # remove the 3 last . to have a Perl number
735
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
736
    Koha::Logger->get->debug("kohaversion : $kohaversion");
737
    if ( $version < $kohaversion ) {
738
        my $warning = "Database update needed, redirecting to %s. Database is $version and Koha is $kohaversion";
739
        if ( $type ne 'opac' ) {
730
        if ( $type ne 'opac' ) {
740
            warn sprintf( $warning, 'Installer' );
731
            warn sprintf( $warning, 'Installer' );
741
            print $query->redirect("/cgi-bin/koha/installer/install.pl?step=1&op=updatestructure");
732
            print $query->redirect("/cgi-bin/koha/installer/install.pl?step=1&op=updatestructure");
Lines 1519-1533 sub check_api_auth { Link Here
1519
    my $flagsrequired = shift;
1510
    my $flagsrequired = shift;
1520
    my $timeout = _timeout_syspref();
1511
    my $timeout = _timeout_syspref();
1521
1512
1522
    unless ( C4::Context->preference('Version') ) {
1513
    if ( Koha::Migrations->pending_migrations > 0 ) {
1523
1524
        # database has not been installed yet
1525
        return ( "maintenance", undef, undef );
1526
    }
1527
    my $kohaversion = Koha::version();
1528
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
1529
    if ( C4::Context->preference('Version') < $kohaversion ) {
1530
1531
        # database in need of version update; assume that
1514
        # database in need of version update; assume that
1532
        # no API should be called while databsae is in
1515
        # no API should be called while databsae is in
1533
        # this condition.
1516
        # this condition.
Lines 1728-1744 sub check_cookie_auth { Link Here
1728
    my $skip_version_check = $params->{skip_version_check}; # Only for checkauth
1711
    my $skip_version_check = $params->{skip_version_check}; # Only for checkauth
1729
1712
1730
    unless ( $skip_version_check ) {
1713
    unless ( $skip_version_check ) {
1731
        unless ( C4::Context->preference('Version') ) {
1714
        if ( Koha::Migrations->pending_migrations > 0 ) {
1732
1733
            # database has not been installed yet
1734
            return ( "maintenance", undef );
1735
        }
1736
        my $kohaversion = Koha::version();
1737
        $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
1738
        if ( C4::Context->preference('Version') < $kohaversion ) {
1739
1740
            # database in need of version update; assume that
1715
            # database in need of version update; assume that
1741
            # no API should be called while databsae is in
1716
            # no API should be called while database is in
1742
            # this condition.
1717
            # this condition.
1743
            return ( "maintenance", undef );
1718
            return ( "maintenance", undef );
1744
        }
1719
        }
(-)a/C4/Context.pm (-2 / +13 lines)
Lines 314-319 sub preference { Link Here
314
314
315
    $var = lc $var;
315
    $var = lc $var;
316
316
317
    if ($var eq 'version') {
318
        my $version = Koha::version();
319
        $version =~ s/^(\d+)\.(\d+)\.(\d+)$/$1.$2$3/;
320
        return $version;
321
    }
322
317
    if ($use_syspref_cache) {
323
    if ($use_syspref_cache) {
318
        my $syspref_cache = Koha::Caches->get_instance('syspref');
324
        my $syspref_cache = Koha::Caches->get_instance('syspref');
319
        my $cached_var = $syspref_cache->get_from_cache("syspref_$var");
325
        my $cached_var = $syspref_cache->get_from_cache("syspref_$var");
Lines 856-862 Gets various version info, for core Koha packages, Currently called from carp ha Link Here
856
sub get_versions {
862
sub get_versions {
857
    my ( %versions, $mysqlVersion );
863
    my ( %versions, $mysqlVersion );
858
    $versions{kohaVersion}  = Koha::version();
864
    $versions{kohaVersion}  = Koha::version();
859
    $versions{kohaDbVersion} = C4::Context->preference('version');
860
    $versions{osVersion} = join(" ", POSIX::uname());
865
    $versions{osVersion} = join(" ", POSIX::uname());
861
    $versions{perlVersion} = $];
866
    $versions{perlVersion} = $];
862
867
Lines 1037-1043 This method returns a boolean representing the install status of the Koha instan Link Here
1037
1042
1038
sub needs_install {
1043
sub needs_install {
1039
    my ($self) = @_;
1044
    my ($self) = @_;
1040
    return ($self->preference('Version')) ? 0 : 1;
1045
    eval {
1046
        my $dbh = $self->dbh;
1047
        local $dbh->{PrintError} = 0;
1048
        local $dbh->{RaiseError} = 1;
1049
        $dbh->do('SELECT * FROM systempreferences WHERE 1 = 0');
1050
    };
1051
    return $@ ? 1 : 0;
1041
}
1052
}
1042
1053
1043
=head3 psgi_env
1054
=head3 psgi_env
(-)a/C4/Installer.pm (-28 lines)
Lines 50-56 C4::Installer Link Here
50
 my $list;
50
 my $list;
51
 #fill $list with list of sql files
51
 #fill $list with list of sql files
52
 my ($fwk_language, $error_list) = $installer->load_sql_in_order($all_languages, @$list);
52
 my ($fwk_language, $error_list) = $installer->load_sql_in_order($all_languages, @$list);
53
 $installer->set_version_syspref();
54
 $installer->set_marcflavour_syspref('MARC21');
53
 $installer->set_marcflavour_syspref('MARC21');
55
54
56
=head1 DESCRIPTION
55
=head1 DESCRIPTION
Lines 448-480 sub set_marcflavour_syspref { Link Here
448
    $request->execute;
447
    $request->execute;
449
}
448
}
450
449
451
=head2 set_version_syspref
452
453
  $installer->set_version_syspref();
454
455
Set or update the 'Version' system preference to the current
456
Koha software version.
457
458
=cut
459
460
sub set_version_syspref {
461
    my $self = shift;
462
463
    my $kohaversion = Koha::version();
464
    # remove the 3 last . to have a Perl number
465
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
466
    if (C4::Context->preference('Version')) {
467
        warn "UPDATE Version";
468
        my $finish=$self->{'dbh'}->prepare("UPDATE systempreferences SET value=? WHERE variable='Version'");
469
        $finish->execute($kohaversion);
470
    } else {
471
        warn "INSERT Version";
472
        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')");
473
        $finish->execute($kohaversion);
474
    }
475
    C4::Context->clear_syspref_cache();
476
}
477
478
=head2 set_languages_syspref
450
=head2 set_languages_syspref
479
451
480
  $installer->set_languages_syspref();
452
  $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 = "23.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 = "23.06.00.007";
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 73-86 sub CSVDelimiter { Link Here
73
73
74
sub Version {
74
sub Version {
75
    my $version_string = Koha::version();
75
    my $version_string = Koha::version();
76
    my ( $major, $minor, $maintenance, $development ) = split( '\.', $version_string );
76
    my ( $major, $minor, $maintenance ) = split( '\.', $version_string );
77
77
78
    return {
78
    return {
79
        major       => $major,
79
        major       => $major,
80
        minor       => $minor,
80
        minor       => $minor,
81
        release     => $major . "." . $minor,
81
        release     => $major . "." . $minor,
82
        maintenance => $major . "." . $minor . "." . $maintenance,
82
        maintenance => $major . "." . $minor . "." . $maintenance,
83
        development => ( $development ne '000' ) ? $development : undef,
84
    };
83
    };
85
}
84
}
86
85
(-)a/installer/data/mysql/kohastructure.sql (+11 lines)
Lines 3067-3072 CREATE TABLE `erm_user_roles` ( Link Here
3067
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3067
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3068
/*!40101 SET character_set_client = @saved_cs_client */;
3068
/*!40101 SET character_set_client = @saved_cs_client */;
3069
3069
3070
--
3071
-- Structure for table executed_migrations
3072
--
3073
3074
DROP TABLE IF EXISTS `executed_migrations`;
3075
CREATE TABLE `executed_migrations` (
3076
    `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
3077
    `executed_at` timestamp NOT NULL DEFAULT current_timestamp(),
3078
    PRIMARY KEY (`name`)
3079
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3080
3070
--
3081
--
3071
-- Table structure for table `export_format`
3082
-- Table structure for table `export_format`
3072
--
3083
--
(-)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 (+27 lines)
Lines 42-47 use Koha::Database; Link Here
42
use Koha;
42
use Koha;
43
use Koha::DateUtils qw( dt_from_string output_pref );
43
use Koha::DateUtils qw( dt_from_string output_pref );
44
use Koha::Caches;
44
use Koha::Caches;
45
use Koha::Migrations;
45
46
46
use MARC::Record;
47
use MARC::Record;
47
use MARC::File::XML ( BinaryEncoding => 'utf8' );
48
use MARC::File::XML ( BinaryEncoding => 'utf8' );
Lines 24316-24319 unless ( $ENV{HTTP_HOST} ) { # Is that correct? Link Here
24316
24317
24317
}
24318
}
24318
24319
24320
my $insert_migration_sth = $dbh->prepare('INSERT INTO executed_migrations (name) VALUES (?)');
24321
24322
my $migrations_dir = Koha::Migrations->migrations_dir;
24323
foreach my $file (Koha::Migrations->pending_migrations) {
24324
    my $migration = do $migrations_dir . '/' . $file;
24325
    unless ($migration) {
24326
        if ($@) {
24327
            warn "Could not compile $file: $@";
24328
        } elsif ($!) {
24329
            warn "Could not do $file: $!";
24330
        } else {
24331
            warn "Could not run $file";
24332
        }
24333
        next;
24334
    }
24335
24336
    eval {
24337
        $migration->{up}->($dbh);
24338
        $insert_migration_sth->execute($file);
24339
        say sprintf('Migration done: %s (%s)', $file, $migration->{description});
24340
    };
24341
    if ($@) {
24342
        die sprintf('Migration failed %s (%s): %s', $file, $migration->{description}, $@);
24343
    }
24344
}
24345
24319
exit;
24346
exit;
(-)a/installer/install.pl (-25 / +12 lines)
Lines 33-38 use C4::Installer::PerlModules; Link Here
33
33
34
use Koha;
34
use Koha;
35
use Koha::Caches;
35
use Koha::Caches;
36
use Koha::Migrations;
36
37
37
my $query = CGI->new;
38
my $query = CGI->new;
38
my $step  = $query->param('step');
39
my $step  = $query->param('step');
Lines 238-244 elsif ( $step && $step == 3 ) { Link Here
238
        exit;
239
        exit;
239
    }
240
    }
240
    elsif ( $op && $op eq 'finish' ) {
241
    elsif ( $op && $op eq 'finish' ) {
241
        $installer->set_version_syspref();
242
        Koha::Migrations->mark_all_migrations_as_executed();
242
243
243
        my $langchoice = $query->param('fwklanguage');
244
        my $langchoice = $query->param('fwklanguage');
244
        $langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice);
245
        $langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice);
Lines 395-405 elsif ( $step && $step == 3 ) { Link Here
395
396
396
        my $now         = POSIX::strftime( "%Y-%m-%dT%H:%M:%S", localtime() );
397
        my $now         = POSIX::strftime( "%Y-%m-%dT%H:%M:%S", localtime() );
397
        my $logdir      = C4::Context->config('logdir');
398
        my $logdir      = C4::Context->config('logdir');
398
        my $dbversion   = C4::Context->preference('Version');
399
        my $kohaversion = Koha::version;
399
        my $kohaversion = Koha::version;
400
        $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
400
        $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
401
401
402
        my $filename_suffix = join '_', $now, $dbversion, $kohaversion;
402
        my $filename_suffix = join '_', $now, $kohaversion;
403
        my ( $logfilepath, $logfilepath_errors ) = (
403
        my ( $logfilepath, $logfilepath_errors ) = (
404
            chk_log( $logdir, "updatedatabase_$filename_suffix" ),
404
            chk_log( $logdir, "updatedatabase_$filename_suffix" ),
405
            chk_log( $logdir, "updatedatabase-error_$filename_suffix" )
405
            chk_log( $logdir, "updatedatabase-error_$filename_suffix" )
Lines 497-515 elsif ( $step && $step == 3 ) { Link Here
497
           # we have tables, propose to select files to upload or updatedatabase
497
           # we have tables, propose to select files to upload or updatedatabase
498
           #
498
           #
499
            $template->param( "count" => $count, "default" => 1 );
499
            $template->param( "count" => $count, "default" => 1 );
500
     #
500
501
     # 1st part of step 3 : check if there is a databaseversion systempreference
501
            # 1st part of step 3 : check if we need to install the database
502
     # if there is, then we just need to upgrade
502
            # if not, then we just need to upgrade
503
     # if there is none, then we need to install the database
503
            unless ( C4::Context->needs_install() ) {
504
     #
505
            if ( C4::Context->preference('Version') ) {
506
                my $dbversion = C4::Context->preference('Version');
507
                $dbversion =~ /(.*)\.(..)(..)(...)/;
508
                $dbversion = "$1.$2.$3.$4";
509
                $template->param(
504
                $template->param(
510
                    "upgrading"   => 1,
505
                    "upgrading"   => 1,
511
                    "dbversion"   => $dbversion,
512
                    "kohaversion" => Koha::version(),
506
                    "kohaversion" => Koha::version(),
507
                    "pending_migrations" => [ Koha::Migrations->pending_migrations ],
513
                );
508
                );
514
            }
509
            }
515
        }
510
        }
Lines 521-538 else { Link Here
521
    # using opendir + language Hash
516
    # using opendir + language Hash
522
    my $languages_loop = getTranslatedLanguages('intranet');
517
    my $languages_loop = getTranslatedLanguages('intranet');
523
    $template->param( installer_languages_loop => $languages_loop );
518
    $template->param( installer_languages_loop => $languages_loop );
524
    if ($dbh) {
519
    if (!C4::Context->needs_install) {
525
        my $rq =
520
        print $query->redirect(
526
          $dbh->prepare(
521
            "/cgi-bin/koha/installer/install.pl?step=3");
527
            "SELECT * from systempreferences WHERE variable='Version'");
522
        exit;
528
        if ( $rq->execute ) {
529
            my ($version) = $rq->fetchrow;
530
            if ($version) {
531
                print $query->redirect(
532
                    "/cgi-bin/koha/installer/install.pl?step=3");
533
                exit;
534
            }
535
        }
536
    }
523
    }
537
}
524
}
538
output_html_with_http_headers $query, $cookie, $template->output;
525
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/installer/onboarding.pl (-1 / +1 lines)
Lines 34-40 use Koha::CirculationRules; Link Here
34
#Setting variables
34
#Setting variables
35
my $input = CGI->new;
35
my $input = CGI->new;
36
36
37
unless ( C4::Context->preference('Version') ) {
37
if ( C4::Context->needs_install ) {
38
    print $input->redirect("/cgi-bin/koha/installer/install.pl");
38
    print $input->redirect("/cgi-bin/koha/installer/install.pl");
39
    exit;
39
    exit;
40
}
40
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt (-1 / +8 lines)
Lines 314-320 Link Here
314
                [% IF ( default ) %]
314
                [% IF ( default ) %]
315
                    [% IF ( upgrading ) %]
315
                    [% IF ( upgrading ) %]
316
                        <h1>Web installer &rsaquo; Update database</h1>
316
                        <h1>Web installer &rsaquo; Update database</h1>
317
                        <p>We are upgrading from Koha [% dbversion | html %] to [% kohaversion | html %]</p>
317
                        <p>
318
                            Pending migrations:
319
                            <ul>
320
                                [% FOREACH migration IN pending_migrations %]
321
                                    <li>[% migration | html %]</li>
322
                                [% END %]
323
                            </ul>
324
                        </p>
318
                        <p><a href="install.pl?step=3&amp;op=updatestructure" class="btn btn-primary">Update your database</a></p>
325
                        <p><a href="install.pl?step=3&amp;op=updatestructure" class="btn btn-primary">Update your database</a></p>
319
                    [% ELSE %]
326
                    [% ELSE %]
320
                        <h1>Web installer &rsaquo; Install basic configuration settings</h1>
327
                        <h1>Web installer &rsaquo; Install basic configuration settings</h1>
(-)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 qw( output_html_with_http_headers );
23
use C4::Output qw( output_html_with_http_headers );
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 45-52 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
45
45
46
if ($plugins_enabled) {
46
if ($plugins_enabled) {
47
47
48
    my $koha_version = Koha::version();
49
    if ($koha_version =~ /^(\d+)\.(\d+)\.(\d+)/) {
50
        $koha_version = "$1.$2$3";
51
    }
48
    $template->param(
52
    $template->param(
49
        koha_version => C4::Context->preference("Version"),
53
        koha_version => $koha_version,
50
        method       => $method,
54
        method       => $method,
51
    );
55
    );
52
56
(-)a/t/Context.t (-11 lines)
Lines 58-74 subtest 'yaml_preference() tests' => sub { Link Here
58
    $context->unmock( 'preference' );
58
    $context->unmock( 'preference' );
59
};
59
};
60
60
61
subtest 'needs_install() tests' => sub {
62
63
    plan tests => 2;
64
65
    t::lib::Mocks::mock_preference( 'Version', '3.0.0' );
66
    is( C4::Context->needs_install, 0, 'Preference is defined, no need to install' );
67
68
    t::lib::Mocks::mock_preference( 'Version', undef ); # the behaviour when ->preference fails to fetch
69
    is( C4::Context->needs_install, 1, "->preference(Version) is not defined, need to install" );
70
};
71
72
subtest 'csv_delimiter() tests' => sub {
61
subtest 'csv_delimiter() tests' => sub {
73
62
74
    plan tests => 4;
63
    plan tests => 4;
(-)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/Koha/REST/Plugin/PluginRoutes.t (-4 / +3 lines)
Lines 218-225 subtest 'needs_install use case tests' => sub { Link Here
218
    my $plugins = Koha::Plugins->new;
218
    my $plugins = Koha::Plugins->new;
219
    $plugins->InstallPlugins;
219
    $plugins->InstallPlugins;
220
220
221
    # mock Version before initializing the API class
221
    my $c4_context = Test::MockModule->new('C4::Context');
222
    t::lib::Mocks::mock_preference('Version', undef);
222
    $c4_context->mock('needs_install', sub { 1 });
223
    # initialize Koha::REST::V1 after mocking
223
    # initialize Koha::REST::V1 after mocking
224
224
225
    my $t      = Test::Mojo->new('Koha::REST::V1');
225
    my $t      = Test::Mojo->new('Koha::REST::V1');
Lines 232-238 subtest 'needs_install use case tests' => sub { Link Here
232
        'Plugin enabled, route not defined as C4::Context->needs_install is true'
232
        'Plugin enabled, route not defined as C4::Context->needs_install is true'
233
    );
233
    );
234
234
235
    t::lib::Mocks::mock_preference('Version', '3.0.0');
235
    $c4_context->mock('needs_install', sub { 0 });
236
236
237
    $schema->resultset('PluginData')->delete;
237
    $schema->resultset('PluginData')->delete;
238
    $plugins->InstallPlugins;
238
    $plugins->InstallPlugins;
239
- 

Return to bug 27880