From 83b2f6412bcd01ddf041ec47226641330628c180 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Mon, 24 Jul 2023 13:51:43 +0000 Subject: [PATCH] Bug 34355: DB schema and atomic update file --- Koha/Schema/Result/Aqbookseller.pm | 19 +- Koha/Schema/Result/Aqbudget.pm | 19 +- Koha/Schema/Result/MarcOrderAccount.pm | 208 ++++++++++++++++++ .../bug_34355-add_marc_order_accounts.pl | 43 ++++ installer/data/mysql/kohastructure.sql | 26 +++ installer/data/mysql/mandatory/sysprefs.sql | 1 + 6 files changed, 312 insertions(+), 4 deletions(-) create mode 100644 Koha/Schema/Result/MarcOrderAccount.pm create mode 100644 installer/data/mysql/atomicupdate/bug_34355-add_marc_order_accounts.pl diff --git a/Koha/Schema/Result/Aqbookseller.pm b/Koha/Schema/Result/Aqbookseller.pm index f9ce48cae4..8e49ddef7a 100644 --- a/Koha/Schema/Result/Aqbookseller.pm +++ b/Koha/Schema/Result/Aqbookseller.pm @@ -494,6 +494,21 @@ __PACKAGE__->belongs_to( }, ); +=head2 marc_order_accounts + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "marc_order_accounts", + "Koha::Schema::Result::MarcOrderAccount", + { "foreign.vendor_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 vendor_edi_accounts Type: has_many @@ -510,8 +525,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-06-30 09:54:35 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:xjeOqpcdN3Kb1wmLGDjzLg +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-07-12 16:43:09 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:4L14+X0NSAgyWGrKaFPR5w __PACKAGE__->add_columns( '+active' => { is_boolean => 1 }, diff --git a/Koha/Schema/Result/Aqbudget.pm b/Koha/Schema/Result/Aqbudget.pm index 182a7e39c5..d91cb19ec8 100644 --- a/Koha/Schema/Result/Aqbudget.pm +++ b/Koha/Schema/Result/Aqbudget.pm @@ -308,6 +308,21 @@ __PACKAGE__->belongs_to( }, ); +=head2 marc_order_accounts + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "marc_order_accounts", + "Koha::Schema::Result::MarcOrderAccount", + { "foreign.budget_id" => "self.budget_id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 suggestions Type: has_many @@ -349,8 +364,8 @@ Composing rels: L -> borrowernumber __PACKAGE__->many_to_many("borrowernumbers", "aqbudgetborrowers", "borrowernumber"); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:sl+TGQXY85UWwS+Ld/vvyQ +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-07-12 16:51:53 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:pCgGAZOv1TPHe6LIQhb1BQ __PACKAGE__->belongs_to( "budget", diff --git a/Koha/Schema/Result/MarcOrderAccount.pm b/Koha/Schema/Result/MarcOrderAccount.pm new file mode 100644 index 0000000000..88f6119290 --- /dev/null +++ b/Koha/Schema/Result/MarcOrderAccount.pm @@ -0,0 +1,208 @@ +use utf8; +package Koha::Schema::Result::MarcOrderAccount; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +=head1 NAME + +Koha::Schema::Result::MarcOrderAccount + +=cut + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +=head1 TABLE: C + +=cut + +__PACKAGE__->table("marc_order_accounts"); + +=head1 ACCESSORS + +=head2 id + + data_type: 'integer' + is_auto_increment: 1 + is_nullable: 0 + +unique identifier and primary key + +=head2 description + + data_type: 'varchar' + is_nullable: 0 + size: 250 + +description of this account + +=head2 vendor_id + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 1 + +vendor id for this account + +=head2 budget_id + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 1 + +budget id for this account + +=head2 download_directory + + data_type: 'mediumtext' + is_nullable: 1 + +download directory for this account + +=head2 matcher_id + + data_type: 'integer' + is_nullable: 1 + +the id of the match rule used (matchpoints.matcher_id) + +=head2 overlay_action + + data_type: 'varchar' + is_nullable: 1 + size: 50 + +how to handle duplicate records + +=head2 nomatch_action + + data_type: 'varchar' + is_nullable: 1 + size: 50 + +how to handle records where no match is found + +=head2 item_action + + data_type: 'varchar' + is_nullable: 1 + size: 50 + +what to do with item records + +=head2 parse_items + + data_type: 'tinyint' + is_nullable: 1 + +should items be parsed + +=head2 record_type + + data_type: 'varchar' + is_nullable: 1 + size: 50 + +type of record in the file + +=head2 encoding + + data_type: 'varchar' + is_nullable: 1 + size: 50 + +file encoding + +=cut + +__PACKAGE__->add_columns( + "id", + { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, + "description", + { data_type => "varchar", is_nullable => 0, size => 250 }, + "vendor_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, + "budget_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, + "download_directory", + { data_type => "mediumtext", is_nullable => 1 }, + "matcher_id", + { data_type => "integer", is_nullable => 1 }, + "overlay_action", + { data_type => "varchar", is_nullable => 1, size => 50 }, + "nomatch_action", + { data_type => "varchar", is_nullable => 1, size => 50 }, + "item_action", + { data_type => "varchar", is_nullable => 1, size => 50 }, + "parse_items", + { data_type => "tinyint", is_nullable => 1 }, + "record_type", + { data_type => "varchar", is_nullable => 1, size => 50 }, + "encoding", + { data_type => "varchar", is_nullable => 1, size => 50 }, +); + +=head1 PRIMARY KEY + +=over 4 + +=item * L + +=back + +=cut + +__PACKAGE__->set_primary_key("id"); + +=head1 RELATIONS + +=head2 budget + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "budget", + "Koha::Schema::Result::Aqbudget", + { budget_id => "budget_id" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); + +=head2 vendor + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "vendor", + "Koha::Schema::Result::Aqbookseller", + { id => "vendor_id" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); + + +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-07-18 16:31:16 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:vMLrmisXQnn2e60qW7ppnA + + +# You can replace this text with custom code or comments, and it will be preserved on regeneration +1; diff --git a/installer/data/mysql/atomicupdate/bug_34355-add_marc_order_accounts.pl b/installer/data/mysql/atomicupdate/bug_34355-add_marc_order_accounts.pl new file mode 100644 index 0000000000..f0a5f2ab21 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_34355-add_marc_order_accounts.pl @@ -0,0 +1,43 @@ +use Modern::Perl; + +return { + bug_number => "34355", + description => "Add a table to allow creation of MARC order accounts and a syspref to activate it.", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + + unless( TableExists('marc_order_accounts') ) { + $dbh->do(q{ + CREATE TABLE `marc_order_accounts` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier and primary key', + `description` varchar(250) NOT NULL COMMENT 'description of this account', + `vendor_id` int(11) DEFAULT NULL COMMENT 'vendor id for this account', + `budget_id` int(11) DEFAULT NULL COMMENT 'budget id for this account', + `download_directory` mediumtext DEFAULT NULL COMMENT 'download directory for this account', + `matcher_id` int(11) DEFAULT NULL COMMENT 'the id of the match rule used (matchpoints.matcher_id)', + `overlay_action` varchar(50) DEFAULT NULL COMMENT 'how to handle duplicate records', + `nomatch_action` varchar(50) DEFAULT NULL COMMENT 'how to handle records where no match is found', + `item_action` varchar(50) DEFAULT NULL COMMENT 'what to do with item records', + `parse_items` tinyint(1) DEFAULT NULL COMMENT 'should items be parsed', + `record_type` varchar(50) DEFAULT NULL COMMENT 'type of record in the file', + `encoding` varchar(50) DEFAULT NULL COMMENT 'file encoding', + PRIMARY KEY (`id`), + CONSTRAINT `marc_ordering_account_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `marc_ordering_account_ibfk_2` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + }); + + say $out "Added new table 'marc_order_accounts'"; + } else { + say $out "Table 'marc_order_accounts' already exists"; + } + + $dbh->do( + q{ + INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type) VALUES ('MarcOrderingAutomation', '0', 'NULL', 'Enables automatic order line creation from MARC records', 'YesNo'); + } + ); + + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index d91bd46b32..27f9ab4a6f 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -4092,6 +4092,32 @@ CREATE TABLE `marc_modification_templates` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `marc_order_accounts` +-- + +DROP TABLE IF EXISTS `marc_order_accounts`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `marc_order_accounts` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier and primary key', + `description` varchar(250) NOT NULL COMMENT 'description of this account', + `vendor_id` int(11) DEFAULT NULL COMMENT 'vendor id for this account', + `budget_id` int(11) DEFAULT NULL COMMENT 'budget id for this account', + `download_directory` mediumtext DEFAULT NULL COMMENT 'download directory for this account', + `matcher_id` int(11) DEFAULT NULL COMMENT 'the id of the match rule used (matchpoints.matcher_id)', + `overlay_action` varchar(50) DEFAULT NULL COMMENT 'how to handle duplicate records', + `nomatch_action` varchar(50) DEFAULT NULL COMMENT 'how to handle records where no match is found', + `item_action` varchar(50) DEFAULT NULL COMMENT 'what to do with item records', + `parse_items` tinyint(1) DEFAULT NULL COMMENT 'should items be parsed', + `record_type` varchar(50) DEFAULT NULL COMMENT 'type of record in the file', + `encoding` varchar(50) DEFAULT NULL COMMENT 'file encoding', + PRIMARY KEY (`id`), + CONSTRAINT `marc_ordering_account_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `marc_ordering_account_ibfk_2` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_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 `marc_overlay_rules` -- diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 2b2794106e..dadfe08690 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -373,6 +373,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('MarcFieldsToOrder','',NULL,'Set the mapping values for a new order line created from a MARC record in a staged file. In a YAML format.','textarea'), ('MarcItemFieldsToOrder','',NULL,'Set the mapping values for new item records created from a MARC record in a staged file. In a YAML format.','textarea'), ('MarkLostItemsAsReturned','batchmod,moredetail,cronjob,additem,pendingreserves,onpayment','claim_returned|batchmod|moredetail|cronjob|additem|pendingreserves|onpayment','Mark items as returned when flagged as lost','multiple'), +('MarcOrderingAutomation','0',NULL,'Enables automatic order line creation from MARC records','YesNo'), ('MARCOrgCode','OSt','','Define MARC Organization Code for MARC21 records - http://www.loc.gov/marc/organizations/orgshome.html','free'), ('MARCOverlayRules','0',NULL,'Use the MARC record overlay rules system to decide what actions to take for each field when modifying records.','YesNo'), ('MaxFine',NULL,'','Maximum fine a patron can have for all late returns at one moment. Single item caps are specified in the circulation rules matrix.','Integer'), -- 2.37.1 (Apple Git-137.1)