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

(-)a/C4/Biblio.pm (-2 / +2 lines)
Lines 3004-3012 sub ModBiblioMarc { Link Here
3004
        }
3004
        }
3005
    )->store;
3005
    )->store;
3006
3006
3007
    if ( $m_rs->stripped_nonxml && ref $options->{warnings} eq 'ARRAY' ) {
3007
    if ( $m_rs->nonxml_stripped && ref $options->{warnings} eq 'ARRAY' ) {
3008
        push @{ $options->{warnings} },
3008
        push @{ $options->{warnings} },
3009
            { type => 'nonxml_stripped', message => $m_rs->stripped_nonxml };
3009
            { type => 'nonxml_stripped', message => $m_rs->nonxml_stripped };
3010
    }
3010
    }
3011
3011
3012
    unless ($skip_record_index) {
3012
    unless ($skip_record_index) {
(-)a/Koha/Biblio/Metadata.pm (-19 / +7 lines)
Lines 48-54 to committing to the database. Link Here
48
48
49
If the MARCXML cannot be parsed but can be recovered by stripping non-XML
49
If the MARCXML cannot be parsed but can be recovered by stripping non-XML
50
characters (C<StripNonXmlChars>), the stripped version is saved and
50
characters (C<StripNonXmlChars>), the stripped version is saved and
51
C<stripped_nonxml> is set on the object so callers can notify the user.
51
C<nonxml_stripped> is persisted on the row so callers and the UI can notify the user.
52
52
53
If the MARCXML cannot be recovered at all, a
53
If the MARCXML cannot be recovered at all, a
54
I<Koha::Exceptions::Metadata::Invalid> exception is thrown.
54
I<Koha::Exceptions::Metadata::Invalid> exception is thrown.
Lines 69-75 sub store { Link Here
69
        };
69
        };
70
        my $marcxml_error = $@;
70
        my $marcxml_error = $@;
71
        chomp $marcxml_error;
71
        chomp $marcxml_error;
72
        unless ($marcxml) {
72
        if ($marcxml) {
73
74
            # Clean parse – clear any previously recorded stripping
75
            $self->nonxml_stripped(undef);
76
        } else {
73
77
74
            # Attempt recovery by stripping non-XML characters
78
            # Attempt recovery by stripping non-XML characters
75
            my $stripped_metadata = StripNonXmlChars( $self->metadata );
79
            my $stripped_metadata = StripNonXmlChars( $self->metadata );
Lines 85-91 sub store { Link Here
85
                    )
89
                    )
86
                );
90
                );
87
                $self->metadata($stripped_metadata);
91
                $self->metadata($stripped_metadata);
88
                $self->{_stripped_nonxml} = $marcxml_error;
92
                $self->nonxml_stripped($marcxml_error);
89
            } else {
93
            } else {
90
94
91
                # Truly unrecoverable
95
                # Truly unrecoverable
Lines 104-125 sub store { Link Here
104
    return $self->SUPER::store;
108
    return $self->SUPER::store;
105
}
109
}
106
110
107
=head3 stripped_nonxml
108
109
    if ( my $error = $metadata->stripped_nonxml ) {
110
        # warn user that non-XML characters were removed on last store()
111
    }
112
113
Returns the original decode error string if non-XML characters were stripped
114
during the most recent call to C<store()>, or C<undef> otherwise.
115
116
=cut
117
118
sub stripped_nonxml {
119
    my $self = shift;
120
    return $self->{_stripped_nonxml};
121
}
122
123
=head3 record
111
=head3 record
124
112
125
my $record = $metadata->record;
113
my $record = $metadata->record;
(-)a/Koha/Import/Record.pm (-1 / +5 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Carp;
20
use Carp;
21
use MARC::Record;
21
use MARC::Record;
22
22
23
use C4::Charset qw( StripNonXmlChars );
23
use C4::Context;
24
use C4::Context;
24
use C4::Biblio          qw(ModBiblio);
25
use C4::Biblio          qw(ModBiblio);
25
use C4::AuthoritiesMarc qw(GuessAuthTypeCode ModAuthority);
26
use C4::AuthoritiesMarc qw(GuessAuthTypeCode ModAuthority);
Lines 56-62 sub get_marc_record { Link Here
56
        $format = 'UNIMARCAUTH';
57
        $format = 'UNIMARCAUTH';
57
    }
58
    }
