From ff82be052e59c21cb53825dc4137372e60f008b4 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 8 Mar 2024 14:33:29 +0100 Subject: [PATCH] Bug 36367: Remove schema_stack Same pattern in Koha::Database Signed-off-by: Julian Maurice --- Koha/Database.pm | 77 +--------------------------------- t/db_dependent/Koha_Database.t | 7 +--- 2 files changed, 2 insertions(+), 82 deletions(-) diff --git a/Koha/Database.pm b/Koha/Database.pm index 87bc53de7f..8457c18e80 100644 --- a/Koha/Database.pm +++ b/Koha/Database.pm @@ -166,8 +166,7 @@ creates one, and connects to the database. This database handle is cached for future use: if you call C<$database-Eschema> 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 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-Eset_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); diff --git a/t/db_dependent/Koha_Database.t b/t/db_dependent/Koha_Database.t index d950cb9ad7..dd51feb707 100755 --- a/t/db_dependent/Koha_Database.t +++ b/t/db_dependent/Koha_Database.t @@ -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(); -- 2.30.2