From 1038972196ecded567b6c49d541ecc8d35e0ae91 Mon Sep 17 00:00:00 2001 From: Jan Kissig Date: Mon, 16 Dec 2024 09:09:02 +0000 Subject: [PATCH] Bug 35380: Change record sources to by systemdefined This changes the structure of record source with an is_system column which controls wheter this value can be deleted. Also predefined values are inserted to reflect the default hard coded values from 'Record overlay rules' sources --- Koha/RecordSource.pm | 14 ++++++++ api/v1/swagger/definitions/record_source.yaml | 4 +++ .../data/mysql/atomicupdate/bug_35380.pl | 36 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 4 ++- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 installer/data/mysql/atomicupdate/bug_35380.pl diff --git a/Koha/RecordSource.pm b/Koha/RecordSource.pm index 54f7921b6d..d92401f0dd 100644 --- a/Koha/RecordSource.pm +++ b/Koha/RecordSource.pm @@ -46,6 +46,20 @@ sub usage_count { return $self->_result->biblio_metadatas->count(); } +=head3 delete + +Overridden delete method to prevent system default deletions + +=cut + +sub delete { + my ($self) = @_; + + Koha::Exceptions::CannotDeleteDefault->throw if $self->is_system; + + return $self->SUPER::delete; +} + =head2 Internal methods =head3 _type diff --git a/api/v1/swagger/definitions/record_source.yaml b/api/v1/swagger/definitions/record_source.yaml index 4bd3f05265..6c1ff382eb 100644 --- a/api/v1/swagger/definitions/record_source.yaml +++ b/api/v1/swagger/definitions/record_source.yaml @@ -14,6 +14,10 @@ properties: usage_count: description: Record source usage count (x-koha-embed) type: integer + is_system: + description: Is this record source system or not + type: boolean + readOnly: true additionalProperties: false required: - name diff --git a/installer/data/mysql/atomicupdate/bug_35380.pl b/installer/data/mysql/atomicupdate/bug_35380.pl new file mode 100644 index 0000000000..5f967cfed6 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_35380.pl @@ -0,0 +1,36 @@ +use Modern::Perl; + +return { + bug_number => "35380", + description => "Add new unique name to record sources, add default record sources, add is_system column to default record sources.", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + + # change name to be unique + if ( !unique_key_exists('record_sources', 'name') ) { + $dbh->do(q{ + ALTER TABLE record_sources + ADD UNIQUE KEY name (`name`) + }); + say $out "Added unique key 'name' "; + } + + # add column is system + unless ( column_exists('record_sources', 'is_system') ) { + $dbh->do(q{ ALTER TABLE record_sources ADD COLUMN `is_system` TINYINT(1) NOT NULL DEFAULT 0 AFTER can_be_edited }); + say $out "Added column 'record_sources.is_system'"; + } + + $dbh->do(q{ + INSERT IGNORE INTO record_sources ( name, can_be_edited, is_system ) + VALUES + ('batchmod', 0, 1 ), + ('intranet', 0, 1 ), + ('batchimport', 0, 1 ), + ('z3950', 0, 1 ), + ('bulkmarcimport', 0, 1 ), + ('import_lexile', 0, 1 ) + }); + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 3bf15c1007..d0d3485b6b 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -5540,7 +5540,9 @@ CREATE TABLE `record_sources` ( `record_source_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Primary key for the `record_sources` table', `name` text NOT NULL COMMENT 'User defined name for the record source', `can_be_edited` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'If records from this source can be edited', - PRIMARY KEY (`record_source_id`) + `is_system` tinyint(1) NOT NULL DEFAULT 0, + PRIMARY KEY (`record_source_id`), + UNIQUE KEY `name` (`name`(191)) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- 2.39.5