Bug 36367: Remove schema_stack
Same pattern in Koha::Database Signed-off-by: Julian Maurice <julian.maurice@biblibre.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
f4ed78de2c
commit
fbb5cd98f9
2 changed files with 2 additions and 82 deletions
|
@ -166,8 +166,7 @@ creates one, and connects to the database.
|
|||
|
||||
This database handle is cached for future use: if you call
|
||||
C<$database-E<gt>schema> twice, you will get the same handle both
|
||||
times. If you need a second database handle, use C<&new_schema> and
|
||||
possibly C<&set_schema>.
|
||||
times.
|
||||
|
||||
=cut
|
||||
|
||||
|
@ -182,80 +181,6 @@ sub schema {
|
|||
return $database->{schema};
|
||||
}
|
||||
|
||||
=head2 new_schema
|
||||
|
||||
$schema = $database->new_schema;
|
||||
|
||||
Creates a new connection to the Koha database for the current context,
|
||||
and returns the database handle (a C<DBI::db> object).
|
||||
|
||||
The handle is not saved anywhere: this method is strictly a
|
||||
convenience function; the point is that it knows which database to
|
||||
connect to so that the caller doesn't have to know.
|
||||
|
||||
=cut
|
||||
|
||||
#'
|
||||
sub new_schema {
|
||||
my $self = shift;
|
||||
|
||||
return &_new_schema();
|
||||
}
|
||||
|
||||
=head2 set_schema
|
||||
|
||||
$my_schema = $database->new_schema;
|
||||
$database->set_schema($my_schema);
|
||||
...
|
||||
$database->restore_schema;
|
||||
|
||||
C<&set_schema> and C<&restore_schema> work in a manner analogous to
|
||||
C<&set_context> and C<&restore_context>.
|
||||
|
||||
C<&set_schema> saves the current database handle on a stack, then sets
|
||||
the current database handle to C<$my_schema>.
|
||||
|
||||
C<$my_schema> is assumed to be a good database handle.
|
||||
|
||||
=cut
|
||||
|
||||
sub set_schema {
|
||||
my $self = shift;
|
||||
my $new_schema = shift;
|
||||
|
||||
# Save the current database handle on the handle stack.
|
||||
# We assume that $new_schema is all good: if the caller wants to
|
||||
# screw himself by passing an invalid handle, that's fine by
|
||||
# us.
|
||||
push @{ $database->{schema_stack} }, $database->{schema};
|
||||
$database->{schema} = $new_schema;
|
||||
}
|
||||
|
||||
=head2 restore_schema
|
||||
|
||||
$database->restore_schema;
|
||||
|
||||
Restores the database handle saved by an earlier call to
|
||||
C<$database-E<gt>set_schema>.
|
||||
|
||||
=cut
|
||||
|
||||
sub restore_schema {
|
||||
my $self = shift;
|
||||
|
||||
if ( $#{ $database->{schema_stack} } < 0 ) {
|
||||
|
||||
# Stack underflow
|
||||
die "SCHEMA stack underflow";
|
||||
}
|
||||
|
||||
# Pop the old database handle and set it.
|
||||
$database->{schema} = pop @{ $database->{schema_stack} };
|
||||
|
||||
# FIXME - If it is determined that restore_context should
|
||||
# return something, then this function should, too.
|
||||
}
|
||||
|
||||
=head2 db_scheme2dbi
|
||||
|
||||
my $dbd_driver_name = Koha::Database::db_scheme2dbi($scheme);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
use Modern::Perl;
|
||||
use utf8;
|
||||
|
||||
use Test::More tests => 12;
|
||||
use Test::More tests => 9;
|
||||
|
||||
BEGIN {
|
||||
use_ok('Koha::Database');
|
||||
|
@ -24,11 +24,6 @@ is( $another_schema->storage->_conn_pid, $schema->storage->_conn_pid, 'Getting a
|
|||
$another_schema = Koha::Database->new->schema();
|
||||
is( $another_schema->storage->_conn_pid, $schema->storage->_conn_pid, 'Getting another schema should return the same one, it has correctly been cached' );
|
||||
|
||||
my $new_schema;
|
||||
ok( $new_schema = $database->new_schema(), 'Try to get a new schema' );
|
||||
ok( $database->set_schema($new_schema), 'Switch to new schema' );
|
||||
ok( $database->restore_schema(), 'Switch back' );
|
||||
|
||||
# run in a transaction
|
||||
$schema->storage->txn_begin();
|
||||
|
||||
|
|
Loading…
Reference in a new issue