58
59
59
    my $record = MARC::Record->new_from_xml( $self->marcxml, 'UTF-8', $format );
60
    my $record = eval { MARC::Record->new_from_xml( $self->marcxml, 'UTF-8', $format ) };
61
    unless ($record) {
62
        $record = eval { MARC::Record->new_from_xml( StripNonXmlChars( $self->marcxml ), 'UTF-8', $format ) };
63
    }
60
64
61
    return $record;
65
    return $record;
62
}
66
}
(-)a/Koha/Schema/Result/BiblioMetadata.pm (+9 lines)
Lines 52-57 __PACKAGE__->table("biblio_metadata"); Link Here
52
  data_type: 'longtext'
52
  data_type: 'longtext'
53
  is_nullable: 0
53
  is_nullable: 0
54
54
55
=head2 nonxml_stripped
56
57
  data_type: 'mediumtext'
58
  is_nullable: 1
59
60
Parse error message recorded when non-XML characters were stripped on last store().
61
55
=head2 timestamp
62
=head2 timestamp
56
63
57
  data_type: 'timestamp'
64
  data_type: 'timestamp'
Lines 80-85 __PACKAGE__->add_columns( Link Here
80
  { data_type => "varchar", is_nullable => 0, size => 16 },
87
  { data_type => "varchar", is_nullable => 0, size => 16 },
81
  "metadata",
88
  "metadata",
82
  { data_type => "longtext", is_nullable => 0 },
89
  { data_type => "longtext", is_nullable => 0 },
90
  "nonxml_stripped",
91
  { data_type => "mediumtext", is_nullable => 1 },
83
  "timestamp",
92
  "timestamp",
84
  {
93
  {
85
    data_type => "timestamp",
94
    data_type => "timestamp",
(-)a/catalogue/MARCdetail.pl (-1 / +2 lines)
Lines 120-126 if ( $query->cookie("searchToOrder") ) { Link Here
120
    );
120
    );
121
}
121
}
122
122
123
$template->param( ocoins => $biblio_object->get_coins );
123
$template->param( ocoins          => $biblio_object->get_coins );
124
$template->param( nonxml_stripped => $biblio_object->metadata->nonxml_stripped );
124
125
125
#count of item linked
126
#count of item linked
126
my $itemcount = $biblio_object->items->count;
127
my $itemcount = $biblio_object->items->count;
(-)a/catalogue/detail.pl (-1 / +2 lines)
Lines 176-182 my $marcflavour = C4::Context->preference("marcflavour"); Link Here
176
176
177
$template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") );
177
$template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") );
178
178
179
$template->param( ocoins => !$invalid_marc_record ? $biblio->get_coins : undef );
179
$template->param( ocoins          => !$invalid_marc_record ? $biblio->get_coins : undef );
180
$template->param( nonxml_stripped => $biblio->metadata->nonxml_stripped );
180
181
181
# some useful variables for enhanced content;
182
# some useful variables for enhanced content;
182
# in each case, we're grabbing the first value we find in
183
# in each case, we're grabbing the first value we find in
(-)a/installer/data/mysql/atomicupdate/bug_35104.pl (+23 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_success say_info);
3
4
return {
5
    bug_number  => "35104",
6
    description => "Add nonxml_stripped column to biblio_metadata",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        unless ( column_exists( 'biblio_metadata', 'nonxml_stripped' ) ) {
12
            $dbh->do(
13
                q{
14
                    ALTER TABLE biblio_metadata
15
                        ADD COLUMN `nonxml_stripped` mediumtext NULL DEFAULT NULL
16
                        COMMENT 'parse error message recorded when non-XML characters were stripped on last store()'
17
                        AFTER metadata
18
                }
19
            );
20
            say $out "Added new column 'biblio_metadata.nonxml_stripped'";
21
        }
22
    },
