From adb6ce4114717a86931b01100356a410f53bcc07 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 19 Mar 2013 03:27:46 -0700 Subject: [PATCH] Bug 8015: Fix template capitalization amd other template issues Signed-off-by: Leila Bug 8015: Fix error where field object is returned instead of field value for fields without subfields Signed-off-by: Leila Bug 8015: Fix bad ordering on function parameters Signed-off-by: Leila Bug 8015: Escape escape characters for strings Signed-off-by: Leila Bug 8015: Fix bad parameter list for direct external call to update_field Signed-off-by: Leila Bug 8015: Fix problem with moving existing subfield value to nonexistent field/subfield Signed-off-by: Leila Bug 8015: FIX QA issues This patch fixes some stuffs failing qa tests: POD, indentation (tabs), perlcritic --- C4/Koha.pm | 11 +- C4/MarcModificationTemplates.pm | 39 +- Koha/SimpleMARC.pm | 32 +- .../intranet-tmpl/prog/en/includes/tools-menu.inc | 2 +- .../modules/tools/marc_modification_templates.tt | 809 ++++++++++---------- tools/marc_modification_templates.pl | 15 +- 6 files changed, 455 insertions(+), 453 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index ade33f0..90dfc50 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -1488,9 +1488,7 @@ sub _isbn_cleanup { return; } -=head2 - - Log( $message ); +=head2 Log( $message ); Writes data to /tmp/koha.log. @@ -1501,9 +1499,10 @@ sub _isbn_cleanup { sub Log { my ($data) = @_; - open (MYFILE, '>>/tmp/koha.log'); - print MYFILE "$data\n"; - close (MYFILE); + warn $data; + open my $fh, '>>/tmp/koha.log'; + print $fh "$data\n"; + close $fh; } 1; diff --git a/C4/MarcModificationTemplates.pm b/C4/MarcModificationTemplates.pm index 2c8bbaf..8c9212f 100644 --- a/C4/MarcModificationTemplates.pm +++ b/C4/MarcModificationTemplates.pm @@ -35,24 +35,24 @@ use vars qw($VERSION @ISA @EXPORT); use constant DEBUG => 0; BEGIN { - $VERSION = 1.00; # set the version for version checking - @ISA = qw(Exporter); - @EXPORT = qw( - &GetModificationTemplates - &AddModificationTemplate - &DelModificationTemplate - - &GetModificationTemplateAction - &GetModificationTemplateActions - - &AddModificationTemplateAction - &ModModificationTemplateAction - &DelModificationTemplateAction - &MoveModificationTemplateAction - - &ModifyRecordsWithTemplate - &ModifyRecordWithTemplate - ); + $VERSION = 1.00; # set the version for version checking + @ISA = qw(Exporter); + @EXPORT = qw( + &GetModificationTemplates + &AddModificationTemplate + &DelModificationTemplate + + &GetModificationTemplateAction + &GetModificationTemplateActions + + &AddModificationTemplateAction + &ModModificationTemplateAction + &DelModificationTemplateAction + &MoveModificationTemplateAction + + &ModifyRecordsWithTemplate + &ModifyRecordWithTemplate + ); } @@ -529,6 +529,7 @@ sub ModifyRecordWithTemplate { $field_value =~ s/__CURRENTDATE__/$current_date/g; $field_value =~ s/__BRANCHCODE__/$branchcode/g; + $eval .= " undef, " if ( $action eq 'update_field' ); $eval .= " '$field_value' "; C4::Koha::Log( "Field value after replacements: $field_value" ) if ( DEBUG >= 3 ); @@ -563,7 +564,7 @@ sub ModifyRecordWithTemplate { C4::Koha::Log("eval $eval") if DEBUG >= 2; warn("eval $eval") if DEBUG >= 2; - eval $eval; + eval {$eval}; C4::Koha::Log( $record->as_formatted() ) if DEBUG >= 10; warn( $record->as_formatted() ) if DEBUG >= 10; diff --git a/Koha/SimpleMARC.pm b/Koha/SimpleMARC.pm index 82abe00..f72fc2f 100644 --- a/Koha/SimpleMARC.pm +++ b/Koha/SimpleMARC.pm @@ -60,7 +60,7 @@ at your option, any later version of Perl 5 you may have available. =head1 FUNCTIONS -=head2 +=head2 copy_field copy_field( $record, $fromFieldName, $fromSubfieldName, $toFieldName, $toSubfieldName[, $regex[, $n ] ] ); @@ -90,13 +90,13 @@ sub copy_field { } } - update_field( $record, $toFieldName, $toSubfieldName, @values, $dont_erase ); + update_field( $record, $toFieldName, $toSubfieldName, $dont_erase, @values ); } -=head2 +=head2 update_field - update_field( $record, $fieldName, $subfieldName, $value[, $value,[ $value ... ] ] ); + update_field( $record, $fieldName, $subfieldName, $dont_erase, $value[, $value,[ $value ... ] ] ); Updates a field with the given value, creating it if neccessary. @@ -109,8 +109,8 @@ sub copy_field { =cut sub update_field { - my ( $record, $fieldName, $subfieldName, @values, $dont_erase ) = @_; - C4::Koha::Log( "C4::SimpleMARC::update_field( $record, $fieldName, $subfieldName, @values )" ) if $debug; + my ( $record, $fieldName, $subfieldName, $dont_erase, @values ) = @_; + C4::Koha::Log( "C4::SimpleMARC::update_field( $record, $fieldName, $subfieldName, $dont_erase, @values )" ) if $debug; if ( ! ( $record && $fieldName ) ) { return; } @@ -157,7 +157,7 @@ sub update_field { } } -=head2 +=head2 read_field my @values = read_field( $record, $fieldName[, $subfieldName, [, $n ] ] ); @@ -174,7 +174,7 @@ sub read_field { my @fields = $record->field( $fieldName ); - return @fields unless $subfieldName; + return map { $_->data() } @fields unless $subfieldName; my @subfields; foreach my $field ( @fields ) { @@ -189,7 +189,7 @@ sub read_field { } } -=head2 +=head2 field_exists $bool = field_exists( $record, $fieldName[, $subfieldName ]); @@ -214,7 +214,7 @@ sub field_exists { return $return; } -=head2 +=head2 field_equals $bool = field_equals( $record, $value, $fieldName[, $subfieldName[, $regex [, $n ] ] ]); @@ -246,7 +246,7 @@ sub field_equals { } } -=head2 +=head2 move_field move_field( $record, $fromFieldName, $fromSubfieldName, $toFieldName, $toSubfieldName[, $regex [, $n ] ] ); @@ -262,11 +262,11 @@ sub field_equals { sub move_field { my ( $record, $fromFieldName, $fromSubfieldName, $toFieldName, $toSubfieldName, $regex, $n ) = @_; C4::Koha::Log( "C4::SimpleMARC::move_field( '$record', '$fromFieldName', '$fromSubfieldName', '$toFieldName', '$toSubfieldName', '$regex', '$n' )" ) if $debug; - copy_field( $record, $fromFieldName, $fromSubfieldName, $toFieldName, $toSubfieldName, $regex, $n , "don't_erase"); + copy_field( $record, $fromFieldName, $fromSubfieldName, $toFieldName, $toSubfieldName, $regex, $n , 1); delete_field( $record, $fromFieldName, $fromSubfieldName, $n ); } -=head2 +=head2 delete_field delete_field( $record, $fieldName[, $subfieldName [, $n ] ] ); @@ -296,7 +296,7 @@ sub delete_field { } } -=head2 +=head2 _update_repeatable_field_with_single_value _update_repeatable_field_with_single_value( $record, $fieldName, $subfieldName, $value ); @@ -316,11 +316,11 @@ sub _update_repeatable_field_with_single_value { if ( $subfieldName ) { if ( my @fields = $record->field( $fieldName ) ) { foreach my $field ( @fields ) { - $field->update( "$subfieldName" => $value ); + $field->update( $subfieldName => $value ); } } else { ## Field does not exist, create it. - $field = MARC::Field->new( $fieldName, '', '', "$subfieldName" => $value ); + $field = MARC::Field->new( $fieldName, undef, undef, $subfieldName => $value ); $record->append_fields( $field ); } } else { ## No subfield diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc index 871803e..45d9b4e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc @@ -72,7 +72,7 @@ [% END %] --> [% IF ( CAN_user_tools_marc_modification_templates ) %] -
  • Manage MARC modification templates
  • +
  • Manage MARC modification templates
  • [% END %] [% IF ( CAN_user_tools_stage_marc_import ) %]
  • Stage MARC for import
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt index 255310d..00a6e84 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt @@ -1,237 +1,237 @@ [% INCLUDE 'doc-head-open.inc' %] -Koha › Tools › MARC Modification Templates +Koha › Tools › MARC modification templates [% INCLUDE 'doc-head-close.inc' %] @@ -242,251 +242,252 @@ function setSelectByValue( selectId, value ) { [% INCLUDE 'header.inc' %] [% INCLUDE 'cat-search.inc' %] - +
    -
    -
    -

    MARC Modification Templates

    - - [% IF ( TemplatesLoop ) %] - -
    - - - - -
    - -
    - - - -
    - - - [% IF ( ActionsLoop ) %] - - - - - - - - - - - - - [% FOREACH ActionsLoo IN ActionsLoop %] - - - - - - - - - - [% END %] -
    Actions for this template
    Change OrderOrderActionDescription  
    - - Go up - - - - Go top - - - - Go bottom - - - - Go down - - [% ActionsLoo.ordering %] - [% IF ( ActionsLoo.action_delete_field ) %] Delete [% END %] - [% IF ( ActionsLoo.action_update_field ) %] Update [% END %] - [% IF ( ActionsLoo.action_move_field ) %] Move [% END %] - [% IF ( ActionsLoo.action_copy_field ) %] Copy [% END %] - - [% UNLESS ( ActionsLoo.action_update_field ) %] - [% IF ( ActionsLoo.field_number ) %] - 1st - [% END %] - [% END %] - - field - - [% ActionsLoo.from_field %][% IF ( ActionsLoo.from_subfield ) %]$[% ActionsLoo.from_subfield %][% END %] - - [% IF ( ActionsLoo.field_value ) %] - with value [% ActionsLoo.field_value %] - [% END %] - - [% IF ( ActionsLoo.to_field ) %] - to [% ActionsLoo.to_field %][% IF ( ActionsLoo.to_subfield ) %]$[% ActionsLoo.to_subfield %][% END %] - - [% IF ( ActionsLoo.to_regex ) %] - using RegEx s[% ActionsLoo.to_regex %] - [% END %] - [% END %] - - [% IF ( ActionsLoo.conditional ) %] - [% IF ( ActionsLoo.conditional_if ) %] if [% END %] - [% IF ( ActionsLoo.conditional_unless ) %] unless [% END %] - - [% ActionsLoo.conditional_field %][% IF ( ActionsLoo.conditional_subfield ) %]$[% ActionsLoo.conditional_subfield %][% END %] - - [% IF ( ActionsLoo.conditional_comparison_exists ) %] exists [% END %] - [% IF ( ActionsLoo.conditional_comparison_not_exists ) %] does not exist [% END %] - [% IF ( ActionsLoo.conditional_comparison_equals ) %] matches [% END %] - [% IF ( ActionsLoo.conditional_comparison_not_equals ) %] does not match [% END %] - - [% IF ( ActionsLoo.conditional_regex ) %] RegEx m[% END %][% ActionsLoo.conditional_value %] - [% END %] - [% ActionsLoo.description %]EditDelete
    - [% ELSE %] -

    There are no defined actions for this template.

    - [% END %] - -
    - -
    - Add A New Action - - - - - - - - field(s) - - - - - -

    - - - - - - - - - -

    - - - -

    - - -

    -
    - - [% ELSE %] -

    There are no defined templates. Please create a template first.

    - [% END %] - -
    -
    - Create A New Template - - - - - - - - [% IF ( template_id ) %] - - - - [% END %] -
    -
    - - - -
    -
    - -
    - [% INCLUDE 'tools-menu.inc' %] -
    +
    +
    +

    MARC modification templates

    + + [% IF ( TemplatesLoop ) %] + +
    + + + + +
    + +
    + + + +
    + + + [% IF ( ActionsLoop ) %] + + + + + + + + + + + + + [% FOREACH ActionsLoo IN ActionsLoop %] + + + + + + + + + + [% END %] +
    Actions for this template
    Change OrderOrderActionDescription  
    + + Go up + + + + Go top + + + + Go bottom + + + + Go down + + [% ActionsLoo.ordering %] + [% IF ( ActionsLoo.action_delete_field ) %] Delete [% END %] + [% IF ( ActionsLoo.action_update_field ) %] Update [% END %] + [% IF ( ActionsLoo.action_move_field ) %] Move [% END %] + [% IF ( ActionsLoo.action_copy_field ) %] Copy [% END %] + + [% UNLESS ( ActionsLoo.action_update_field ) %] + [% IF ( ActionsLoo.field_number ) %] + 1st + [% END %] + [% END %] + + field + + [% ActionsLoo.from_field %][% IF ( ActionsLoo.from_subfield ) %]$[% ActionsLoo.from_subfield %][% END %] + + [% IF ( ActionsLoo.field_value ) %] + with value [% ActionsLoo.field_value %] + [% END %] + + [% IF ( ActionsLoo.to_field ) %] + to [% ActionsLoo.to_field %][% IF ( ActionsLoo.to_subfield ) %]$[% ActionsLoo.to_subfield %][% END %] + + [% IF ( ActionsLoo.to_regex ) %] + using RegEx s[% ActionsLoo.to_regex %] + [% END %] + [% END %] + + [% IF ( ActionsLoo.conditional ) %] + [% IF ( ActionsLoo.conditional_if ) %] if [% END %] + [% IF ( ActionsLoo.conditional_unless ) %] unless [% END %] + + [% ActionsLoo.conditional_field %][% IF ( ActionsLoo.conditional_subfield ) %]$[% ActionsLoo.conditional_subfield %][% END %] + + [% IF ( ActionsLoo.conditional_comparison_exists ) %] exists [% END %] + [% IF ( ActionsLoo.conditional_comparison_not_exists ) %] does not exist [% END %] + [% IF ( ActionsLoo.conditional_comparison_equals ) %] matches [% END %] + [% IF ( ActionsLoo.conditional_comparison_not_equals ) %] does not match [% END %] + + [% IF ( ActionsLoo.conditional_regex ) %] RegEx m[% END %][% ActionsLoo.conditional_value %] + [% END %] + [% ActionsLoo.description %]EditDelete
    + [% ELSE %] +

    There are no defined actions for this template.

    + [% END %] + +
    + +
    + Add A New Action + + + + + + + + field(s) + + + + + +

    + + + + + + + + + +

    + + + +

    + + +

    +
    + + [% ELSE %] +

    There are no defined templates. Please create a template first.

    + [% END %] + +
    +
    + Create a new template + + + + + + + + [% IF ( template_id ) %] + + + + [% END %] +
    +
    +
    +
    + +
    + [% INCLUDE 'tools-menu.inc' %] +
    [% INCLUDE 'intranet-bottom.inc' %] diff --git a/tools/marc_modification_templates.pl b/tools/marc_modification_templates.pl index d3a4d8c..dde2476 100755 --- a/tools/marc_modification_templates.pl +++ b/tools/marc_modification_templates.pl @@ -32,13 +32,14 @@ my $op = $cgi->param('op'); my $template_id = $cgi->param('template_id'); my ($template, $loggedinuser, $cookie) - = get_template_and_user({template_name => "tools/marc_modification_templates.tmpl", - query => $cgi, - type => "intranet", - authnotrequired => 0, - flagsrequired => { tools => 'marc_modfication_templates' }, - debug => 1, - }); + = get_template_and_user({ + template_name => "tools/marc_modification_templates.tmpl", + query => $cgi, + type => "intranet", + authnotrequired => 0, + flagsrequired => { tools => 'marc_modfication_templates' }, + debug => 1, + }); if ( $op eq "create_template" ) { $template_id = '' unless $cgi->param('duplicate_current_template'); -- 1.7.2.5