From 9abe5530f0548d46d6828507f5c580101ad35f88 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 4 Aug 2021 09:28:52 +0000 Subject: [PATCH] Bug 15067: DBRev 21.06.00.012 JD Amended DB rev: no need to display a warning, the creation of the unique key will fail with an appropriate error. Signed-off-by: Jonathan Druart --- Koha.pm | 2 +- .../bug_15067-add_additional_languages.perl | 81 ------------------- installer/data/mysql/updatedatabase.pl | 61 ++++++++++++++ 3 files changed, 62 insertions(+), 82 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_15067-add_additional_languages.perl diff --git a/Koha.pm b/Koha.pm index e9da245648..77a3f819cb 100644 --- a/Koha.pm +++ b/Koha.pm @@ -29,7 +29,7 @@ use vars qw{ $VERSION }; # - #4 : the developer version. The 4th number is the database subversion. # used by developers when the database changes. updatedatabase take care of the changes itself # and is automatically called by Auth.pm when needed. -$VERSION = "21.06.00.011"; +$VERSION = "21.06.00.012"; sub version { return $VERSION; diff --git a/installer/data/mysql/atomicupdate/bug_15067-add_additional_languages.perl b/installer/data/mysql/atomicupdate/bug_15067-add_additional_languages.perl deleted file mode 100644 index b6eda77e39..0000000000 --- a/installer/data/mysql/atomicupdate/bug_15067-add_additional_languages.perl +++ /dev/null @@ -1,81 +0,0 @@ -$DBversion = 'XXX'; -if( CheckVersion( $DBversion ) ) { - if( !unique_key_exists( 'language_subtag_registry', 'uniq_lang' ) ) { - my $dupe_languages = $dbh->selectall_arrayref(q| - SELECT subtag, type FROM language_subtag_registry GROUP BY subtag, type HAVING COUNT(*) > 1 - |, { Slice => {} }); - if ( @$dupe_languages ) { - warn "You have duplicated languages in the language_subtag_registry table in your database, unique constraint cannot be added"; - } else { - $dbh->do(q{ - ALTER TABLE language_subtag_registry - ADD UNIQUE KEY uniq_lang (subtag, type) - }); - } - }; - - if( !unique_key_exists( 'language_descriptions', 'uniq_desc' ) ) { - my $dupe_language_descriptions = $dbh->selectall_arrayref(q| - SELECT subtag, lang, type FROM language_descriptions GROUP BY subtag, lang, type HAVING COUNT(*) > 1 - |, { Slice => {} }); - if ( @$dupe_language_descriptions ) { - warn "You have duplicated language descriptionss in the language_descriptions table in your database, unique constraint cannot be added"; - } else { - $dbh->do(q{ - ALTER TABLE language_descriptions - ADD UNIQUE KEY uniq_desc (subtag, type, lang) - }); - } - }; - - if( !unique_key_exists( 'language_rfc4646_to_iso639', 'uniq_code' ) ) { - my $dupe_language_rfc = $dbh->selectall_arrayref(q| - SELECT rfc4646_subtag, iso639_2_code FROM language_rfc4646_to_iso639 GROUP BY rfc4646_subtag, iso639_2_code HAVING COUNT(*) > 1 - |, { Slice => {} }); - if ( @$dupe_language_rfc ) { - warn "You have duplicated languages in the language_rfc4646_to_iso639 in your database, unique constraint cannot be added"; - } else { - $dbh->do(q{ - ALTER TABLE language_rfc4646_to_iso639 - ADD UNIQUE KEY uniq_code (rfc4646_subtag, iso639_2_code) - }); - } - }; - - $dbh->do(q{ - INSERT IGNORE INTO language_subtag_registry (subtag, type, description, added) - VALUES - ('et', 'language', 'Estonian', now()), - ('lv', 'language', 'Latvian', now()), - ('lt', 'language', 'Lithuanian', now()), - ('iu', 'language', 'Inuktitut', now()), - ('ik', 'language', 'Inupiaq', now()) - }); - - $dbh->do(q{ - INSERT IGNORE INTO language_descriptions (subtag, type, lang, description) - VALUES - ('et', 'language', 'en', 'Estonian'), - ('et', 'language', 'et', 'Eesti'), - ('lv', 'language', 'en', 'Latvian'), - ('lv', 'language', 'lv', 'Latvija'), - ('lt', 'language', 'en', 'Lithuanian'), - ('lt', 'language', 'lt', 'Lietuvių'), - ('iu', 'language', 'en', 'Inuktitut'), - ('iu', 'language', 'iu', 'ᐃᓄᒃᑎᑐᑦ'), - ('ik', 'language', 'en', 'Inupiaq'), - ('ik', 'language', 'ik', 'Iñupiaq') - }); - - $dbh->do(q{ - INSERT IGNORE INTO language_rfc4646_to_iso639 (rfc4646_subtag, iso639_2_code) - VALUES - ('et', 'est'), - ('lv', 'lav'), - ('lt', 'lit'), - ('iu', 'iku'), - ('ik', 'ipk') - }); - - NewVersion( $DBversion, 15067, "Add missing languages"); -} diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 8f1d037791..fe2fe27d88 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -24481,6 +24481,67 @@ if( CheckVersion( $DBversion ) ) { NewVersion( $DBversion, 28567, "Set to NULL empty branches fields"); } +$DBversion = '21.06.00.012'; +if( CheckVersion( $DBversion ) ) { + if( !unique_key_exists( 'language_subtag_registry', 'uniq_lang' ) ) { + $dbh->do(q{ + ALTER TABLE language_subtag_registry + ADD UNIQUE KEY uniq_lang (subtag, type) + }); + }; + + if( !unique_key_exists( 'language_descriptions', 'uniq_desc' ) ) { + $dbh->do(q{ + ALTER TABLE language_descriptions + ADD UNIQUE KEY uniq_desc (subtag, type, lang) + }); + }; + + if( !unique_key_exists( 'language_rfc4646_to_iso639', 'uniq_code' ) ) { + $dbh->do(q{ + ALTER TABLE language_rfc4646_to_iso639 + ADD UNIQUE KEY uniq_code (rfc4646_subtag, iso639_2_code) + }); + }; + + $dbh->do(q{ + INSERT IGNORE INTO language_subtag_registry (subtag, type, description, added) + VALUES + ('et', 'language', 'Estonian', now()), + ('lv', 'language', 'Latvian', now()), + ('lt', 'language', 'Lithuanian', now()), + ('iu', 'language', 'Inuktitut', now()), + ('ik', 'language', 'Inupiaq', now()) + }); + + $dbh->do(q{ + INSERT IGNORE INTO language_descriptions (subtag, type, lang, description) + VALUES + ('et', 'language', 'en', 'Estonian'), + ('et', 'language', 'et', 'Eesti'), + ('lv', 'language', 'en', 'Latvian'), + ('lv', 'language', 'lv', 'Latvija'), + ('lt', 'language', 'en', 'Lithuanian'), + ('lt', 'language', 'lt', 'Lietuvių'), + ('iu', 'language', 'en', 'Inuktitut'), + ('iu', 'language', 'iu', 'ᐃᓄᒃᑎᑐᑦ'), + ('ik', 'language', 'en', 'Inupiaq'), + ('ik', 'language', 'ik', 'Iñupiaq') + }); + + $dbh->do(q{ + INSERT IGNORE INTO language_rfc4646_to_iso639 (rfc4646_subtag, iso639_2_code) + VALUES + ('et', 'est'), + ('lv', 'lav'), + ('lt', 'lit'), + ('iu', 'iku'), + ('ik', 'ipk') + }); + + NewVersion( $DBversion, 15067, "Add missing languages" ); +} + # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. my $update_dir = C4::Context->config('intranetdir') . '/installer/data/mysql/atomicupdate/'; -- 2.39.5