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

(-)a/C4/Installer.pm (+37 lines)
Lines 26-31 use C4::Installer::PerlModules; Link Here
26
use DBI;
26
use DBI;
27
use Koha;
27
use Koha;
28
28
29
use vars qw(@ISA @EXPORT);
30
BEGIN {
31
    require Exporter;
32
    @ISA = qw( Exporter );
33
    push @EXPORT, qw( foreign_key_exists index_exists column_exists );
34
};
35
29
=head1 NAME
36
=head1 NAME
30
37
31
C4::Installer
38
C4::Installer
Lines 487-492 sub get_file_path_from_name { Link Here
487
494
488
}
495
}
489
496
497
sub foreign_key_exists {
498
    my ( $table_name, $constraint_name ) = @_;
499
    my $dbh = C4::Context->dbh;
500
    my (undef, $infos) = $dbh->selectrow_array(qq|SHOW CREATE TABLE $table_name|);
501
    return $infos =~ m|CONSTRAINT `$constraint_name` FOREIGN KEY|;
502
}
503
504
sub index_exists {
505
    my ( $table_name, $key_name ) = @_;
506
    my $dbh = C4::Context->dbh;
507
    my ($exists) = $dbh->selectrow_array(
508
        qq|
509
        SHOW INDEX FROM $table_name
510
        WHERE key_name = ?
511
        |, undef, $key_name
512
    );
513
    return $exists;
514
}
515
516
sub column_exists {
517
    my ( $table_name, $column_name ) = @_;
518
    my $dbh = C4::Context->dbh;
519
    my ($exists) = $dbh->selectrow_array(
520
        qq|
521
        SHOW COLUMNS FROM $table_name
522
        WHERE Field = ?
523
        |, undef, $column_name
524
    );
525
    return $exists;
526
}
490
527
491
=head1 AUTHOR
528
=head1 AUTHOR
492
529
(-)a/t/db_dependent/Installer.t (-16 / +58 lines)
Lines 1-23 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
#
2
#
3
# This Koha test module is a stub!
3
# This file is part of Koha.
4
# Add more tests here!!!
4
#
5
# Bug 11541
5
# Copyright (C) 2014  Aleisha Amohia (Bug 11541)
6
# Copyright (C) 2016  Mark Tompsett (Bug 17234)
7
#
8
# Koha is free software; you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 3 of the License, or
11
# (at your option) any later version.
12
#
13
# Koha is distributed in the hope that it will be useful, but
14
# WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
6
20
7
use strict;
21
# This Koha test module is still a stub!
8
use warnings;
22
# Add more tests here!!!
9
23
10
use Test::More tests => 9;
24
use Modern::Perl;
25
use Test::More tests => 15;
26
use Koha::Database;
11
27
12
BEGIN {
28
BEGIN {
13
        use_ok('C4::Installer');
29
    use_ok('C4::Installer');
14
}
30
}
15
31
16
ok ( my $installer = C4::Installer->new(), 'Testing NewInstaller' );
32
ok( my $installer = C4::Installer->new(), 'Testing NewInstaller' );
17
is ( ref $installer, 'C4::Installer', 'Testing class of object' );
33
is( ref $installer, 'C4::Installer', 'Testing class of object' );
18
is ( $installer->{'dbname'},   C4::Context->config("database"), 'Testing DbName' );
34
is( $installer->{'dbname'}, C4::Context->config('database'), 'Testing DbName' );
19
is ( $installer->{'dbms'},     C4::Context->config("db_scheme") ? C4::Context->config("db_scheme") : "mysql", 'Testing DbScheme' );
35
is(
20
is ( $installer->{'hostname'}, C4::Context->config("hostname"), 'Testing Hostname' );
36
    $installer->{'dbms'},
21
is ( $installer->{'port'},     C4::Context->config("port"), 'Testing Port' );
37
    C4::Context->config('db_scheme')
22
is ( $installer->{'user'},     C4::Context->config("user"), 'Testing User' );
38
    ? C4::Context->config('db_scheme')
23
is ( $installer->{'password'}, C4::Context->config("pass"), 'Testing Password' );
39
    : 'mysql',
40
    'Testing DbScheme'
41
);
42
is(
43
    $installer->{'hostname'},
44
    C4::Context->config('hostname'),
45
    'Testing Hostname'
46
);
47
is( $installer->{'port'},     C4::Context->config('port'), 'Testing Port' );
48
is( $installer->{'user'},     C4::Context->config('user'), 'Testing User' );
49
is( $installer->{'password'}, C4::Context->config('pass'), 'Testing Password' );
50
51
# The borrower table is known to have columns and constraints.
52
my $schema = Koha::Database->new->schema;
53
my $source = $schema->source('Borrower');
54
55
my @column_names = $source->columns();
56
my $column_name  = $column_names[0];
57
ok( column_exists( 'borrowers', $column_name ), 'Known column does exist' );
58
ok( ! column_exists( 'borrowers', 'xxx'), 'Column xxx does not exist' );
59
60
my @constraint_names = $source->unique_constraint_names();
61
my $constraint_name  = $constraint_names[0];
62
ok( index_exists( 'borrowers', $constraint_name), 'Known contraint does exist' );
63
ok( ! index_exists( 'borrowers', 'xxx'), 'Constraint xxx does not exist' );
64
65
ok( foreign_key_exists( 'borrowers', 'borrowers_ibfk_1' ), 'FK borrowers_ibfk_1 exists' );
66
ok( ! foreign_key_exists( 'borrowers', 'xxx' ), 'FK xxxx does not exist' );
24
- 

Return to bug 17234