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

(-)a/C4/AuthoritiesMarc.pm (+11 lines)
Lines 626-631 sub AddAuthority { Link Here
626
    $record->add_fields($auth_type_tag,'','', $auth_type_subfield=>$authtypecode); 
626
    $record->add_fields($auth_type_tag,'','', $auth_type_subfield=>$authtypecode); 
627
  }
627
  }
628
628
629
    if ( C4::Context->preference('StripWhitespaceChars') ) {
630
        foreach my $field ( $record->fields ) {
631
            foreach my $subfield ( $field->subfields ) {
632
                my $key = $subfield->[0];
633
                my $value = $subfield->[1];
634
                $value =~ s/^\s+|\s+$|^\n+|\n+$|^\r+|\r+$|^\t+|\t+$//g;
635
                $field->update( $key => $value );
636
            }
637
        }
638
    }
639
629
    # Save record into auth_header, update 001
640
    # Save record into auth_header, update 001
630
    my $action;
641
    my $action;
631
    if (!$authid ) {
642
    if (!$authid ) {
(-)a/C4/Biblio.pm (+11 lines)
Lines 2892-2897 sub ModBiblioMarc { Link Here
2892
      $f005->update(sprintf("%4d%02d%02d%02d%02d%04.1f",@a)) if $f005;
2892
      $f005->update(sprintf("%4d%02d%02d%02d%02d%04.1f",@a)) if $f005;
2893
    }
2893
    }
2894
2894
2895
    if ( C4::Context->preference('StripWhitespaceChars') ) {
2896
        foreach my $field ( $record->fields ) {
2897
            foreach my $subfield ( $field->subfields ) {
2898
                my $key = $subfield->[0];
2899
                my $value = $subfield->[1];
2900
                $value =~ s/^\s+|\s+$|^\n+|\n+$|^\r+|\r+$|^\t+|\t+$//g;
2901
                $field->update( $key => $value );
2902
            }
2903
        }
2904
    }
2905
2895
    my $metadata = {
2906
    my $metadata = {
2896
        biblionumber => $biblionumber,
2907
        biblionumber => $biblionumber,
2897
        format       => 'marcxml',
2908
        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 641-646 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
641
('StatisticsFields','location|itype|ccode', NULL, 'Define Fields (from the items table) used for statistics members','Free'),
641
('StatisticsFields','location|itype|ccode', NULL, 'Define Fields (from the items table) used for statistics members','Free'),
642
('StockRotation','0',NULL,'If ON, enables the stock rotation module','YesNo'),
642
('StockRotation','0',NULL,'If ON, enables the stock rotation module','YesNo'),
643
('StoreLastBorrower','0','','If ON, the last borrower to return an item will be stored in items.last_returned_by','YesNo'),
643
('StoreLastBorrower','0','','If ON, the last borrower to return an item will be stored in items.last_returned_by','YesNo'),
644
('StripWhitespaceChars','0',NULL,'Strip leading and trailing whitespace characters from input fields when cataloguing bibliographic and authority records.','YesNo'),
644
('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'),
645
('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'),
645
('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'),
646
('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'),
646
('SubfieldsToUseWhenPrefill','','','Define a list of subfields to use when prefilling items (separated by space)','Free'),
647
('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 165-170 Cataloging: Link Here
165
            - and record's last modifier name in MARC subfield
165
            - and record's last modifier name in MARC subfield
166
            - pref: MarcFieldForModifierName
166
            - pref: MarcFieldForModifierName
167
            - ". <br/><strong>NOTE:</strong> Use a dollar sign between field and subfield like 123$a."
167
            - ". <br/><strong>NOTE:</strong> Use a dollar sign between field and subfield like 123$a."
168
        -
169
            - pref: StripWhitespaceChars
170
              choices:
171
                  1: Strip
172
                  0: "Don't strip"
173
            - leading and trailing whitespace characters from input fields when cataloguing bibliographic and authority records. Whitespace characters include spaces, tabs, newlines and carriage returns.
168
    Display:
174
    Display:
169
        -
175
        -
170
            - 'Separate main entry and subdivisions with '
176
            - '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 46-49 subtest "Check MARC field length calculation" => sub { Link Here
46
    like( substr($savedrec->leader,12,5), qr/^\d{5}$/, 'Base address found' );
46
    like( substr($savedrec->leader,12,5), qr/^\d{5}$/, 'Base address found' );
47
};
47
};
48
48
49
subtest "StripWhitespaceChars tests" => sub {
50
    plan tests => 3;
51
52
    t::lib::Mocks->mock_preference('marcflavour', 'MARC21');
53
    t::lib::Mocks->mock_preference('StripWhitespaceChars', 0);
54
55
    my $biblio = t::lib::TestBuilder->new->build_sample_biblio;
56
    my $record = MARC::Record->new;
57
    $record->append_fields(
58
        MARC::Field->new( '245', '', '', a => "  My title\n" ),
59
    );
60
61
    my $title = $record->title;
62
    is( $title, "  My title\n", 'Title has whitespace characters' );
63
64
    C4::Biblio::ModBiblioMarc( $record, $biblio->biblionumber );
65
    my $savedrec = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber });
66
    my $savedtitle = $savedrec->title;
67
    is( $savedtitle, "  My title\n", "Title still has whitespace characters because StripWhitespaceChars is disabled" );
68
69
    t::lib::Mocks->mock_preference('StripWhitespaceChars', 1);
70
71
    C4::Biblio::ModBiblioMarc( $record, $biblio->biblionumber );
72
    my $amendedrec = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber });
73
    my $amendedtitle = $amendedrec->title;
74
    is( $amendedtitle, "My title", "Whitespace characters removed from title because StripWhitespaceChars is enabled" );
75
};
76
49
$schema->storage->txn_rollback;
77
$schema->storage->txn_rollback;
50
- 

Return to bug 30358