23
};
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt (+10 lines)
Lines 68-73 Link Here
68
            </select>
68
            </select>
69
        </strong></p
69
        </strong></p
70
    >
70
    >
71
    [% IF nonxml_stripped %]
72
        <div class="alert alert-warning">
73
            <h1>Record was automatically modified</h1>
74
            <p
75
                >Non-XML characters were stripped from this record when it was last saved. Please <a href="/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% biblionumber | uri %]">review and re-save the record</a> to confirm the data
76
                is correct.</p
77
            >
78
            <pre class="error">[% nonxml_stripped | html %]</pre>
79
        </div>
80
    [% END %]
71
    [% IF ( ocoins ) %]
81
    [% IF ( ocoins ) %]
72
        <!-- COinS / OpenURL -->
82
        <!-- COinS / OpenURL -->
73
        <span class="Z3988" title="[% ocoins | html %]"></span>
83
        <span class="Z3988" title="[% ocoins | html %]"></span>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt (+10 lines)
Lines 102-107 Link Here
102
    <!-- /.row -->
102
    <!-- /.row -->
103
    <div class="row">
103
    <div class="row">
104
        <div id="catalogue_detail_biblio" class="col">
104
        <div id="catalogue_detail_biblio" class="col">
105
            [% IF nonxml_stripped %]
106
                <div class="alert alert-warning">
107
                    <h1>Record was automatically modified</h1>
108
                    <p
109
                        >Non-XML characters were stripped from this record when it was last saved. Please <a href="/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% biblio.biblionumber | uri %]">review and re-save the record</a> to
110
                        confirm the data is correct.</p
111
                    >
112
                    <pre class="error">[% nonxml_stripped | html %]</pre>
113
                </div>
114
            [% END %]
105
            [% IF decoding_error || analytics_error %]
115
            [% IF decoding_error || analytics_error %]
106
                <div class="alert alert-warning">
116
                <div class="alert alert-warning">
107
                    <h1>Errors found</h1>
117
                    <h1>Errors found</h1>
(-)a/t/db_dependent/Koha/Biblio/Metadata.t (-3 / +2 lines)
Lines 75-81 EOX Link Here
75
75
76
        lives_ok { $record->store }
76
        lives_ok { $record->store }
77
        'Valid MARCXML record stores successfully';
77
        'Valid MARCXML record stores successfully';
78
        is( $record->stripped_nonxml, undef, 'stripped_nonxml is undef for clean record' );
78
        is( $record->nonxml_stripped, undef, 'nonxml_stripped is undef for clean record' );
79
79
80
        $schema->storage->txn_rollback;
80
        $schema->storage->txn_rollback;
81
    };
81
    };
Lines 104-110 EOX Link Here
104
104
105
        lives_ok { $record->store } 'MARCXML with strippable characters stores successfully';
105
        lives_ok { $record->store } 'MARCXML with strippable characters stores successfully';
106
106
107
        ok( $record->stripped_nonxml, 'stripped_nonxml is set after stripping' );
107
        ok( $record->nonxml_stripped, 'nonxml_stripped is set after stripping' );
108
108
109
        my $stored = Koha::Biblio::Metadatas->find( { biblionumber => $biblio->{biblionumber}, format => 'marcxml' } );
109
        my $stored = Koha::Biblio::Metadatas->find( { biblionumber => $biblio->{biblionumber}, format => 'marcxml' } );
110
        is(
110
        is(
111
- 

Return to bug 35104