use Modern::Perl;
use CGI qw ( -utf8 );
+use Try::Tiny;
use C4::Auth;
use C4::Output;
query => $cgi,
type => "intranet",
authnotrequired => 0,
- flagsrequired => { borrowers => 1 },
- debug => 1,
+ flagsrequired => { borrowers => 'edit_borrowers' },
}
);
my $action = $cgi->param('action') || 'show';
-my @ids = $cgi->multi_param('id');
+my @ids = $cgi->multi_param('id');
if ( $action eq 'show' ) {
- my $patrons =
- Koha::Patrons->search( { borrowernumber => { -in => \@ids } } );
+ my $patrons = Koha::Patrons->search({ borrowernumber => { -in => \@ids } });
$template->param( patrons => $patrons );
} elsif ( $action eq 'merge' ) {
- my $keeper = $cgi->param('keeper');
- my $results = Koha::Patrons->merge( { keeper => $keeper, patrons => \@ids } );
- $template->param( results => $results );
+ my $keeper_id = $cgi->param('keeper');
+ my $results;
+
+ my $keeper = Koha::Patrons->find( $keeper_id );
+
+ if ( $keeper ) {
+ try {
+ $results = $keeper->merge_with( \@ids );
+ $template->param(
+ keeper => $keeper,
+ results => $results
+ );
+ }
+ catch {
+ $template->param( error => $_ );
+ }
+ } else {
+ $template->param( error => 'INVALID_KEEPER' );
+ }
}
$template->param( action => $action );