From f9a23815abb4c47b287d2c1fc77ee16e88d2bba6 Mon Sep 17 00:00:00 2001
From: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Date: Mon, 29 Jul 2024 10:58:48 +0000
Subject: [PATCH] Bug 30300: Add a patron expiry messaging preference
Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
---
...add_expiration_to_messaging_preferences.pl | 51 +++++++++++++++++++
.../sample_notices_message_attributes.sql | 3 +-
.../sample_notices_message_transports.sql | 5 +-
.../en/includes/messaging-preference-form.inc | 1 +
.../prog/en/modules/admin/categories.tt | 1 +
.../bootstrap/en/modules/opac-messaging.tt | 1 +
6 files changed, 60 insertions(+), 2 deletions(-)
create mode 100755 installer/data/mysql/atomicupdate/bug_30300-add_expiration_to_messaging_preferences.pl
diff --git a/installer/data/mysql/atomicupdate/bug_30300-add_expiration_to_messaging_preferences.pl b/installer/data/mysql/atomicupdate/bug_30300-add_expiration_to_messaging_preferences.pl
new file mode 100755
index 00000000000..db212f19b26
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug_30300-add_expiration_to_messaging_preferences.pl
@@ -0,0 +1,51 @@
+use Modern::Perl;
+
+return {
+ bug_number => "30300",
+ description => "Add Patron expiry to messaging preference",
+ up => sub {
+ my ($args) = @_;
+ my ( $dbh, $out ) = @$args{qw(dbh out)};
+ my $attribute = $dbh->do(
+ q{
+ SELECT message_attribute_id
+ FROM message_attributes
+ WHERE message_name = "Patron_Expiry"
+ }
+ );
+ unless ( $attribute == 1 ) {
+ $dbh->do(
+ q{
+ INSERT IGNORE INTO `message_attributes`
+ (message_name, `takes_days`)
+ VALUES ('Patron_Expiry', 0)
+ }
+ );
+ say $out "Message attribute added";
+ my $query = q{
+ SELECT message_attribute_id
+ FROM message_attributes
+ WHERE message_name = "Patron_Expiry"
+ };
+ my $sth = $dbh->prepare($query);
+ $sth->execute();
+ my $results = $sth->fetchrow_hashref;
+ my $message_attribute_id = $results->{message_attribute_id};
+
+ $dbh->do(
+ q{
+ INSERT IGNORE INTO `message_transports`
+ (`message_attribute_id`, `message_transport_type`, `is_digest`, `letter_module`, `letter_code`)
+ VALUES (?, 'email', 0, 'circulation', 'MEMBERSHIP_EXPIRY'),
+ (?, 'sms', 0, 'circulation', 'MEMBERSHIP_EXPIRY'),
+ (?, 'phone', 0, 'circulation', 'MEMBERSHIP_EXPIRY'),
+ ( ?, 'itiva', 0, 'circulation', 'MEMBERSHIP_EXPIRY' )
+ }, {}, $message_attribute_id, $message_attribute_id, $message_attribute_id, $message_attribute_id
+
+ );
+ say $out "MEMBERSHIP_EXPIRY added to message_transports";
+ } else {
+ say $out "Patron_Expiry message attribute exists, skipping update";
+ }
+ },
+ }
diff --git a/installer/data/mysql/mandatory/sample_notices_message_attributes.sql b/installer/data/mysql/mandatory/sample_notices_message_attributes.sql
index 31bf6d0b371..1b1659a67ef 100644
--- a/installer/data/mysql/mandatory/sample_notices_message_attributes.sql
+++ b/installer/data/mysql/mandatory/sample_notices_message_attributes.sql
@@ -12,4 +12,5 @@ values
(10, 'Hold_Reminder', 0),
(11, 'Ill_update', 0),
(12, 'Recall_Waiting', 0),
-(13, 'Recall_Requested', 0);
+(13, 'Recall_Requested', 0),
+(14, 'Patron_Expiry', 0);
diff --git a/installer/data/mysql/mandatory/sample_notices_message_transports.sql b/installer/data/mysql/mandatory/sample_notices_message_transports.sql
index 762fdb7ee50..c0395e09c92 100644
--- a/installer/data/mysql/mandatory/sample_notices_message_transports.sql
+++ b/installer/data/mysql/mandatory/sample_notices_message_transports.sql
@@ -52,4 +52,7 @@ values
(12, "phone", 0, "circulation", "PICKUP_RECALLED_ITEM"),
(13, "email", 0, "circulation", "RETURN_RECALLED_ITEM"),
(13, "sms", 0, "circulation", "RETURN_RECALLED_ITEM"),
-(13, "phone", 0, "circulation", "RETURN_RECALLED_ITEM");
+(13, "phone", 0, "circulation", "RETURN_RECALLED_ITEM"),
+(14, "email", 0, "members", "MEMBERSHIP_EXPIRY"),
+(14, "sms", 0, "members", "MEMBERSHIP_EXPIRY"),
+(14, "phone", 0, "members", "MEMBERSHIP_EXPIRY");
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc
index ecf35310f3f..9a0d4f5886c 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc
@@ -31,6 +31,7 @@
[% ELSE %]
<span>Item checkout</span>
[% END %]
+ [% ELSIF ( messaging_preference.Patron_Expiry ) %]<span>Patron expiry</span>
[% ELSIF ( messaging_preference.Ill_ready ) %]<span>Interlibrary loan ready</span>
[% ELSIF ( messaging_preference.Ill_unavailable ) %]<span>Interlibrary loan unavailable</span>
[% ELSIF ( messaging_preference.Ill_update ) %]<span>Interlibrary loan updated</span>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt
index a162519f98b..aa1785de62a 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt
@@ -715,6 +715,7 @@
[% ELSIF ( prefs.Ill_update ) %]<span>Interlibrary loan updated</span>
[% ELSIF ( prefs.Auto_Renewals ) %]<span>Auto renewal</span>
[% ELSIF ( prefs.Hold_Reminder ) %]<span>Hold reminder</span>
+ [% ELSIF ( prefs.Patron_Expiry ) %]<span>Patron expiry</span>
[% ELSE %]<span>Unknown</span>
[% END %]:
<strong>[% transport.transport | html %]</strong><br />
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt
index c25147453d1..5e45443173a 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt
@@ -73,6 +73,7 @@
[% ELSE %]
<span>Item checkout</span>
[% END %]
+ [% ELSIF ( messaging_preference.Patron_Expiry ) %]<span>Patron expiry</span>
[% ELSIF ( messaging_preference.Ill_ready ) %]<span>Interlibrary loan ready</span>
[% ELSIF ( messaging_preference.Ill_unavailable ) %]<span>Interlibrary loan unavailable</span>
[% ELSIF ( messaging_preference.Ill_update ) %]<span>Interlibrary loan updated</span>
--
2.47.1