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

(-)a/C4/Context.pm (-62 lines)
Lines 97-105 environment variable to the pathname of a configuration file to use. Link Here
97
#    file (/etc/koha/koha-conf.xml).
97
#    file (/etc/koha/koha-conf.xml).
98
# dbh
98
# dbh
99
#    A handle to the appropriate database for this context.
99
#    A handle to the appropriate database for this context.
100
# dbh_stack
101
#    Used by &set_dbh and &restore_dbh to hold other database
102
#    handles for this context.
103
# Zconn
100
# Zconn
104
#     A connection object for the Zebra server
101
#     A connection object for the Zebra server
105
102
Lines 601-614 Returns a database handle connected to the Koha database for the Link Here
601
current context. If no connection has yet been made, this method
598
current context. If no connection has yet been made, this method
602
creates one, and connects to the database.
599
creates one, and connects to the database.
603
600
604
This database handle is cached for future use: if you call
605
C<C4::Context-E<gt>dbh> twice, you will get the same handle both
606
times. If you need a second database handle, use C<&new_dbh> and
607
possibly C<&set_dbh>.
608
609
=cut
601
=cut
610
602
611
#'
612
sub dbh
603
sub dbh
613
{
604
{
614
    my $self = shift;
605
    my $self = shift;
Lines 642-699 sub new_dbh Link Here
642
    return &dbh({ new => 1 });
633
    return &dbh({ new => 1 });
643
}
634
}
644
635
645
=head2 set_dbh
646
647
  $my_dbh = C4::Connect->new_dbh;
648
  C4::Connect->set_dbh($my_dbh);
649
  ...
650
  C4::Connect->restore_dbh;
651
652
C<&set_dbh> saves the current database handle on a stack, then sets
653
the current database handle to C<$my_dbh>.
654
655
C<$my_dbh> is assumed to be a good database handle.
656
657
=cut
658
659
#'
660
sub set_dbh
661
{
662
    my $self = shift;
663
    my $new_dbh = shift;
664
665
    # Save the current database handle on the handle stack.
666
    # We assume that $new_dbh is all good: if the caller wants to
667
    # screw himself by passing an invalid handle, that's fine by
668
    # us.
669
    push @{$context->{"dbh_stack"}}, $context->{"dbh"};
670
    $context->{"dbh"} = $new_dbh;
671
}
672
673
=head2 restore_dbh
674
675
  C4::Context->restore_dbh;
676
677
Restores the database handle saved by an earlier call to
678
C<C4::Context-E<gt>set_dbh>.
679
680
=cut
681
682
#'
683
sub restore_dbh
684
{
685
    my $self = shift;
686
687
    if ($#{$context->{"dbh_stack"}} < 0)
688
    {
689
        # Stack underflow
690
        die "DBH stack underflow";
691
    }
692
693
    # Pop the old database handle and set it.
694
    $context->{"dbh"} = pop @{$context->{"dbh_stack"}};
695
}
696
697
=head2 userenv
636
=head2 userenv
698
637
699
  C4::Context->userenv;
638
  C4::Context->userenv;
700
- 

Return to bug 36367