From 8d689ff50a6989f24084f11cbb6adc3a9e779002 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 22 Aug 2024 15:13:01 -0300 Subject: [PATCH] Bug 37711: DB update Signed-off-by: Martin Renvoize --- .../data/mysql/atomicupdate/bug_37711.pl | 52 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 3 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100755 installer/data/mysql/atomicupdate/bug_37711.pl diff --git a/installer/data/mysql/atomicupdate/bug_37711.pl b/installer/data/mysql/atomicupdate/bug_37711.pl new file mode 100755 index 00000000000..6412c61235d --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_37711.pl @@ -0,0 +1,52 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_failure say_success say_info); + +return { + bug_number => "37711", + description => "Allow setting auto-register per interface (identity providers)", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + if ( !column_exists( 'identity_provider_domains', 'auto_register_opac' ) ) { + $dbh->do( + q{ + ALTER TABLE identity_provider_domains + ADD COLUMN `auto_register_opac` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Allow user auto register (OPAC)' + AFTER `allow_staff`; + } + ); + say $out "Added column 'identity_provider_domains.auto_register_opac'"; + } + + if ( !column_exists( 'identity_provider_domains', 'auto_register_staff' ) ) { + $dbh->do( + q{ + ALTER TABLE identity_provider_domains + ADD COLUMN `auto_register_staff` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Allow user auto register (OPAC)' + AFTER `auto_register_opac`; + } + ); + say $out "Added column 'identity_provider_domains.auto_register_staff'"; + } + + # if this is a sane upgrade, then the column exists and to keep the current + # behavior we only enable OPAC auto-register, if enabled previously + if ( column_exists( 'identity_provider_domains', 'auto_register' ) ) { + $dbh->do( + q{ + UPDATE identity_provider_domains + SET auto_register_opac=auto_register; + } + ); + + $dbh->do( + q{ + ALTER TABLE identity_provider_domains + DROP COLUMN `auto_register`; + } + ); + say $out "Removed column 'identity_provider_domains.auto_register'"; + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 442f683e02f..5a492b75292 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -3534,12 +3534,13 @@ CREATE TABLE `identity_provider_domains` ( `identity_provider_domain_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique key, used to identify providers domain', `identity_provider_id` int(11) NOT NULL COMMENT 'Reference to provider', `domain` varchar(100) DEFAULT NULL COMMENT 'Domain name. If null means all domains', - `auto_register` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Allow user auto register', `update_on_auth` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Update user data on auth login', `default_library_id` varchar(10) DEFAULT NULL COMMENT 'Default library to create user if auto register is enabled', `default_category_id` varchar(10) DEFAULT NULL COMMENT 'Default category to create user if auto register is enabled', `allow_opac` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Allow provider from opac interface', `allow_staff` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Allow provider from staff interface', + `auto_register_opac` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Allow user auto register (OPAC)', + `auto_register_staff` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Allow user auto register (Staff interface)', PRIMARY KEY (`identity_provider_domain_id`), UNIQUE KEY `identity_provider_id` (`identity_provider_id`,`domain`), KEY `domain` (`domain`), -- 2.47.0