|
Lines 24-29
use C4::Biblio qw( GetMarcFromKohaField );
Link Here
|
| 24 |
use C4::Charset qw( StripNonXmlChars ); |
24 |
use C4::Charset qw( StripNonXmlChars ); |
| 25 |
use C4::Items qw( GetMarcItem ); |
25 |
use C4::Items qw( GetMarcItem ); |
| 26 |
|
26 |
|
|
|
27 |
use Koha::Biblio::Metadata::Error; |
| 28 |
use Koha::Biblio::Metadata::Errors; |
| 27 |
use Koha::Database; |
29 |
use Koha::Database; |
| 28 |
use Koha::Exceptions::Metadata; |
30 |
use Koha::Exceptions::Metadata; |
| 29 |
use Koha::Logger; |
31 |
use Koha::Logger; |
|
Lines 47-54
Metadata specific store method to catch errant characters prior
Link Here
|
| 47 |
to committing to the database. |
49 |
to committing to the database. |
| 48 |
|
50 |
|
| 49 |
If the MARCXML cannot be parsed but can be recovered by stripping non-XML |
51 |
If the MARCXML cannot be parsed but can be recovered by stripping non-XML |
| 50 |
characters (C<StripNonXmlChars>), the stripped version is saved and |
52 |
characters (C<StripNonXmlChars>), the stripped version is saved and a |
| 51 |
C<nonxml_stripped> is persisted on the row so callers and the UI can notify the user. |
53 |
C<nonxml_stripped> error row is written to C<biblio_metadata_errors> so |
|
|
54 |
callers and the UI can notify the user. Any pre-existing C<nonxml_stripped> |
| 55 |
error is removed when the record parses cleanly. |
| 52 |
|
56 |
|
| 53 |
If the MARCXML cannot be recovered at all, a |
57 |
If the MARCXML cannot be recovered at all, a |
| 54 |
I<Koha::Exceptions::Metadata::Invalid> exception is thrown. |
58 |
I<Koha::Exceptions::Metadata::Invalid> exception is thrown. |
|
Lines 58-63
I<Koha::Exceptions::Metadata::Invalid> exception is thrown.
Link Here
|
| 58 |
sub store { |
62 |
sub store { |
| 59 |
my $self = shift; |
63 |
my $self = shift; |
| 60 |
|
64 |
|
|
|
65 |
my $nonxml_error_message; |
| 66 |
|
| 61 |
# Check marcxml will roundtrip |
67 |
# Check marcxml will roundtrip |
| 62 |
if ( $self->format eq 'marcxml' ) { |
68 |
if ( $self->format eq 'marcxml' ) { |
| 63 |
|
69 |
|
|
Lines 69-79
sub store {
Link Here
|
| 69 |
}; |
75 |
}; |
| 70 |
my $marcxml_error = $@; |
76 |
my $marcxml_error = $@; |
| 71 |
chomp $marcxml_error; |
77 |
chomp $marcxml_error; |
| 72 |
if ($marcxml) { |
|
|
| 73 |
|
78 |
|
| 74 |
# Clean parse – clear any previously recorded stripping |
79 |
unless ($marcxml) { |
| 75 |
$self->nonxml_stripped(undef); |
|
|
| 76 |
} else { |
| 77 |
|
80 |
|
| 78 |
# Attempt recovery by stripping non-XML characters |
81 |
# Attempt recovery by stripping non-XML characters |
| 79 |
my $stripped_metadata = StripNonXmlChars( $self->metadata ); |
82 |
my $stripped_metadata = StripNonXmlChars( $self->metadata ); |
|
Lines 81-87
sub store {
Link Here
|
| 81 |
|
84 |
|
| 82 |
if ($stripped_marcxml) { |
85 |
if ($stripped_marcxml) { |
| 83 |
|
86 |
|
| 84 |
# Stripping fixed it – save the clean version and record what happened |
87 |
# Stripping fixed it – save the clean version |
| 85 |
Koha::Logger->get->warn( |
88 |
Koha::Logger->get->warn( |
| 86 |
sprintf( |
89 |
sprintf( |
| 87 |
"Non-XML characters stripped from bibliographic record (biblionumber=%s): %s", |
90 |
"Non-XML characters stripped from bibliographic record (biblionumber=%s): %s", |
|
Lines 89-95
sub store {
Link Here
|
| 89 |
) |
92 |
) |
| 90 |
); |
93 |
); |
| 91 |
$self->metadata($stripped_metadata); |
94 |
$self->metadata($stripped_metadata); |
| 92 |
$self->nonxml_stripped($marcxml_error); |
95 |
$nonxml_error_message = $marcxml_error; |
| 93 |
} else { |
96 |
} else { |
| 94 |
|
97 |
|
| 95 |
# Truly unrecoverable |
98 |
# Truly unrecoverable |
|
Lines 105-111
sub store {
Link Here
|
| 105 |
} |
108 |
} |
| 106 |
} |
109 |
} |
| 107 |
|
110 |
|
| 108 |
return $self->SUPER::store; |
111 |
$self->SUPER::store; |
|
|
112 |
|
| 113 |
# Sync nonxml_stripped error rows: clear any existing, then re-add if needed |
| 114 |
$self->metadata_errors->search( { error_type => 'nonxml_stripped' } )->delete; |
| 115 |
if ($nonxml_error_message) { |
| 116 |
Koha::Biblio::Metadata::Error->new( |
| 117 |
{ |
| 118 |
metadata_id => $self->id, |
| 119 |
error_type => 'nonxml_stripped', |
| 120 |
message => $nonxml_error_message, |
| 121 |
} |
| 122 |
)->store; |
| 123 |
} |
| 124 |
|
| 125 |
return $self; |
| 126 |
} |
| 127 |
|
| 128 |
=head3 metadata_errors |
| 129 |
|
| 130 |
my $errors = $metadata->metadata_errors; |
| 131 |
|
| 132 |
Returns a I<Koha::Biblio::Metadata::Errors> resultset for errors associated |
| 133 |
with this metadata record. |
| 134 |
|
| 135 |
=cut |
| 136 |
|
| 137 |
sub metadata_errors { |
| 138 |
my ($self) = @_; |
| 139 |
return Koha::Biblio::Metadata::Errors->_new_from_dbic( scalar $self->_result->biblio_metadata_errors ); |
| 109 |
} |
140 |
} |
| 110 |
|
141 |
|
| 111 |
=head3 record |
142 |
=head3 record |