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

(-)a/C4/AuthoritiesMarc.pm (-1 / +12 lines)
Lines 638-646 sub AddAuthority { Link Here
638
    $field->update($auth_type_subfield=>$authtypecode);
638
    $field->update($auth_type_subfield=>$authtypecode);
639
  }
639
  }
640
  else {
640
  else {
641
    $record->add_fields($auth_type_tag,'','', $auth_type_subfield=>$authtypecode); 
641
    $record->add_fields($auth_type_tag,'','', $auth_type_subfield=>$authtypecode);
642
  }
642
  }
643
643
644
    if ( C4::Context->preference('StripWhitespaceChars') ) {
645
        foreach my $field ( $record->fields ) {
646
            foreach my $subfield ( $field->subfields ) {
647
                my $key = $subfield->[0];
648
                my $value = $subfield->[1];
649
                $value =~ s/^\s+|\s+$|^\n+|\n+$|^\r+|\r+$|^\t+|\t+$//g;
650
                $field->update( $key => $value );
651
            }
652
        }
653
    }
654
644
    # Save record into auth_header, update 001
655
    # Save record into auth_header, update 001
645
    my $action;
656
    my $action;
646
    my $authority;
657
    my $authority;
(-)a/C4/Biblio.pm (+11 lines)
Lines 2752-2757 sub ModBiblioMarc { Link Here
2752
      $f005->update(sprintf("%4d%02d%02d%02d%02d%04.1f",@a)) if $f005;
2752
      $f005->update(sprintf("%4d%02d%02d%02d%02d%04.1f",@a)) if $f005;
2753
    }
2753
    }
2754
2754
2755
    if ( C4::Context->preference('StripWhitespaceChars') ) {
2756
        foreach my $field ( $record->fields ) {
2757
            foreach my $subfield ( $field->subfields ) {
2758
                my $key = $subfield->[0];
2759
                my $value = $subfield->[1];
2760
                $value =~ s/^\s+|\s+$|^\n+|\n+$|^\r+|\r+$|^\t+|\t+$//g;
2761
                $field->update( $key => $value );
2762
            }
2763
        }
2764
    }
2765
2755
    my $metadata = {
2766
    my $metadata = {
2756
        biblionumber => $biblionumber,
2767
        biblionumber => $biblionumber,
2757
        format       => 'marcxml',
2768
        format       => 'marcxml',
(-)a/installer/data/mysql/atomicupdate/bug_30358_-_add_StripWhitespaceChars_syspref.pl (+12 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "30358",
5
    description => "Add new system preference StripWhitespaceChars",
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
10
        $dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('StripWhitespaceChars', '0', NULL, 'Strip leading and trailing whitespace characters from input fields when cataloguing bibliographic and authority records.', 'YesNo') });
11
    },
12
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 683-688 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
683
('StatisticsFields','location|itype|ccode', NULL, 'Define Fields (from the items table) used for statistics members','Free'),
683
('StatisticsFields','location|itype|ccode', NULL, 'Define Fields (from the items table) used for statistics members','Free'),
684
('StockRotation','0',NULL,'If ON, enables the stock rotation module','YesNo'),
684
('StockRotation','0',NULL,'If ON, enables the stock rotation module','YesNo'),
685
('StoreLastBorrower','0','','If ON, the last borrower to return an item will be stored in items.last_returned_by','YesNo'),
685
('StoreLastBorrower','0','','If ON, the last borrower to return an item will be stored in items.last_returned_by','YesNo'),
686
('StripWhitespaceChars','0',NULL,'Strip leading and trailing whitespace characters from input fields when cataloguing bibliographic and authority records.','YesNo'),
686
('SubfieldsToAllowForRestrictedBatchmod','','Define a list of subfields for which edition is authorized when items_batchmod_restricted permission is enabled, separated by spaces. Example: 995\$f 995\$h 995\$j',NULL,'Free'),
687
('SubfieldsToAllowForRestrictedBatchmod','','Define a list of subfields for which edition is authorized when items_batchmod_restricted permission is enabled, separated by spaces. Example: 995\$f 995\$h 995\$j',NULL,'Free'),
687
('SubfieldsToAllowForRestrictedEditing','','Define a list of subfields for which edition is authorized when edit_items_restricted permission is enabled, separated by spaces. Example: 995\$f 995\$h 995\$j',NULL,'Free'),
688
('SubfieldsToAllowForRestrictedEditing','','Define a list of subfields for which edition is authorized when edit_items_restricted permission is enabled, separated by spaces. Example: 995\$f 995\$h 995\$j',NULL,'Free'),
688
('SubfieldsToUseWhenPrefill','','','Define a list of subfields to use when prefilling items (separated by space)','Free'),
689
('SubfieldsToUseWhenPrefill','','','Define a list of subfields to use when prefilling items (separated by space)','Free'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (+6 lines)
Lines 178-183 Cataloging: Link Here
178
                  1: Display
178
                  1: Display
179
                  0: "Don't display"
179
                  0: "Don't display"
180
            - OCLC defined values for MARC encoding level in leader value builder for position 17.
180
            - OCLC defined values for MARC encoding level in leader value builder for position 17.
181
        -
182
            - pref: StripWhitespaceChars
183
              choices:
184
                  1: Strip
185
                  0: "Don't strip"
186
            - leading and trailing whitespace characters from input fields when cataloguing bibliographic and authority records. Whitespace characters include spaces, tabs, newlines and carriage returns.
181
    Display:
187
    Display:
182
        -
188
        -
183
            - 'Separate main entry and subdivisions with '
189
            - 'Separate main entry and subdivisions with '
(-)a/t/db_dependent/Biblio/ModBiblioMarc.t (-2 / +29 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 1;
20
use Test::More tests => 2;
21
use t::lib::Mocks;
21
use t::lib::Mocks;
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
23
use MARC::Record;
23
use MARC::Record;
Lines 47-50 subtest "Check MARC field length calculation" => sub { Link Here
47
    like( substr($savedrec->leader,12,5), qr/^\d{5}$/, 'Base address found' );
47
    like( substr($savedrec->leader,12,5), qr/^\d{5}$/, 'Base address found' );
48
};
48
};
49
49
50
subtest "StripWhitespaceChars tests" => sub {
51
    plan tests => 3;
52
53
    t::lib::Mocks->mock_preference('marcflavour', 'MARC21');
54
    t::lib::Mocks->mock_preference('StripWhitespaceChars', 0);
55
56
    my $biblio = t::lib::TestBuilder->new->build_sample_biblio;
57
    my $record = MARC::Record->new;
58
    $record->append_fields(
59
        MARC::Field->new( '245', '', '', a => "  My title\n" ),
60
    );
61
62
    my $title = $record->title;
63
    is( $title, "  My title\n", 'Title has whitespace characters' );
64
65
    C4::Biblio::ModBiblioMarc( $record, $biblio->biblionumber );
66
    my $savedrec = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber });
67
    my $savedtitle = $savedrec->title;
68
    is( $savedtitle, "  My title\n", "Title still has whitespace characters because StripWhitespaceChars is disabled" );
69
70
    t::lib::Mocks->mock_preference('StripWhitespaceChars', 1);
71
72
    C4::Biblio::ModBiblioMarc( $record, $biblio->biblionumber );
73
    my $amendedrec = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber });
74
    my $amendedtitle = $amendedrec->title;
75
    is( $amendedtitle, "My title", "Whitespace characters removed from title because StripWhitespaceChars is enabled" );
76
};
77
50
$schema->storage->txn_rollback;
78
$schema->storage->txn_rollback;
51
- 

Return to bug 30358