From 69dba73e62c990cf8272de32a0a2773020aa0990 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 4 Nov 2015 07:47:57 -0500 Subject: [PATCH] Bug 15124 - Tidy relevent code --- C4/SIP/Sip/MsgType.pm | 255 +++++++++++++++++++++++++------------------------ 1 files changed, 132 insertions(+), 123 deletions(-) diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm index 6b387cf..24fdc66 100644 --- a/C4/SIP/Sip/MsgType.pm +++ b/C4/SIP/Sip/MsgType.pm @@ -437,38 +437,40 @@ sub build_patron_status { my $resp = (PATRON_STATUS_RESP); if ($patron) { - $resp .= patron_status_string($patron); - $resp .= $lang . timestamp(); - $resp .= add_field(FID_PERSONAL_NAME, $patron->name); + $resp .= patron_status_string($patron); + $resp .= $lang . timestamp(); + $resp .= add_field( FID_PERSONAL_NAME, $patron->name ); - # while the patron ID we got from the SC is valid, let's - # use the one returned from the ILS, just in case... - $resp .= add_field(FID_PATRON_ID, $patron->id); - if ($protocol_version >= 2) { - $resp .= add_field(FID_VALID_PATRON, 'Y'); - # Patron password is a required field. - $resp .= add_field(FID_VALID_PATRON_PWD, sipbool($patron->check_password($patron_pwd))); - $resp .= maybe_add(FID_CURRENCY, $patron->currency); - $resp .= maybe_add(FID_FEE_AMT, $patron->fee_amount); - } + # while the patron ID we got from the SC is valid, let's + # use the one returned from the ILS, just in case... + $resp .= add_field( FID_PATRON_ID, $patron->id ); + if ( $protocol_version >= 2 ) { + $resp .= add_field( FID_VALID_PATRON, 'Y' ); + + # Patron password is a required field. + $resp .= add_field( FID_VALID_PATRON_PWD, sipbool( $patron->check_password($patron_pwd) ) ); + $resp .= maybe_add( FID_CURRENCY, $patron->currency ); + $resp .= maybe_add( FID_FEE_AMT, $patron->fee_amount ); + } - $resp .= maybe_add( FID_SCREEN_MSG, $patron->screen_msg, $server ); - $resp .= maybe_add( FID_SCREEN_MSG, $patron->{branchcode}, $server ) - if ( $server->{account}->{send_patron_home_library_in_af} ); + $resp .= maybe_add( FID_SCREEN_MSG, $patron->screen_msg, $server ); + $resp .= maybe_add( FID_SCREEN_MSG, $patron->{branchcode}, $server ) + if ( $server->{account}->{send_patron_home_library_in_af} ); - $resp .= maybe_add(FID_PRINT_LINE, $patron->print_line); - } else { - # Invalid patron id. Report that the user has no privs., - # no personal name, and is invalid (if we're using 2.00) - $resp .= 'YYYY' . (' ' x 10) . $lang . timestamp(); - $resp .= add_field(FID_PERSONAL_NAME, ''); + $resp .= maybe_add( FID_PRINT_LINE, $patron->print_line ); + } + else { + # Invalid patron id. Report that the user has no privs., + # no personal name, and is invalid (if we're using 2.00) + $resp .= 'YYYY' . ( ' ' x 10 ) . $lang . timestamp(); + $resp .= add_field( FID_PERSONAL_NAME, '' ); - # the patron ID is invalid, but it's a required field, so - # just echo it back - $resp .= add_field(FID_PATRON_ID, $fields->{(FID_PATRON_ID)}); + # the patron ID is invalid, but it's a required field, so + # just echo it back + $resp .= add_field( FID_PATRON_ID, $fields->{ (FID_PATRON_ID) } ); - ($protocol_version >= 2) and - $resp .= add_field(FID_VALID_PATRON, 'N'); + ( $protocol_version >= 2 ) + and $resp .= add_field( FID_VALID_PATRON, 'N' ); } $resp .= add_field(FID_INST_ID, $fields->{(FID_INST_ID)}); @@ -531,74 +533,80 @@ sub handle_checkout { $item = $status->item; $patron = $status->patron; - if ($status->ok) { - # Item successfully checked out - # Fixed fields - $resp = CHECKOUT_RESP . '1'; - $resp .= sipbool($status->renew_ok); - if ($ils->supports('magnetic media')) { - $resp .= sipbool($item->magnetic_media); - } else { - $resp .= 'U'; - } - # We never return the obsolete 'U' value for 'desensitize' - $resp .= sipbool($status->desensitize); - $resp .= timestamp; + if ( $status->ok ) { - # Now for the variable fields - $resp .= add_field(FID_INST_ID, $inst); - $resp .= add_field(FID_PATRON_ID, $patron_id); - $resp .= add_field(FID_ITEM_ID, $item_id); - $resp .= add_field(FID_TITLE_ID, $item->title_id); - if ($item->due_date) { - $resp .= add_field(FID_DUE_DATE, timestamp($item->due_date)); - } else { - $resp .= add_field(FID_DUE_DATE, q{}); - } + # Item successfully checked out + # Fixed fields + $resp = CHECKOUT_RESP . '1'; + $resp .= sipbool( $status->renew_ok ); + if ( $ils->supports('magnetic media') ) { + $resp .= sipbool( $item->magnetic_media ); + } + else { + $resp .= 'U'; + } - $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg, $server); - $resp .= maybe_add(FID_PRINT_LINE, $status->print_line); + # We never return the obsolete 'U' value for 'desensitize' + $resp .= sipbool( $status->desensitize ); + $resp .= timestamp; + + # Now for the variable fields + $resp .= add_field( FID_INST_ID, $inst ); + $resp .= add_field( FID_PATRON_ID, $patron_id ); + $resp .= add_field( FID_ITEM_ID, $item_id ); + $resp .= add_field( FID_TITLE_ID, $item->title_id ); + if ( $item->due_date ) { + $resp .= add_field( FID_DUE_DATE, timestamp( $item->due_date ) ); + } + else { + $resp .= add_field( FID_DUE_DATE, q{} ); + } - if ($protocol_version >= 2) { - if ($ils->supports('security inhibit')) { - $resp .= add_field(FID_SECURITY_INHIBIT, - $status->security_inhibit); - } - $resp .= maybe_add(FID_MEDIA_TYPE, $item->sip_media_type); - $resp .= maybe_add(FID_ITEM_PROPS, $item->sip_item_properties); + $resp .= maybe_add( FID_SCREEN_MSG, $status->screen_msg, $server ); + $resp .= maybe_add( FID_PRINT_LINE, $status->print_line ); - } - } + if ( $protocol_version >= 2 ) { + if ( $ils->supports('security inhibit') ) { + $resp .= add_field( FID_SECURITY_INHIBIT, $status->security_inhibit ); + } + $resp .= maybe_add( FID_MEDIA_TYPE, $item->sip_media_type ); + $resp .= maybe_add( FID_ITEM_PROPS, $item->sip_item_properties ); + } + } else { - # Checkout failed - # Checkout Response: not ok, no renewal, don't know mag. media, - # no desensitize - $resp = sprintf("120NUN%s", timestamp); - $resp .= add_field(FID_INST_ID, $inst); - $resp .= add_field(FID_PATRON_ID, $patron_id); - $resp .= add_field(FID_ITEM_ID, $item_id); + # Checkout failed + # Checkout Response: not ok, no renewal, don't know mag. media, + # no desensitize + $resp = sprintf( "120NUN%s", timestamp ); + $resp .= add_field( FID_INST_ID, $inst ); + $resp .= add_field( FID_PATRON_ID, $patron_id ); + $resp .= add_field( FID_ITEM_ID, $item_id ); - # If the item is valid, provide the title, otherwise - # leave it blank - $resp .= add_field(FID_TITLE_ID, $item ? $item->title_id : ''); - # Due date is required. Since it didn't get checked out, - # it's not due, so leave the date blank - $resp .= add_field(FID_DUE_DATE, ''); + # If the item is valid, provide the title, otherwise + # leave it blank + $resp .= add_field( FID_TITLE_ID, $item ? $item->title_id : '' ); - $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg, $server); - $resp .= maybe_add(FID_PRINT_LINE, $status->print_line); + # Due date is required. Since it didn't get checked out, + # it's not due, so leave the date blank + $resp .= add_field( FID_DUE_DATE, '' ); - if ($protocol_version >= 2) { - # Is the patron ID valid? - $resp .= add_field(FID_VALID_PATRON, sipbool($patron)); + $resp .= maybe_add( FID_SCREEN_MSG, $status->screen_msg, $server ); + $resp .= maybe_add( FID_PRINT_LINE, $status->print_line ); - if ($patron && exists($fields->{FID_PATRON_PWD})) { - # Password provided, so we can tell if it was valid or not - $resp .= add_field(FID_VALID_PATRON_PWD, - sipbool($patron->check_password($fields->{(FID_PATRON_PWD)}))); - } - } + if ( $protocol_version >= 2 ) { + + # Is the patron ID valid? + $resp .= add_field( FID_VALID_PATRON, sipbool($patron) ); + + if ( $patron && exists( $fields->{FID_PATRON_PWD} ) ) { + + # Password provided, so we can tell if it was valid or not + $resp .= + add_field( FID_VALID_PATRON_PWD, + sipbool( $patron->check_password( $fields->{ (FID_PATRON_PWD) } ) ) ); + } + } } if ( $protocol_version >= 2 ) { @@ -1210,54 +1218,55 @@ sub handle_item_status_update { } sub handle_patron_enable { - my ($self, $server) = @_; - my $ils = $server->{ils}; + my ( $self, $server ) = @_; + my $ils = $server->{ils}; my $fields = $self->{fields}; - my ($trans_date, $patron_id, $terminal_pwd, $patron_pwd); - my ($status, $patron); + my ( $trans_date, $patron_id, $terminal_pwd, $patron_pwd ); + my ( $status, $patron ); my $resp = PATRON_ENABLE_RESP; - ($trans_date) = @{$self->{fixed_fields}}; - $patron_id = $fields->{(FID_PATRON_ID)}; - $patron_pwd = $fields->{(FID_PATRON_PWD)}; + ($trans_date) = @{ $self->{fixed_fields} }; + $patron_id = $fields->{ (FID_PATRON_ID) }; + $patron_pwd = $fields->{ (FID_PATRON_PWD) }; - syslog("LOG_DEBUG", "handle_patron_enable: patron_id: '%s', patron_pwd: '%s'", - $patron_id, $patron_pwd); + syslog( "LOG_DEBUG", "handle_patron_enable: patron_id: '%s', patron_pwd: '%s'", $patron_id, $patron_pwd ); $patron = $ils->find_patron($patron_id); - if (!defined($patron)) { - # Invalid patron ID - $resp .= 'YYYY' . (' ' x 10) . '000' . timestamp(); - $resp .= add_field(FID_PATRON_ID, $patron_id); - $resp .= add_field(FID_PERSONAL_NAME, ''); - $resp .= add_field(FID_VALID_PATRON, 'N'); - $resp .= add_field(FID_VALID_PATRON_PWD, 'N'); - } else { - # valid patron - if (!defined($patron_pwd) || $patron->check_password($patron_pwd)) { - # Don't enable the patron if there was an invalid password - $status = $patron->enable; - } - $resp .= patron_status_string($patron); - $resp .= $patron->language . timestamp(); + if ( !defined($patron) ) { - $resp .= add_field(FID_PATRON_ID, $patron->id); - $resp .= add_field(FID_PERSONAL_NAME, $patron->name); - if (defined($patron_pwd)) { - $resp .= add_field(FID_VALID_PATRON_PWD, - sipbool($patron->check_password($patron_pwd))); - } - $resp .= add_field(FID_VALID_PATRON, 'Y'); - $resp .= maybe_add(FID_SCREEN_MSG, $patron->screen_msg, $server); - $resp .= maybe_add(FID_PRINT_LINE, $patron->print_line); + # Invalid patron ID + $resp .= 'YYYY' . ( ' ' x 10 ) . '000' . timestamp(); + $resp .= add_field( FID_PATRON_ID, $patron_id ); + $resp .= add_field( FID_PERSONAL_NAME, '' ); + $resp .= add_field( FID_VALID_PATRON, 'N' ); + $resp .= add_field( FID_VALID_PATRON_PWD, 'N' ); } + else { + # valid patron + if ( !defined($patron_pwd) || $patron->check_password($patron_pwd) ) { - $resp .= add_field(FID_INST_ID, $ils->institution); + # Don't enable the patron if there was an invalid password + $status = $patron->enable; + } + $resp .= patron_status_string($patron); + $resp .= $patron->language . timestamp(); - $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); + $resp .= add_field( FID_PATRON_ID, $patron->id ); + $resp .= add_field( FID_PERSONAL_NAME, $patron->name ); + if ( defined($patron_pwd) ) { + $resp .= add_field( FID_VALID_PATRON_PWD, sipbool( $patron->check_password($patron_pwd) ) ); + } + $resp .= add_field( FID_VALID_PATRON, 'Y' ); + $resp .= maybe_add( FID_SCREEN_MSG, $patron->screen_msg, $server ); + $resp .= maybe_add( FID_PRINT_LINE, $patron->print_line ); + } + + $resp .= add_field( FID_INST_ID, $ils->institution ); + + $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); - return(PATRON_ENABLE); + return (PATRON_ENABLE); } sub handle_hold { -- 1.7.2.5