+ try {
+ $schema->storage->txn_do(sub {
+ $patron->set(\%borrower)->store;
+ # Don't add a new restriction if the existing 'combined' restriction matches this one
+ if ( $borrower{debarred} && ( ( $borrower{debarred} ne $member->{debarred} ) || ( $borrower{debarredcomment} ne $member->{debarredcomment} ) ) ) {
+
+ # Check to see if this debarment already exists
+ my $restrictions = $patron->restrictions->search(
+ {
+ expiration => $borrower{debarred},
+ comment => $borrower{debarredcomment}
+ }
+ );
+
+ # If it doesn't, then add it!
+ unless ($restrictions->count) {
+ AddDebarment(
+ {
+ borrowernumber => $borrowernumber,
+ expiration => $borrower{debarred},
+ comment => $borrower{debarredcomment}
+ }
+ );
+ }
+ }
+ if ($patron->category->category_type ne 'S' && $overwrite_passwords && defined $borrower{password} && $borrower{password} ne ''){
+ try {
+ $patron->set_password({ password => $borrower{password} });
+ }
+ catch {
+ if ( $_->isa('Koha::Exceptions::Password::TooShort') ) {
+ push @errors, { passwd_too_short => 1, borrowernumber => $borrowernumber, length => $_->{length}, min_length => $_->{min_length} };
+ }
+ elsif ( $_->isa('Koha::Exceptions::Password::WhitespaceCharacters') ) {
+ push @errors, { passwd_whitespace => 1, borrowernumber => $borrowernumber } ;
+ }
+ elsif ( $_->isa('Koha::Exceptions::Password::TooWeak') ) {
+ push @errors, { passwd_too_weak => 1, borrowernumber => $borrowernumber } ;
+ }
+ elsif ( $_->isa('Koha::Exceptions::Password::Plugin') ) {
+ push @errors, { passwd_plugin_err => 1, borrowernumber => $borrowernumber } ;
+ }
+ else {
+ push @errors, { passwd_unknown_err => 1, borrowernumber => $borrowernumber } ;
+ }
+ }
+ }
+ if ($extended && @$patron_attributes) {
+ if ($ext_preserve) {
+ $patron_attributes = $patron->extended_attributes->merge_and_replace_with( $patron_attributes );
+ }
+ # We do not want to filter by branch, maybe we should?
+ Koha::Patrons->find($borrowernumber)->extended_attributes->delete;
+ $patron->extended_attributes($patron_attributes);
+ }
+ $overwritten++;
+ push(
+ @feedback,
+ {
+ feedback => 1,
+ name => 'lastoverwritten',
+ value => $borrower{'surname'} . ' / ' . $borrowernumber
+ }
+ );
+ });
+ } catch {