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

(-)a/C4/Auth.pm (-33 / +8 lines)
Lines 30-35 use C4::Context; Link Here
30
use C4::Templates;    # to get the template
30
use C4::Templates;    # to get the template
31
use C4::Languages;
31
use C4::Languages;
32
use C4::Search::History;
32
use C4::Search::History;
33
use C4::Installer;
33
use Koha;
34
use Koha;
34
use Koha::Logger;
35
use Koha::Logger;
35
use Koha::Caches;
36
use Koha::Caches;
Lines 47-52 use Encode; Link Here
47
use C4::Auth_with_shibboleth qw( shib_ok get_login_shib login_shib_url logout_shib checkpw_shib );
48
use C4::Auth_with_shibboleth qw( shib_ok get_login_shib login_shib_url logout_shib checkpw_shib );
48
use Net::CIDR;
49
use Net::CIDR;
49
use C4::Log qw( logaction );
50
use C4::Log qw( logaction );
51
use Koha::Migrations;
50
52
51
# use utf8;
53
# use utf8;
52
54
Lines 595-601 sub get_template_and_user { Link Here
595
            OPACPrivacy                           => C4::Context->preference("OPACPrivacy"),
597
            OPACPrivacy                           => C4::Context->preference("OPACPrivacy"),
596
            OPACFinesTab                          => C4::Context->preference("OPACFinesTab"),
598
            OPACFinesTab                          => C4::Context->preference("OPACFinesTab"),
597
            OpacTopissue                          => C4::Context->preference("OpacTopissue"),
599
            OpacTopissue                          => C4::Context->preference("OpacTopissue"),
598
            'Version'                             => C4::Context->preference('Version'),
599
            hidelostitems                         => C4::Context->preference("hidelostitems"),
600
            hidelostitems                         => C4::Context->preference("hidelostitems"),
600
            mylibraryfirst                        => ( C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv ) ? C4::Context->userenv->{'branch'} : '',
601
            mylibraryfirst                        => ( C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv ) ? C4::Context->userenv->{'branch'} : '',
601
            opacbookbag                           => "" . C4::Context->preference("opacbookbag"),
602
            opacbookbag                           => "" . C4::Context->preference("opacbookbag"),
Lines 729-735 has authenticated. Link Here
729
sub _version_check {
730
sub _version_check {
730
    my $type  = shift;
731
    my $type  = shift;
731
    my $query = shift;
732
    my $query = shift;
732
    my $version;
733
733
734
    # If version syspref is unavailable, it means Koha is being installed,
734
    # If version syspref is unavailable, it means Koha is being installed,
735
    # and so we must redirect to OPAC maintenance page or to the WebInstaller
735
    # and so we must redirect to OPAC maintenance page or to the WebInstaller
Lines 739-745 sub _version_check { Link Here
739
        print $query->redirect("/cgi-bin/koha/maintenance.pl");
739
        print $query->redirect("/cgi-bin/koha/maintenance.pl");
740
        safe_exit;
740
        safe_exit;
741
    }
741
    }
742
    unless ( $version = C4::Context->preference('Version') ) {    # assignment, not comparison
742
    unless ( C4::Installer::TableExists('systempreferences') ) {
743
        if ( $type ne 'opac' ) {
743
        if ( $type ne 'opac' ) {
744
            warn "Install required, redirecting to Installer";
744
            warn "Install required, redirecting to Installer";
745
            print $query->redirect("/cgi-bin/koha/installer/install.pl");
745
            print $query->redirect("/cgi-bin/koha/installer/install.pl");
Lines 750-766 sub _version_check { Link Here
750
        safe_exit;
750
        safe_exit;
751
    }
751
    }
752
752
753
    # check that database and koha version are the same
753
    if (Koha::Migrations->pending_migrations > 0) {
754
    # there is no DB version, it's a fresh install,
754
        my $warning = "Database update needed, redirecting to %s";
755
    # go to web installer
756
    # there is a DB version, compare it to the code version
757
    my $kohaversion = Koha::version();
758
759
    # remove the 3 last . to have a Perl number
760
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
761
    Koha::Logger->get->debug("kohaversion : $kohaversion");
762
    if ( $version < $kohaversion ) {
763
        my $warning = "Database update needed, redirecting to %s. Database is $version and Koha is $kohaversion";
764
        if ( $type ne 'opac' ) {
755
        if ( $type ne 'opac' ) {
765
            warn sprintf( $warning, 'Installer' );
756
            warn sprintf( $warning, 'Installer' );
766
            print $query->redirect("/cgi-bin/koha/installer/install.pl?step=1&op=updatestructure");
757
            print $query->redirect("/cgi-bin/koha/installer/install.pl?step=1&op=updatestructure");
Lines 1440-1454 sub check_api_auth { Link Here
1440
    my $dbh     = C4::Context->dbh;
1431
    my $dbh     = C4::Context->dbh;
1441
    my $timeout = _timeout_syspref();
1432
    my $timeout = _timeout_syspref();
1442
1433
1443
    unless ( C4::Context->preference('Version') ) {
1434
    if ( Koha::Migrations->pending_migrations > 0 ) {
1444
1445
        # database has not been installed yet
1446
        return ( "maintenance", undef, undef );
1447
    }
1448
    my $kohaversion = Koha::version();
1449
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
1450
    if ( C4::Context->preference('Version') < $kohaversion ) {
1451
1452
        # database in need of version update; assume that
1435
        # database in need of version update; assume that
1453
        # no API should be called while databsae is in
1436
        # no API should be called while databsae is in
1454
        # this condition.
1437
        # this condition.
Lines 1644-1660 sub check_cookie_auth { Link Here
1644
    my $skip_version_check = $params->{skip_version_check}; # Only for checkauth
1627
    my $skip_version_check = $params->{skip_version_check}; # Only for checkauth
1645
1628
1646
    unless ( $skip_version_check ) {
1629
    unless ( $skip_version_check ) {
1647
        unless ( C4::Context->preference('Version') ) {
1630
        if ( Koha::Migrations->pending_migrations > 0 ) {
1648
1649
            # database has not been installed yet
1650
            return ( "maintenance", undef );
1651
        }
1652
        my $kohaversion = Koha::version();
1653
        $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
1654
        if ( C4::Context->preference('Version') < $kohaversion ) {
1655
1656
            # database in need of version update; assume that
1631
            # database in need of version update; assume that
1657
            # no API should be called while databsae is in
1632
            # no API should be called while database is in
1658
            # this condition.
1633
            # this condition.
1659
            return ( "maintenance", undef );
1634
            return ( "maintenance", undef );
1660
        }
1635
        }
(-)a/C4/Context.pm (-2 / +13 lines)
Lines 313-318 sub preference { Link Here
313
313
314
    $var = lc $var;
314
    $var = lc $var;
315
315
316
    if ($var eq 'version') {
317
        my $version = Koha::version();
318
        $version =~ s/^(\d+)\.(\d+)\.(\d+)$/$1.$2$3/;
319
        return $version;
320
    }
321
316
    if ($use_syspref_cache) {
322
    if ($use_syspref_cache) {
317
        my $syspref_cache = Koha::Caches->get_instance('syspref');
323
        my $syspref_cache = Koha::Caches->get_instance('syspref');
318
        my $cached_var = $syspref_cache->get_from_cache("syspref_$var");
324
        my $cached_var = $syspref_cache->get_from_cache("syspref_$var");
Lines 799-805 Gets various version info, for core Koha packages, Currently called from carp ha Link Here
799
sub get_versions {
805
sub get_versions {
800
    my %versions;
806
    my %versions;
801
    $versions{kohaVersion}  = Koha::version();
807
    $versions{kohaVersion}  = Koha::version();
802
    $versions{kohaDbVersion} = C4::Context->preference('version');
803
    $versions{osVersion} = join(" ", POSIX::uname());
808
    $versions{osVersion} = join(" ", POSIX::uname());
804
    $versions{perlVersion} = $];
809
    $versions{perlVersion} = $];
805
    {
810
    {
Lines 975-981 This method returns a boolean representing the install status of the Koha instan Link Here
975
980
976
sub needs_install {
981
sub needs_install {
977
    my ($self) = @_;
982
    my ($self) = @_;
978
    return ($self->preference('Version')) ? 0 : 1;
983
    eval {
984
        my $dbh = $self->dbh;
985
        local $dbh->{PrintError} = 0;
986
        local $dbh->{RaiseError} = 1;
987
        $dbh->do('SELECT * FROM systempreferences WHERE 1 = 0');
988
    };
989
    return $@ ? 1 : 0;
979
}
990
}
980
991
981
__END__
992
__END__
(-)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 445-477 sub set_marcflavour_syspref { Link Here
445
    $request->execute;
444
    $request->execute;
446
}
445
}
447
446
448
=head2 set_version_syspref
449
450
  $installer->set_version_syspref();
451
452
Set or update the 'Version' system preference to the current
453
Koha software version.
454
455
=cut
456
457
sub set_version_syspref {
458
    my $self = shift;
459
460
    my $kohaversion = Koha::version();
461
    # remove the 3 last . to have a Perl number
462
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
463
    if (C4::Context->preference('Version')) {
464
        warn "UPDATE Version";
465
        my $finish=$self->{'dbh'}->prepare("UPDATE systempreferences SET value=? WHERE variable='Version'");
466
        $finish->execute($kohaversion);
467
    } else {
468
        warn "INSERT Version";
469
        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')");
470
        $finish->execute($kohaversion);
471
    }
472
    C4::Context->clear_syspref_cache();
473
}
474
475
=head2 set_languages_syspref
447
=head2 set_languages_syspref
476
448
477
  $installer->set_languages_syspref();
449
  $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 = "21.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 = "21.06.00.049";
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/kohastructure.sql (+11 lines)
Lines 2583-2588 CREATE TABLE `edifact_messages` ( Link Here
2583
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2583
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2584
/*!40101 SET character_set_client = @saved_cs_client */;
2584
/*!40101 SET character_set_client = @saved_cs_client */;
2585
2585
2586
--
2587
-- Structure for table executed_migrations
2588
--
2589
2590
DROP TABLE IF EXISTS `executed_migrations`;
2591
CREATE TABLE `executed_migrations` (
2592
    `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
2593
    `executed_at` timestamp NOT NULL DEFAULT current_timestamp(),
2594
    PRIMARY KEY (`name`)
2595
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2596
2586
--
2597
--
2587
-- Table structure for table `export_format`
2598
-- Table structure for table `export_format`
2588
--
2599
--
(-)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 41-46 use C4::Installer; Link Here
41
use Koha::Database;
41
use Koha::Database;
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::Migrations;
44
45
45
use MARC::Record;
46
use MARC::Record;
46
use MARC::File::XML ( BinaryEncoding => 'utf8' );
47
use MARC::File::XML ( BinaryEncoding => 'utf8' );
Lines 24307-24310 unless ( $ENV{HTTP_HOST} ) { # Is that correct? Link Here
24307
24308
24308
}
24309
}
24309
24310
24311
my $insert_migration_sth = $dbh->prepare('INSERT INTO executed_migrations (name) VALUES (?)');
24312
24313
my $migrations_dir = Koha::Migrations->migrations_dir;
24314
foreach my $file (Koha::Migrations->pending_migrations) {
24315
    my $migration = do $migrations_dir . '/' . $file;
24316
    unless ($migration) {
24317
        if ($@) {
24318
            warn "Could not compile $file: $@";
24319
        } elsif ($!) {
24320
            warn "Could not do $file: $!";
24321
        } else {
24322
            warn "Could not run $file";
24323
        }
24324
        next;
24325
    }
24326
24327
    eval {
24328
        $migration->{up}->($dbh);
24329
        $insert_migration_sth->execute($file);
24330
        say sprintf('Migration done: %s (%s)', $file, $migration->{description});
24331
    };
24332
    if ($@) {
24333
        die sprintf('Migration failed %s (%s): %s', $file, $migration->{description}, $@);
24334
    }
24335
}
24336
24310
exit;
24337
exit;
(-)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 227-233 elsif ( $step && $step == 3 ) { Link Here
227
        exit;
228
        exit;
228
    }
229
    }
229
    elsif ( $op && $op eq 'finish' ) {
230
    elsif ( $op && $op eq 'finish' ) {
230
        $installer->set_version_syspref();
231
        Koha::Migrations->mark_all_migrations_as_executed();
231
232
232
        my $langchoice = $query->param('fwklanguage');
233
        my $langchoice = $query->param('fwklanguage');
233
        $langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice);
234
        $langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice);
Lines 383-393 elsif ( $step && $step == 3 ) { Link Here
383
384
384
        my $now         = POSIX::strftime( "%Y-%m-%dT%H:%M:%S", localtime() );
385
        my $now         = POSIX::strftime( "%Y-%m-%dT%H:%M:%S", localtime() );
385
        my $logdir      = C4::Context->config('logdir');
386
        my $logdir      = C4::Context->config('logdir');
386
        my $dbversion   = C4::Context->preference('Version');
387
        my $kohaversion = Koha::version;
387
        my $kohaversion = Koha::version;
388
        $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
388
        $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
389
389
390
        my $filename_suffix = join '_', $now, $dbversion, $kohaversion;
390
        my $filename_suffix = join '_', $now, $kohaversion;
391
        my ( $logfilepath, $logfilepath_errors ) = (
391
        my ( $logfilepath, $logfilepath_errors ) = (
392
            chk_log( $logdir, "updatedatabase_$filename_suffix" ),
392
            chk_log( $logdir, "updatedatabase_$filename_suffix" ),
393
            chk_log( $logdir, "updatedatabase-error_$filename_suffix" )
393
            chk_log( $logdir, "updatedatabase-error_$filename_suffix" )
Lines 485-503 elsif ( $step && $step == 3 ) { Link Here
485
           # we have tables, propose to select files to upload or updatedatabase
485
           # we have tables, propose to select files to upload or updatedatabase
486
           #
486
           #
487
            $template->param( "count" => $count, "default" => 1 );
487
            $template->param( "count" => $count, "default" => 1 );
488
     #
488
489
     # 1st part of step 3 : check if there is a databaseversion systempreference
489
            # 1st part of step 3 : check if we need to install the database
490
     # if there is, then we just need to upgrade
490
            # if not, then we just need to upgrade
491
     # if there is none, then we need to install the database
491
            unless ( C4::Context->needs_install() ) {
492
     #
493
            if ( C4::Context->preference('Version') ) {
494
                my $dbversion = C4::Context->preference('Version');
495
                $dbversion =~ /(.*)\.(..)(..)(...)/;
496
                $dbversion = "$1.$2.$3.$4";
497
                $template->param(
492
                $template->param(
498
                    "upgrading"   => 1,
493
                    "upgrading"   => 1,
499
                    "dbversion"   => $dbversion,
500
                    "kohaversion" => Koha::version(),
494
                    "kohaversion" => Koha::version(),
495
                    "pending_migrations" => [ Koha::Migrations->pending_migrations ],
501
                );
496
                );
502
            }
497
            }
503
        }
498
        }
Lines 509-526 else { Link Here
509
    # using opendir + language Hash
504
    # using opendir + language Hash
510
    my $languages_loop = getTranslatedLanguages('intranet');
505
    my $languages_loop = getTranslatedLanguages('intranet');
511
    $template->param( installer_languages_loop => $languages_loop );
506
    $template->param( installer_languages_loop => $languages_loop );
512
    if ($dbh) {
507
    if (!C4::Context->needs_install) {
513
        my $rq =
508
        print $query->redirect(
514
          $dbh->prepare(
509
            "/cgi-bin/koha/installer/install.pl?step=3");
515
            "SELECT * from systempreferences WHERE variable='Version'");
510
        exit;
516
        if ( $rq->execute ) {
517
            my ($version) = $rq->fetchrow;
518
            if ($version) {
519
                print $query->redirect(
520
                    "/cgi-bin/koha/installer/install.pl?step=3");
521
                exit;
522
            }
523
        }
524
    }
511
    }
525
}
512
}
526
output_html_with_http_headers $query, $cookie, $template->output;
513
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 314-320 Link Here
314
                [% IF ( default ) %]
314
                [% IF ( default ) %]
315
                    [% IF ( upgrading ) %]
315
                    [% IF ( upgrading ) %]
316
                        <h2>Web installer &rsaquo; Update database</h2>
316
                        <h2>Web installer &rsaquo; Update database</h2>
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
                        <h2>Web installer &rsaquo; Install basic configuration settings</h2>
327
                        <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 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/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 132-147 my $yesno_pref = Koha::Config::SysPrefs->find('AutoEmailOpacUser'); Link Here
132
is( $yesno_pref->value(), 0, 'set_preference should have set the value to 0, instead of an empty string' );
132
is( $yesno_pref->value(), 0, 'set_preference should have set the value to 0, instead of an empty string' );
133
133
134
done_testing();
134
done_testing();
135
136
sub TransformVersionToNum {
137
    my $version = shift;
138
139
    # remove the 3 last . to have a Perl number
140
    $version =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
141
142
    # three X's at the end indicate that you are testing patch with dbrev
143
    # change it into 999
144
    # prevents error on a < comparison between strings (should be: lt)
145
    $version =~ s/XXX$/999/;
146
    return $version;
147
}
(-)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