From b13a3eaddbd8489ef8953265db73b59a0e53d9c5 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Sat, 28 Feb 2026 17:01:32 +0000 Subject: [PATCH] Bug 35104: Add biblio_metadata_errors table The preceding signed-off commits (69a6b1c09f7..bfb14bb949e) established an approach where Metadata::store throws a Koha::Exceptions::Metadata::Invalid exception when non-XML characters are encountered, requiring every caller to catch and handle the exception explicitly. Building on that foundation, we change direction here: instead of throwing, Metadata::store will strip non-XML characters gracefully on save and persist structured error details in a new biblio_metadata_errors table. This will give cataloguers a clear view of which fields were affected, with context snippets pointing to the exact character positions, and allows them to review and confirm or correct the data before marking the errors as resolved. The new biblio_metadata_errors table supports multiple per-field error records per metadata row. Sponsored-by: OpenFifth --- .../data/mysql/atomicupdate/bug_35104.pl | 29 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 19 ++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 installer/data/mysql/atomicupdate/bug_35104.pl diff --git a/installer/data/mysql/atomicupdate/bug_35104.pl b/installer/data/mysql/atomicupdate/bug_35104.pl new file mode 100755 index 00000000000..bd52d9ca266 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_35104.pl @@ -0,0 +1,29 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_success say_info); + +return { + bug_number => "35104", + description => "Add biblio_metadata_errors table for normalised error tracking", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + unless ( TableExists('biblio_metadata_errors') ) { + $dbh->do( + q{ + CREATE TABLE `biblio_metadata_errors` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `metadata_id` int(11) NOT NULL COMMENT 'FK to biblio_metadata.id', + `error_type` varchar(64) NOT NULL COMMENT 'Error type identifier, e.g. nonxml_stripped', + `message` mediumtext DEFAULT NULL COMMENT 'Error message details', + `created_on` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`), + KEY `biblio_metadata_errors_fk_1` (`metadata_id`), + CONSTRAINT `biblio_metadata_errors_fk_1` FOREIGN KEY (`metadata_id`) REFERENCES `biblio_metadata` (`id`) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci + } + ); + say $out "Added new table 'biblio_metadata_errors'"; + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 1222ef6387c..c2fd8639601 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1159,6 +1159,25 @@ CREATE TABLE `biblio_metadata` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `biblio_metadata_errors` +-- + +DROP TABLE IF EXISTS `biblio_metadata_errors`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `biblio_metadata_errors` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `metadata_id` int(11) NOT NULL COMMENT 'FK to biblio_metadata.id', + `error_type` varchar(64) NOT NULL COMMENT 'Error type identifier, e.g. nonxml_stripped', + `message` mediumtext DEFAULT NULL COMMENT 'Error message details', + `created_on` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`), + KEY `biblio_metadata_errors_fk_1` (`metadata_id`), + CONSTRAINT `biblio_metadata_errors_fk_1` FOREIGN KEY (`metadata_id`) REFERENCES `biblio_metadata` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `biblioitems` -- -- 2.53.0