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

(-)a/C4/AuthoritiesMarc.pm (-1 / +12 lines)
Lines 655-663 sub AddAuthority { Link Here
655
    $field->update($auth_type_subfield=>$authtypecode);
655
    $field->update($auth_type_subfield=>$authtypecode);
656
  }
656
  }
657
  else {
657
  else {
658
    $record->add_fields($auth_type_tag,'','', $auth_type_subfield=>$authtypecode); 
658
    $record->add_fields($auth_type_tag,'','', $auth_type_subfield=>$authtypecode);
659
  }
659
  }
660
660
661
    if ( C4::Context->preference('StripWhitespaceChars') ) {
662
        foreach my $field ( $record->fields ) {
663
            foreach my $subfield ( $field->subfields ) {
664
                my $key = $subfield->[0];
665
                my $value = $subfield->[1];
666
                $value =~ s/^\s+|\s+$|^\n+|\n+$|^\r+|\r+$|^\t+|\t+$//g;
667
                $field->update( $key => $value );
668
            }
669
        }
670
    }
671
661
    # Save record into auth_header, update 001
672
    # Save record into auth_header, update 001
662
    my $action;
673
    my $action;
663
    my $authority;
674
    my $authority;
(-)a/C4/Biblio.pm (+11 lines)
Lines 2811-2816 sub ModBiblioMarc { Link Here
2811
      $f005->update(sprintf("%4d%02d%02d%02d%02d%04.1f",@a)) if $f005;
2811
      $f005->update(sprintf("%4d%02d%02d%02d%02d%04.1f",@a)) if $f005;
2812
    }
2812
    }
2813
2813
2814
    if ( C4::Context->preference('StripWhitespaceChars') ) {
2815
        foreach my $field ( $record->fields ) {
2816
            foreach my $subfield ( $field->subfields ) {
2817
                my $key = $subfield->[0];
2818
                my $value = $subfield->[1];
2819
                $value =~ s/^\s+|\s+$|^\n+|\n+$|^\r+|\r+$|^\t+|\t+$//g;
2820
                $field->update( $key => $value );
2821
            }
2822
        }
2823
    }
2824
2814
    my $metadata = {
2825
    my $metadata = {
2815
        biblionumber => $biblionumber,
2826
        biblionumber => $biblionumber,
2816
        format       => 'marcxml',
2827
        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 698-703 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
698
('StatisticsFields','location|itype|ccode', NULL, 'Define Fields (from the items table) used for statistics members','Free'),
698
('StatisticsFields','location|itype|ccode', NULL, 'Define Fields (from the items table) used for statistics members','Free'),
699
('StockRotation','0',NULL,'If ON, enables the stock rotation module','YesNo'),
699
('StockRotation','0',NULL,'If ON, enables the stock rotation module','YesNo'),
700
('StoreLastBorrower','0','','If ON, the last borrower to return an item will be stored in items.last_returned_by','YesNo'),
700
('StoreLastBorrower','0','','If ON, the last borrower to return an item will be stored in items.last_returned_by','YesNo'),
701
('StripWhitespaceChars','0',NULL,'Strip leading and trailing whitespace characters from input fields when cataloguing bibliographic and authority records.','YesNo'),
701
('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'),
702
('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'),
702
('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'),
703
('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'),
703
('SubfieldsToUseWhenPrefill','','','Define a list of subfields to use when prefilling items (separated by space)','Free'),
704
('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 205-210 Cataloging: Link Here
205
            - pref: ContentWarningField
205
            - pref: ContentWarningField
206
            - for storing content warnings.
206
            - for storing content warnings.
207
            - "<br/><strong>NOTE:</strong> The field needs to appear in the MARC frameworks to be accessible."
207
            - "<br/><strong>NOTE:</strong> The field needs to appear in the MARC frameworks to be accessible."
208
        -
209
            - pref: StripWhitespaceChars
210
              choices:
211
                  1: Strip
212
                  0: "Don't strip"
213
            - leading and trailing whitespace characters from input fields when cataloguing bibliographic and authority records. Whitespace characters include spaces, tabs, newlines and carriage returns.
208
    Display:
214
    Display:
209
        -
215
        -
210
            - 'Separate main entry and subdivisions with '
216
            - '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