From d24e12a4cf3e3c0c9aa0052b57fd2be54f5961ef Mon Sep 17 00:00:00 2001
From: Mark Tompsett <mtompset@hotmail.com>
Date: Thu, 19 Jan 2017 09:16:37 -0500
Subject: [PATCH] Bug 17809: Add upgrade warning messages

TEST PLAN
---------
0) backup db
1) drop db and recreate empty
2) run fr-FR web install
3) update systempreferences set Value='16.00003' where variable='Version';
-- it is currently 16.00004 as of this writing
4) run fr-FR web install
   -- bottom of red warnings should be the check messages.
5) perlcritic -1 installer/data/mysql/atomic_update/bug_17809_pretty_red.perl
   -- $VERSION message, which we don't care about
   -- maybe a message about return value of print ignored.

Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
---
 .../mysql/atomicupdate/bug_17809_pretty_red.perl   | 50 ++++++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100755 installer/data/mysql/atomicupdate/bug_17809_pretty_red.perl

diff --git a/installer/data/mysql/atomicupdate/bug_17809_pretty_red.perl b/installer/data/mysql/atomicupdate/bug_17809_pretty_red.perl
new file mode 100755
index 0000000..957bec7
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug_17809_pretty_red.perl
@@ -0,0 +1,50 @@
+#!/usr/bin/perl -w
+
+use Modern::Perl;
+use Carp;
+use Koha::Database;
+
+$DBversion = 'XXX';
+if ( CheckVersion($DBversion) ) {
+    my $schema = Koha::Database->schema;
+    $schema->storage->txn_begin;
+
+    my $number_er = $schema->resultset('AuthorisedValue')->search(
+        {
+            authorised_value => 'ER'
+        }
+    )->count;
+    if ( $number_er > 1 ) {
+        carp
+          'Check for correct Germany [DE] and Eritrea [ER] authorised values.';
+    }
+    my $number_cc = $schema->resultset('AuthorisedValue')->search(
+        {
+            authorised_value => 'CC'
+        }
+    )->count;
+    if ( $number_cc > 1 ) {
+        carp
+'Check for duplicate authorised values of Cocos (Keeling) Islands [CC].';
+    }
+    my $number_gq = $schema->resultset('AuthorisedValue')->search(
+        {
+            authorised_value => 'GQ'
+        }
+    )->count;
+    if ( $number_gq > 1 ) {
+        carp 'Check for duplicate authorised values of Equatorial Guinea [GQ].';
+    }
+    my $number_pk = $schema->resultset('AuthorisedValue')->search(
+        {
+            authorised_value => 'PK'
+        }
+    )->count;
+    if ( $number_pk > 1 ) {
+        carp
+'Check if the authorized value for Poland [PL] matches Pakistan\'s [PK].';
+    }
+    SetVersion($DBversion);
+    print
+"Upgrade to $DBversion done (Bug 17809 - Correct some authorised values in fr-FR)\n";
+}
-- 
2.1.4