From ccf66e6b404ddf7941b43b18f563029cc62433cc Mon Sep 17 00:00:00 2001
From: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Date: Fri, 11 Aug 2023 14:16:51 +0000
Subject: [PATCH] Bug 25393: atomicupdate file

Signed-off-by: Andrew Fuerste-Henry <andrewfh@dubcolib.org>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
---
 .../data/mysql/atomicupdate/bug_25393.pl      | 40 +++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100755 installer/data/mysql/atomicupdate/bug_25393.pl

diff --git a/installer/data/mysql/atomicupdate/bug_25393.pl b/installer/data/mysql/atomicupdate/bug_25393.pl
new file mode 100755
index 0000000000..1b8fd1b5ff
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug_25393.pl
@@ -0,0 +1,40 @@
+use Modern::Perl;
+
+return {
+    bug_number  => "25393",
+    description => "Create separate 'no automatic renewal before' rule",
+    up => sub {
+        my ($args) = @_;
+        my ( $dbh, $out ) = @$args{qw(dbh out)};
+
+        my $rules = $dbh->selectall_arrayref(
+            q|SELECT * FROM circulation_rules WHERE rule_name = "noautorenewalbefore"|,
+            { Slice => {} }
+        );
+
+        if(!scalar @{$rules}){
+            my $existing_rules = $dbh->selectall_arrayref(
+                q|SELECT * FROM circulation_rules WHERE rule_name = "norenewalbefore"|,
+                { Slice => {} }
+            );
+
+            my $insert_sth = $dbh->prepare(
+                q{INSERT INTO circulation_rules ( branchcode, categorycode, itemtype, rule_name, rule_value ) VALUES (?, ?, ?, ?, ?)}
+            );
+
+            for my $existing_rule ( @{$existing_rules} ) {
+                $insert_sth->execute(
+                    $existing_rule->{branchcode},
+                    $existing_rule->{categorycode},
+                    $existing_rule->{itemtype},
+                    'noautorenewalbefore',
+                    $existing_rule->{rule_value}
+                );
+            }
+            say $out "Bug 25939: New circulation rule 'noautorenewalbefore' has been added. Defaulting value to 'norenewalbefore'.";
+        }else{
+            say $out "Bug 25939: Circulation rule 'noautorenewalbefore' found. Skipping update.";
+        }
+
+        },
+};
-- 
2.30.2