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

(-)a/Koha/Database.pm (-9 / +11 lines)
Lines 38-43 use C4::Context; Link Here
38
use Koha::Schema;
38
use Koha::Schema;
39
use base qw(Class::Accessor);
39
use base qw(Class::Accessor);
40
40
41
use vars qw($database);
42
41
__PACKAGE__->mk_accessors(qw( ));
43
__PACKAGE__->mk_accessors(qw( ));
42
44
43
# _new_schema
45
# _new_schema
Lines 72-85 possibly C<&set_schema>. Link Here
72
sub schema {
74
sub schema {
73
    my $self = shift;
75
    my $self = shift;
74
    my $sth;
76
    my $sth;
75
    if ( defined( $self->{"schema"} ) && $self->{"schema"}->storage->connected() ) {
77
76
        return $self->{"schema"};
78
    if ( defined( $database->{schema} ) and $database->{schema}->storage->connected() ) {
79
        return $database->{schema};
77
    }
80
    }
78
81
79
    # No database handle or it died . Create one.
82
    # No database handle or it died . Create one.
80
    $self->{"schema"} = &_new_schema();
83
    $database->{schema} = &_new_schema();
81
84
    return $database->{schema};
82
    return $self->{"schema"};
83
}
85
}
84
86
85
=head2 new_schema
87
=head2 new_schema
Lines 127-134 sub set_schema { Link Here
127
    # We assume that $new_schema is all good: if the caller wants to
129
    # We assume that $new_schema is all good: if the caller wants to
128
    # screw himself by passing an invalid handle, that's fine by
130
    # screw himself by passing an invalid handle, that's fine by
129
    # us.
131
    # us.
130
    push @{ $self->{"schema_stack"} }, $self->{"schema"};
132
    push @{ $database->{schema_stack} }, $database->{schema};
131
    $self->{"schema"} = $new_schema;
133
    $database->{schema} = $new_schema;
132
}
134
}
133
135
134
=head2 restore_schema
136
=head2 restore_schema
Lines 143-156 C<$database-E<gt>set_schema>. Link Here
143
sub restore_schema {
145
sub restore_schema {
144
    my $self = shift;
146
    my $self = shift;
145
147
146
    if ( $#{ $self->{"schema_stack"} } < 0 ) {
148
    if ( $#{ $database->{schema_stack} } < 0 ) {
147
149
148
        # Stack underflow
150
        # Stack underflow
149
        die "SCHEMA stack underflow";
151
        die "SCHEMA stack underflow";
150
    }
152
    }
151
153
152
    # Pop the old database handle and set it.
154
    # Pop the old database handle and set it.
153
    $self->{"schema"} = pop @{ $self->{"schema_stack"} };
155
    $database->{schema} = pop @{ $database->{schema_stack} };
154
156
155
    # FIXME - If it is determined that restore_context should
157
    # FIXME - If it is determined that restore_context should
156
    # return something, then this function should, too.
158
    # return something, then this function should, too.
(-)a/t/db_dependent/Koha_Database.t (-3 / +6 lines)
Lines 4-10 Link Here
4
use Modern::Perl;
4
use Modern::Perl;
5
use utf8;
5
use utf8;
6
6
7
use Test::More tests => 10;
7
use Test::More tests => 12;
8
8
9
BEGIN {
9
BEGIN {
10
    use_ok('Koha::Database');
10
    use_ok('Koha::Database');
Lines 18-24 ok( $schema = $database->schema(), 'Get a schema' ); Link Here
18
my $dbh;
18
my $dbh;
19
ok( $dbh = $schema->storage->dbh(), 'Get an old fashioned DBI dbh handle' );
19
ok( $dbh = $schema->storage->dbh(), 'Get an old fashioned DBI dbh handle' );
20
ok( $schema->storage->connected(), 'Check our db connection is active' );
20
ok( $schema->storage->connected(), 'Check our db connection is active' );
21
ok( $schema = $database->schema(), 'Try and get the same schema' );
21
is( ref($schema), 'Koha::Schema', 'Koha::Database->new->schema should return a Koha::Schema' );
22
my $another_schema = $database->schema();
23
is( $another_schema->storage->_conn_pid, $schema->storage->_conn_pid, 'Getting another schema should return the same one, it has correctly been cached' );
24
$another_schema = Koha::Database->new->schema();
25
is( $another_schema->storage->_conn_pid, $schema->storage->_conn_pid, 'Getting another schema should return the same one, it has correctly been cached' );
22
26
23
my $new_schema;
27
my $new_schema;
24
ok( $new_schema = $database->new_schema(), 'Try to get a new schema' );
28
ok( $new_schema = $database->new_schema(), 'Try to get a new schema' );
25
- 

Return to bug 13645