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

(-)a/C4/AuthoritiesMarc.pm (-1 / +12 lines)
Lines 654-662 sub AddAuthority { Link Here
654
    $field->update($auth_type_subfield=>$authtypecode);
654
    $field->update($auth_type_subfield=>$authtypecode);
655
  }
655
  }
656
  else {
656
  else {
657
    $record->add_fields($auth_type_tag,'','', $auth_type_subfield=>$authtypecode); 
657
    $record->add_fields($auth_type_tag,'','', $auth_type_subfield=>$authtypecode);
658
  }
658
  }
659
659
660
    if ( C4::Context->preference('StripWhitespaceChars') ) {
661
        foreach my $field ( $record->fields ) {
662
            foreach my $subfield ( $field->subfields ) {
663
                my $key = $subfield->[0];
664
                my $value = $subfield->[1];
665
                $value =~ s/^\s+|\s+$|^\n+|\n+$|^\r+|\r+$|^\t+|\t+$//g;
666
                $field->update( $key => $value );
667
            }
668
        }
669
    }
670
660
    # Save record into auth_header, update 001
671
    # Save record into auth_header, update 001
661
    my $action;
672
    my $action;
662
    my $authority;
673
    my $authority;
(-)a/C4/Biblio.pm (+11 lines)
Lines 2751-2756 sub ModBiblioMarc { Link Here
2751
      $f005->update(sprintf("%4d%02d%02d%02d%02d%04.1f",@a)) if $f005;
2751
      $f005->update(sprintf("%4d%02d%02d%02d%02d%04.1f",@a)) if $f005;
2752
    }
2752
    }
2753
2753
2754
    if ( C4::Context->preference('StripWhitespaceChars') ) {
2755
        foreach my $field ( $record->fields ) {
2756
            foreach my $subfield ( $field->subfields ) {
2757
                my $key = $subfield->[0];
2758
                my $value = $subfield->[1];
2759
                $value =~ s/^\s+|\s+$|^\n+|\n+$|^\r+|\r+$|^\t+|\t+$//g;
2760
                $field->update( $key => $value );
2761
            }
2762
        }
2763
    }
2764
2754
    my $metadata = {
2765
    my $metadata = {
2755
        biblionumber => $biblionumber,
2766
        biblionumber => $biblionumber,
2756
        format       => 'marcxml',
2767
        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 690-695 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
690
('StatisticsFields','location|itype|ccode', NULL, 'Define Fields (from the items table) used for statistics members','Free'),
690
('StatisticsFields','location|itype|ccode', NULL, 'Define Fields (from the items table) used for statistics members','Free'),
691
('StockRotation','0',NULL,'If ON, enables the stock rotation module','YesNo'),
691
('StockRotation','0',NULL,'If ON, enables the stock rotation module','YesNo'),
692
('StoreLastBorrower','0','','If ON, the last borrower to return an item will be stored in items.last_returned_by','YesNo'),
692
('StoreLastBorrower','0','','If ON, the last borrower to return an item will be stored in items.last_returned_by','YesNo'),
693
('StripWhitespaceChars','0',NULL,'Strip leading and trailing whitespace characters from input fields when cataloguing bibliographic and authority records.','YesNo'),
693
('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'),
694
('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'),
694
('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'),
695
('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'),
695
('SubfieldsToUseWhenPrefill','','','Define a list of subfields to use when prefilling items (separated by space)','Free'),
696
('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 186-191 Cataloging: Link Here
186
                duplicate: "when editing records as new (duplicating)"
186
                duplicate: "when editing records as new (duplicating)"
187
                changed: "when changing the framework while editing the existing record"
187
                changed: "when changing the framework while editing the existing record"
188
                imported: "when importing a record via z39.50"
188
                imported: "when importing a record via z39.50"
189
        -
190
            - pref: StripWhitespaceChars
191
              choices:
192
                  1: Strip
193
                  0: "Don't strip"
194
            - leading and trailing whitespace characters from input fields when cataloguing bibliographic and authority records. Whitespace characters include spaces, tabs, newlines and carriage returns.
189
    Display:
195
    Display:
190
        -
196
        -
191
            - 'Separate main entry and subdivisions with '
197
            - '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