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

(-)a/Koha/Patrons.pm (-13 / +15 lines)
Lines 260-282 sub merge { Link Here
260
260
261
    my $results;
261
    my $results;
262
262
263
    foreach my $borrowernumber (@borrowernumbers) {
263
    $self->_resultset->result_source->schema->txn_do( sub {
264
        my $patron = Koha::Patrons->find( $borrowernumber );
264
        foreach my $borrowernumber (@borrowernumbers) {
265
            my $patron = Koha::Patrons->find( $borrowernumber );
265
266
266
        next unless $patron;
267
            next unless $patron;
267
268
268
        # Unbless for safety, the patron will end up being deleted
269
            # Unbless for safety, the patron will end up being deleted
269
        $results->{merged}->{$borrowernumber}->{patron} = $patron->unblessed;
270
            $results->{merged}->{$borrowernumber}->{patron} = $patron->unblessed;
270
271
271
        while (my ($r, $field) = each(%$RESULTSET_PATRON_ID_MAPPING)) {
272
            while (my ($r, $field) = each(%$RESULTSET_PATRON_ID_MAPPING)) {
272
            my $rs = $schema->resultset($r)->search({ $field => $borrowernumber} );
273
                my $rs = $schema->resultset($r)->search({ $field => $borrowernumber} );
273
            $results->{merged}->{ $borrowernumber }->{updated}->{$r} = $rs->count();
274
                $results->{merged}->{ $borrowernumber }->{updated}->{$r} = $rs->count();
274
            $rs->update( { $field => $keeper });
275
                $rs->update( { $field => $keeper });
275
        }
276
            }
276
277
277
        $patron->move_to_deleted();
278
            $patron->move_to_deleted();
278
        $patron->delete();
279
            $patron->delete();
279
    }
280
        }
281
    });
280
282
281
    $results->{keeper} = $patron_to_keep;
283
    $results->{keeper} = $patron_to_keep;
282
284
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/merge-patrons.tt (-17 / +21 lines)
Lines 104-129 $(document).ready(function() { Link Here
104
            [% ELSIF action == 'merge' %]
104
            [% ELSIF action == 'merge' %]
105
                <h4>Results</h4>
105
                <h4>Results</h4>
106
106
107
                <p>
107
                [% IF error %]
108
                    Patron records merged into <a href="moremember.pl?borrowernumber=[% results.keeper.id %]">[% results.keeper.firstname %] [% results.keeper.surname %] ([% results.keeper.cardnumber | html %])</a>
108
                    <div class="dialog alert">Merge failed! The following error was reported: [% error %].</div>
109
                </p>
109
                [% ELSE %]
110
                    <p>
111
                        Patron records merged into <a href="moremember.pl?borrowernumber=[% results.keeper.id %]">[% results.keeper.firstname %] [% results.keeper.surname %] ([% results.keeper.cardnumber | html %])</a>
112
                    </p>
110
113
111
                [% FOREACH pair IN results.merged.pairs %]
114
                    [% FOREACH pair IN results.merged.pairs %]
112
                    [% SET patron = pair.value.patron %]
115
                        [% SET patron = pair.value.patron %]
113
116
114
                    <h5>[% patron.firstname %] [% patron.surname %] ([% patron.cardnumber %])</h5>
117
                        <h5>[% patron.firstname %] [% patron.surname %] ([% patron.cardnumber %])</h5>
115
118
116
                    [% USE Dumper %]
119
                        [% USE Dumper %]
117
                    [% FOREACH r IN pair.value.updated.pairs %]
120
                        [% FOREACH r IN pair.value.updated.pairs %]
118
                        [% SET name = r.key %]
121
                            [% SET name = r.key %]
119
                        [% SET count = r.value %]
122
                            [% SET count = r.value %]
120
                        [% IF count %]
123
                            [% IF count %]
121
                            <p>
124
                                <p>
122
                                [% count %] [% PROCESS display_names rs = name %] transferred.
125
                                    [% count %] [% PROCESS display_names rs = name %] transferred.
123
                                [% IF name == 'Reserve' %]
126
                                    [% IF name == 'Reserve' %]
124
                                    <strong>It is advisable to check for and resolve duplicate holds due to merging.</strong>
127
                                        <strong>It is advisable to check for and resolve duplicate holds due to merging.</strong>
125
                                [% END %]
128
                                    [% END %]
126
                            </p>
129
                                </p>
130
                            [% END %]
127
                        [% END %]
131
                        [% END %]
128
                    [% END %]
132
                    [% END %]
129
                [% END %]
133
                [% END %]
(-)a/members/merge-patrons.pl (-3 / +7 lines)
Lines 47-54 if ( $action eq 'show' ) { Link Here
47
    $template->param( patrons => $patrons );
47
    $template->param( patrons => $patrons );
48
} elsif ( $action eq 'merge' ) {
48
} elsif ( $action eq 'merge' ) {
49
    my $keeper = $cgi->param('keeper');
49
    my $keeper = $cgi->param('keeper');
50
    my $results = Koha::Patrons->merge( { keeper => $keeper, patrons => \@ids } );
50
    my $results;
51
    $template->param( results => $results );
51
    eval { $results = Koha::Patrons->merge( { keeper => $keeper, patrons => \@ids } ); };
52
    if ($@) {
53
        $template->param( results => $results );
54
    } else {
55
        $template->param( error => $@ );
56
    }
52
}
57
}
53
58
54
$template->param( action => $action );
59
$template->param( action => $action );
55
- 

Return to bug 9302