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

(-)a/C4/SIP/ILS/Patron.pm (-7 / +40 lines)
Lines 15-21 use Carp; Link Here
15
use Sys::Syslog qw(syslog);
15
use Sys::Syslog qw(syslog);
16
use Data::Dumper;
16
use Data::Dumper;
17
17
18
use C4::SIP::Sip qw(add_field);
18
use C4::SIP::Sip qw(add_field maybe_add);
19
19
20
use C4::Debug;
20
use C4::Debug;
21
use C4::Context;
21
use C4::Context;
Lines 216-222 sub AUTOLOAD { Link Here
216
    }
216
    }
217
}
217
}
218
218
219
sub name {
219
=head2 format
220
221
This method uses a template to build a string from a Koha::Patron object
222
If errors are encountered in processing template we log them and return nothing
223
224
=cut
225
226
sub format {
220
    my ( $self, $template ) = @_;
227
    my ( $self, $template ) = @_;
221
228
222
    if ($template) {
229
    if ($template) {
Lines 228-239 sub name { Link Here
228
        my $patron = Koha::Patrons->find( $self->{borrowernumber} );
235
        my $patron = Koha::Patrons->find( $self->{borrowernumber} );
229
236
230
        my $output;
237
        my $output;
231
        $tt->process( \$template, { patron => $patron }, \$output );
238
        eval {
239
            $tt->process( \$template, { patron => $patron }, \$output );
240
        };
241
        if ( $@ ){
242
            syslog("LOG_DEBUG", "Error processing template: $template");
243
            return "";
244
        }
232
        return $output;
245
        return $output;
233
    }
246
    }
234
    else {
235
        return $self->{name};
236
    }
237
}
247
}
238
248
239
sub check_password {
249
sub check_password {
Lines 528-534 sub build_patron_attributes_string { Link Here
528
    my ( $self, $server ) = @_;
538
    my ( $self, $server ) = @_;
529
539
530
    my $string = q{};
540
    my $string = q{};
531
532
    if ( $server->{account}->{patron_attribute} ) {
541
    if ( $server->{account}->{patron_attribute} ) {
533
        my @attributes_to_send =
542
        my @attributes_to_send =
534
          ref $server->{account}->{patron_attribute} eq "ARRAY"
543
          ref $server->{account}->{patron_attribute} eq "ARRAY"
Lines 553-558 sub build_patron_attributes_string { Link Here
553
    return $string;
562
    return $string;
554
}
563
}
555
564
565
566
=head2 build_custom_field_string
567
568
This method builds the part of the sip message for custom patron fields as defined in the sip config
569
570
=cut
571
572
sub build_custom_field_string {
573
    my ( $self, $server ) = @_;
574
575
    my $string = q{};
576
577
    if ( $server->{account}->{custom_patron_field} ) {
578
        my @custom_fields =
579
            ref $server->{account}->{custom_patron_field} eq "ARRAY"
580
            ? @{ $server->{account}->{custom_patron_field} }
581
            : $server->{account}->{custom_patron_field};
582
        foreach my $custom_field ( @custom_fields ) {
583
            $string .= maybe_add( $custom_field->{field}, $self->format( $custom_field->{template} ) ) if defined $custom_field->{field};
584
        }
585
    }
586
    return $string;
587
}
588
556
1;
589
1;
557
__END__
590
__END__
558
591
(-)a/C4/SIP/Sip.pm (-1 lines)
Lines 108-114 sub maybe_add { Link Here
108
            $value =~ s/$regex->{find}/$regex->{replace}/g;
108
            $value =~ s/$regex->{find}/$regex->{replace}/g;
109
        }
109
        }
110
    }
110
    }
111
112
    return (defined($value) && $value) ? add_field($fid, $value) : '';
111
    return (defined($value) && $value) ? add_field($fid, $value) : '';
113
}
112
}
114
113
(-)a/C4/SIP/Sip/MsgType.pm (-3 / +14 lines)
Lines 435-441 sub build_patron_status { Link Here
435
435
436
        $resp .= patron_status_string($patron);
436
        $resp .= patron_status_string($patron);
437
        $resp .= $lang . timestamp();
437
        $resp .= $lang . timestamp();
438
        $resp .= add_field( FID_PERSONAL_NAME, $patron->name( $server->{account}->{ae_field_template} ), $server );
438
        if ( defined $server->{account}->{ae_field_template} ) {
439
            $resp .= add_field( FID_PERSONAL_NAME, $patron->format( $server->{account}->{ae_field_template}, $server ) );
440
        } else {
441
            $resp .= add_field( FID_PERSONAL_NAME, $patron->name, $server );
442
        }
443
439
444
440
        # while the patron ID we got from the SC is valid, let's
445
        # while the patron ID we got from the SC is valid, let's
441
        # use the one returned from the ILS, just in case...
446
        # use the one returned from the ILS, just in case...
Lines 458-463 sub build_patron_status { Link Here
458
          if ( $server->{account}->{send_patron_home_library_in_af} );
463
          if ( $server->{account}->{send_patron_home_library_in_af} );
459
        $resp .= maybe_add( FID_PRINT_LINE, $patron->print_line, $server );
464
        $resp .= maybe_add( FID_PRINT_LINE, $patron->print_line, $server );
460
465
466
        $resp .= $patron->build_custom_field_string( $server );
461
        $resp .= $patron->build_patron_attributes_string( $server );
467
        $resp .= $patron->build_patron_attributes_string( $server );
462
468
463
    } else {
469
    } else {
Lines 971-977 sub handle_patron_info { Link Here
971
        # while the patron ID we got from the SC is valid, let's
977
        # while the patron ID we got from the SC is valid, let's
972
        # use the one returned from the ILS, just in case...
978
        # use the one returned from the ILS, just in case...
973
        $resp .= add_field( FID_PATRON_ID,     $patron->id, $server );
979
        $resp .= add_field( FID_PATRON_ID,     $patron->id, $server );
974
        $resp .= add_field( FID_PERSONAL_NAME, $patron->name( $server->{account}->{ae_field_template} ), $server );
980
        if ( defined $server->{account}->{ae_field_template} ) {
981
            $resp .= add_field( FID_PERSONAL_NAME, $patron->format( $server->{account}->{ae_field_template} ), $server );
982
        } else {
983
            $resp .= add_field( FID_PERSONAL_NAME, $patron->name, $server );
984
        }
975
985
976
        # TODO: add code for the fields
986
        # TODO: add code for the fields
977
        #   hold items limit
987
        #   hold items limit
Lines 1026-1031 sub handle_patron_info { Link Here
1026
        }
1036
        }
1027
        $resp .= maybe_add( FID_PRINT_LINE, $patron->print_line, $server );
1037
        $resp .= maybe_add( FID_PRINT_LINE, $patron->print_line, $server );
1028
1038
1039
        $resp .= $patron->build_custom_field_string( $server );
1029
        $resp .= $patron->build_patron_attributes_string( $server );
1040
        $resp .= $patron->build_patron_attributes_string( $server );
1030
    } else {
1041
    } else {
1031
1042
Lines 1274-1280 sub handle_patron_enable { Link Here
1274
        $resp .= $patron->language . timestamp();
1285
        $resp .= $patron->language . timestamp();
1275
1286
1276
        $resp .= add_field( FID_PATRON_ID,     $patron->id, $server );
1287
        $resp .= add_field( FID_PATRON_ID,     $patron->id, $server );
1277
        $resp .= add_field( FID_PERSONAL_NAME, $patron->name( $server->{account}->{ae_field_template} ), $server );
1288
        $resp .= add_field( FID_PERSONAL_NAME, $patron->format( $server->{account}->{ae_field_template} ), $server );
1278
        if ( defined($patron_pwd) ) {
1289
        if ( defined($patron_pwd) ) {
1279
            $resp .= add_field( FID_VALID_PATRON_PWD, sipbool( $patron->check_password($patron_pwd) ), $server );
1290
            $resp .= add_field( FID_VALID_PATRON_PWD, sipbool( $patron->check_password($patron_pwd) ), $server );
1280
        }
1291
        }
(-)a/etc/SIPconfig.xml (+1 lines)
Lines 65-70 Link Here
65
          <syspref_overrides>
65
          <syspref_overrides>
66
              <AllFinesNeedOverride>0</AllFinesNeedOverride>
66
              <AllFinesNeedOverride>0</AllFinesNeedOverride>
67
          </syspref_overrides>
67
          </syspref_overrides>
68
          <custom_patron_field field="DE" template="[% patron.dateexpiry %]" />
68
      </login>
69
      </login>
69
  </accounts>
70
  </accounts>
70
71
(-)a/t/db_dependent/SIP/Message.t (-7 / +10 lines)
Lines 326-336 sub test_checkin_v2 { Link Here
326
    my $card1 = $patron1->{cardnumber};
326
    my $card1 = $patron1->{cardnumber};
327
    my $sip_patron1 = C4::SIP::ILS::Patron->new( $card1 );
327
    my $sip_patron1 = C4::SIP::ILS::Patron->new( $card1 );
328
    $findpatron = $sip_patron1;
328
    $findpatron = $sip_patron1;
329
    my $item = $builder->build({
329
    my $item_object = $builder->build_sample_item({
330
        source => 'Item',
330
        damaged => 0,
331
        value => { damaged => 0, withdrawn => 0, itemlost => 0, restricted => 0, homebranch => $branchcode, holdingbranch => $branchcode },
331
        withdrawn => 0,
332
        itemlost => 0,
333
        restricted => 0,
334
        homebranch => $branchcode,
335
        holdingbranch => $branchcode,
332
    });
336
    });
333
    my $item_object = Koha::Items->find( $item->{itemnumber} );
334
337
335
    my $mockILS = $mocks->{ils};
338
    my $mockILS = $mocks->{ils};
336
    my $server = { ils => $mockILS, account => {} };
339
    my $server = { ils => $mockILS, account => {} };
Lines 364-370 sub test_checkin_v2 { Link Here
364
    $siprequest = CHECKIN . 'N' . 'YYYYMMDDZZZZHHMMSS' .
367
    $siprequest = CHECKIN . 'N' . 'YYYYMMDDZZZZHHMMSS' .
365
        siprequestdate( $today->clone->add( days => 1) ) .
368
        siprequestdate( $today->clone->add( days => 1) ) .
366
        FID_INST_ID . $branchcode . '|'.
369
        FID_INST_ID . $branchcode . '|'.
367
        FID_ITEM_ID . $item->{barcode} . '|' .
370
        FID_ITEM_ID . $item_object->barcode . '|' .
368
        FID_TERMINAL_PWD . 'ignored' . '|';
371
        FID_TERMINAL_PWD . 'ignored' . '|';
369
    undef $response;
372
    undef $response;
370
    $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 );
373
    $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 );
Lines 443-449 sub test_checkin_v2 { Link Here
443
    $server->{account}->{ct_always_send} = 0;
446
    $server->{account}->{ct_always_send} = 0;
444
447
445
    # Checkin at wrong branch: issue item and switch branch, and checkin
448
    # Checkin at wrong branch: issue item and switch branch, and checkin
446
    my $issue = Koha::Checkout->new({ branchcode => $branchcode, borrowernumber => $patron1->{borrowernumber}, itemnumber => $item->{itemnumber} })->store;
449
    my $issue = Koha::Checkout->new({ branchcode => $branchcode, borrowernumber => $patron1->{borrowernumber}, itemnumber => $item_object->itemnumber })->store;
447
    $branchcode = $builder->build({ source => 'Branch' })->{branchcode};
450
    $branchcode = $builder->build({ source => 'Branch' })->{branchcode};
448
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
451
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
449
    undef $response;
452
    undef $response;
Lines 452-458 sub test_checkin_v2 { Link Here
452
    is( substr($response,2,1), '0', 'OK flag is false when we check in at the wrong branch and we do not allow it' );
455
    is( substr($response,2,1), '0', 'OK flag is false when we check in at the wrong branch and we do not allow it' );
453
    is( substr($response,5,1), 'Y', 'Alert flag is set' );
456
    is( substr($response,5,1), 'Y', 'Alert flag is set' );
454
    check_field( $respcode, $response, FID_SCREEN_MSG, 'Checkin failed', 'Check screen msg' );
457
    check_field( $respcode, $response, FID_SCREEN_MSG, 'Checkin failed', 'Check screen msg' );
455
    $branchcode = $item->{homebranch};  # switch back
458
    $branchcode = $item_object->homebranch;  # switch back
456
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
459
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
457
460
458
    # Data corrupted: add same issue_id to old_issues
461
    # Data corrupted: add same issue_id to old_issues
(-)a/t/db_dependent/SIP/Patron.t (-1 / +45 lines)
Lines 4-10 Link Here
4
# This needs to be extended! Your help is appreciated..
4
# This needs to be extended! Your help is appreciated..
5
5
6
use Modern::Perl;
6
use Modern::Perl;
7
use Test::More tests => 5;
7
use Test::More tests => 6;
8
8
9
use Koha::Database;
9
use Koha::Database;
10
use Koha::Patrons;
10
use Koha::Patrons;
Lines 116-121 subtest "Test build_patron_attribute_string" => sub { Link Here
116
    is( $attribute_string, "XYTest Attribute|YZAnother Test Attribute|", 'Attribute field generated correctly with multiple params' );
116
    is( $attribute_string, "XYTest Attribute|YZAnother Test Attribute|", 'Attribute field generated correctly with multiple params' );
117
};
117
};
118
118
119
subtest "Test build_custom_field_string" => sub {
120
121
    plan tests => 5;
122
123
    my $patron = $builder->build_object( { class => 'Koha::Patrons',value=>{surname => "Duck", firstname => "Darkwing"} } );
124
125
126
    my $ils_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
127
128
    my $server = {};
129
    $server->{account}->{custom_patron_field}->{field} = "DW";
130
    my $attribute_string = $ils_patron->build_custom_field_string( $server );
131
    is( $attribute_string, "", 'Custom field not generated if no value passed' );
132
133
    $server = {};
134
    $server->{account}->{custom_patron_field}->{template} = "[% patron.surname %]";
135
    $attribute_string = $ils_patron->build_custom_field_string( $server );
136
    is( $attribute_string, "", 'Custom field not generated if no field passed' );
137
138
139
    $server = {};
140
    $server->{account}->{custom_patron_field}->{field} = "DW";
141
    $server->{account}->{custom_patron_field}->{template} = "[% patron.firstname %] [% patron.surname %], let's get dangerous!";
142
    $attribute_string = $ils_patron->build_custom_field_string( $server );
143
    is( $attribute_string, "DWDarkwing Duck, let's get dangerous!|", 'Custom field processed correctly' );
144
145
    $server = {};
146
    $server->{account}->{custom_patron_field}->[0]->{field} = "DW";
147
    $server->{account}->{custom_patron_field}->[0]->{template} = "[% patron.firstname %] [% patron.surname %], let's get dangerous!";
148
    $server->{account}->{custom_patron_field}->[1]->{field} = "LM";
149
    $server->{account}->{custom_patron_field}->[1]->{template} = "Launchpad McQuack crashed on [% patron.dateexpiry %]";
150
    $attribute_string = $ils_patron->build_custom_field_string( $server );
151
    is( $attribute_string, "DWDarkwing Duck, let's get dangerous!|LMLaunchpad McQuack crashed on ".$patron->dateexpiry."|", 'Custom fields processed correctly when multiple exist' );
152
153
    $server = {};
154
    $server->{account}->{custom_patron_field}->[0]->{field} = "DW";
155
    $server->{account}->{custom_patron_field}->[0]->{template} = "[% IF (patron.firstname) %] patron.surname, let's get dangerous!";
156
    $server->{account}->{custom_patron_field}->[1]->{field} = "LM";
157
    $server->{account}->{custom_patron_field}->[1]->{template} = "Launchpad McQuack crashed on [% patron.dateexpiry %]";
158
    $attribute_string = $ils_patron->build_custom_field_string( $server );
159
    is( $attribute_string, "LMLaunchpad McQuack crashed on ".$patron->dateexpiry."|", 'Custom fields processed correctly, bad template generate no text' );
160
161
};
162
119
subtest "update_lastseen tests" => sub {
163
subtest "update_lastseen tests" => sub {
120
    plan tests => 2;
164
    plan tests => 2;
121
165
(-)a/t/db_dependent/SIP/Transaction.t (-14 / +8 lines)
Lines 49-73 subtest fill_holds_at_checkout => sub { Link Here
49
    t::lib::Mocks::mock_userenv({ branchcode => $branch->{branchcode}, flags => 1 });
49
    t::lib::Mocks::mock_userenv({ branchcode => $branch->{branchcode}, flags => 1 });
50
50
51
    my $itype = $builder->build({ source => 'Itemtype', value =>{notforloan=>0} });
51
    my $itype = $builder->build({ source => 'Itemtype', value =>{notforloan=>0} });
52
    my $biblio = $builder->build({ source => 'Biblio' });
52
    my $item1 = $builder->build_sample_item({
53
    my $biblioitem = $builder->build({ source => 'Biblioitem', value=>{biblionumber=>$biblio->{biblionumber}} });
54
    my $item1 = $builder->build({ source => 'Item', value => {
55
        barcode       => 'barcode4test',
53
        barcode       => 'barcode4test',
56
        homebranch    => $branch->{branchcode},
54
        homebranch    => $branch->{branchcode},
57
        holdingbranch => $branch->{branchcode},
55
        holdingbranch => $branch->{branchcode},
58
        biblionumber  => $biblio->{biblionumber},
59
        itype         => $itype->{itemtype},
56
        itype         => $itype->{itemtype},
60
        notforloan       => 0,
57
        notforloan       => 0,
61
        }
58
    })->unblessed;
62
    });
59
    my $item2 = $builder->build_sample_item({
63
    my $item2 = $builder->build({ source => 'Item', value => {
64
        homebranch    => $branch->{branchcode},
60
        homebranch    => $branch->{branchcode},
65
        holdingbranch => $branch->{branchcode},
61
        holdingbranch => $branch->{branchcode},
66
        biblionumber  => $biblio->{biblionumber},
62
        biblionumber  => $item1->{biblionumber},
67
        itype         => $itype->{itemtype},
63
        itype         => $itype->{itemtype},
68
        notforloan       => 0,
64
        notforloan       => 0,
69
        }
65
    })->unblessed;
70
    });
71
66
72
    Koha::IssuingRule->new({
67
    Koha::IssuingRule->new({
73
        categorycode     => $borrower->{categorycode},
68
        categorycode     => $borrower->{categorycode},
Lines 80-88 subtest fill_holds_at_checkout => sub { Link Here
80
        lengthunit       => 'days',
75
        lengthunit       => 'days',
81
    })->store;
76
    })->store;
82
77
83
    my $reserve1 = AddReserve($branch->{branchcode},$borrower->{borrowernumber},$biblio->{biblionumber});
78
    my $reserve1 = AddReserve($branch->{branchcode},$borrower->{borrowernumber},$item1->{biblionumber});
84
    my $reserve2 = AddReserve($branch->{branchcode},$borrower->{borrowernumber},$biblio->{biblionumber});
79
    my $reserve2 = AddReserve($branch->{branchcode},$borrower->{borrowernumber},$item1->{biblionumber});
85
    my $bib = Koha::Biblios->find( $biblio->{biblionumber} );
80
    my $bib = Koha::Biblios->find( $item1->{biblionumber} );
86
    is( $bib->holds->count(), 2, "Bib has 2 holds");
81
    is( $bib->holds->count(), 2, "Bib has 2 holds");
87
82
88
    my $sip_patron = C4::SIP::ILS::Patron->new( $borrower->{cardnumber} );
83
    my $sip_patron = C4::SIP::ILS::Patron->new( $borrower->{cardnumber} );
89
- 

Return to bug 20816