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. |