From 09e82e255a71e0f8c91bdf0ca4d4ca864862a4f5 Mon Sep 17 00:00:00 2001 From: Andrew Isherwood Date: Thu, 21 Nov 2019 14:35:41 +0000 Subject: [PATCH] Bug 24083: Required atomic updates & DB update This patch adds: - An "UnseenRenewals" circulation syspref that enables/disables the functionality added in this bug - A change to the issuingrules table schema and a corresponding database upgrade to add issuingrules.unseen_renewals_allowed - A change to the issues & old_issues table schemas and corresponding database upgrades to add issues.unseen_renewals & old_issues.unseen_renewals - An update for the renewals letter to include a message for unseen renewals --- .../bug_24083_UnseenRenewals_syspref.perl | 6 +++++ .../bug_24083_add_issues_unseen_renewals.perl | 12 +++++++++ ...3_add_issuingrules_unseen_renewals_allowed.perl | 9 +++++++ .../bug_24083_update_auto_renewals_letter.perl | 29 ++++++++++++++++++++++ installer/data/mysql/kohastructure.sql | 3 +++ installer/data/mysql/sysprefs.sql | 1 + .../en/modules/admin/preferences/circulation.pref | 6 +++++ 7 files changed, 66 insertions(+) create mode 100644 installer/data/mysql/atomicupdate/bug_24083_UnseenRenewals_syspref.perl create mode 100644 installer/data/mysql/atomicupdate/bug_24083_add_issues_unseen_renewals.perl create mode 100644 installer/data/mysql/atomicupdate/bug_24083_add_issuingrules_unseen_renewals_allowed.perl create mode 100644 installer/data/mysql/atomicupdate/bug_24083_update_auto_renewals_letter.perl diff --git a/installer/data/mysql/atomicupdate/bug_24083_UnseenRenewals_syspref.perl b/installer/data/mysql/atomicupdate/bug_24083_UnseenRenewals_syspref.perl new file mode 100644 index 0000000000..afa0fcba25 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_24083_UnseenRenewals_syspref.perl @@ -0,0 +1,6 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + $dbh->do( q| INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES ('UnseenRenewals', '0', 'If enabled, a renewal can be recorded as "unseen" by the library and count against the borrowers unseen renewals limit', '', 'YesNo'); | ); + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 24083 - Add UnseenRenewals syspref)\n"; +} diff --git a/installer/data/mysql/atomicupdate/bug_24083_add_issues_unseen_renewals.perl b/installer/data/mysql/atomicupdate/bug_24083_add_issues_unseen_renewals.perl new file mode 100644 index 0000000000..adee26005a --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_24083_add_issues_unseen_renewals.perl @@ -0,0 +1,12 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + if( !column_exists( 'issues', 'unseen_renewals' ) ) { + $dbh->do( q| ALTER TABLE issues ADD unseen_renewals TINYINT(4) DEFAULT 0 NOT NULL AFTER renewals | ); + } + if( !column_exists( 'old_issues', 'unseen_renewals' ) ) { + $dbh->do( q| ALTER TABLE old_issues ADD unseen_renewals TINYINT(4) DEFAULT 0 NOT NULL AFTER renewals | ); + } + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 24083 - Add issues.unseen_renewals & old_issues.unseen_renewals)\n"; +} diff --git a/installer/data/mysql/atomicupdate/bug_24083_add_issuingrules_unseen_renewals_allowed.perl b/installer/data/mysql/atomicupdate/bug_24083_add_issuingrules_unseen_renewals_allowed.perl new file mode 100644 index 0000000000..2706d08675 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_24083_add_issuingrules_unseen_renewals_allowed.perl @@ -0,0 +1,9 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + if( !column_exists( 'issuingrules', 'unseen_renewals_allowed' ) ) { + $dbh->do( q| ALTER TABLE issuingrules ADD unseen_renewals_allowed SMALLINT(6) DEFAULT NULL AFTER renewalsallowed | ); + } + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 24083 - Add issuingrules.unseen_renewals_allowed)\n"; +} diff --git a/installer/data/mysql/atomicupdate/bug_24083_update_auto_renewals_letter.perl b/installer/data/mysql/atomicupdate/bug_24083_update_auto_renewals_letter.perl new file mode 100644 index 0000000000..f928c1cce3 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_24083_update_auto_renewals_letter.perl @@ -0,0 +1,29 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + my ($text) = $dbh->selectrow_array('SELECT content FROM letter WHERE module = "circulation" AND code = "AUTO_RENEWALS" AND content NOT LIKE "%too_unseen%"'); + + if ($text) { + my $find = qr/^\[\% (IF|ELSIF) checkout.auto_renew_error == 'too_many' \%\]$/; + my @lines_in = split /^/, $text; + my @lines_out = (); + foreach my $line(@lines_in) { + if ($line =~ $find) { + if ($1) { + my $newline_test = $1 eq 'IF' ? 'IF' : 'ELSIF'; + $line =~ s/\bIF\b/ELSIF/; + push @lines_out, "[% $newline_test checkout.auto_renew_error == 'too_unseen' %]\n"; + push @lines_out, "You have reach the maximum of consecutive renewals without visiting the library.\n"; + } + } + push @lines_out, $line; + } + if (scalar @lines_out > 0) { + my $joined = join "", @lines_out; + $dbh->do(q{UPDATE letter SET content = ? WHERE module = "circulation" AND code = "AUTO_RENEWALS"}, undef, ($joined)); + } + } + + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 24083 - Add issues.unseen_renewals & old_issues.unseen_renewals)\n"; +} diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 67495ab962..0b00511ab2 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -824,6 +824,7 @@ CREATE TABLE `issuingrules` ( -- circulation and fine rules `hardduedate` date default NULL, -- hard due date `hardduedatecompare` tinyint NOT NULL default "0", -- type of hard due date (1 = after, 0 = on, -1 = before) `renewalsallowed` smallint(6) NOT NULL default "0", -- how many renewals are allowed + `unseen_renewals_allowed` smallint(6) default NULL, -- how many consecutive renewals are allowed without seeing the item in the library `renewalperiod` int(4) default NULL, -- renewal period in the unit set in issuingrules.lengthunit `norenewalbefore` int(4) default NULL, -- no renewal allowed until X days or hours before due date. `auto_renew` BOOLEAN default FALSE, -- automatic renewal @@ -1668,6 +1669,7 @@ CREATE TABLE `issues` ( -- information related to check outs or issues `returndate` datetime default NULL, -- date the item was returned, will be NULL until moved to old_issues `lastreneweddate` datetime default NULL, -- date the item was last renewed `renewals` tinyint(4) NOT NULL default 0, -- lists the number of times the item was renewed + `unseen_renewals` tinyint(4) NOT NULL default 0, -- lists the number of consecutive times the item was renewed without being seen `auto_renew` BOOLEAN default FALSE, -- automatic renewal `auto_renew_error` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL, -- automatic renewal error `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this record was last touched @@ -1700,6 +1702,7 @@ CREATE TABLE `old_issues` ( -- lists items that were checked out and have been r `returndate` datetime default NULL, -- date the item was returned `lastreneweddate` datetime default NULL, -- date the item was last renewed `renewals` tinyint(4) NOT NULL default 0, -- lists the number of times the item was renewed + `unseen_renewals` tinyint(4) NOT NULL default 0, -- lists the number of consecutive times the item was renewed without being seen `auto_renew` BOOLEAN default FALSE, -- automatic renewal `auto_renew_error` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL, -- automatic renewal error `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this record was last touched diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 9fc3d5821e..bcb811b4df 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -642,6 +642,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('UNIMARCField100Language','fre',NULL,'UNIMARC field 100 default language','short'), ('UpdateItemWhenLostFromHoldList','',NULL,'This is a list of values to update an item when it is marked as lost from the holds to pull screen','Free'), ('UniqueItemFields','barcode','','Pipe-separated list of fields that should be unique (used in acquisition module for item creation). Fields must be valid SQL column names of items table','Free'), +('UnseenRenewals','0','','Allow renewals to be recorded as "unseen" by the library, and count against the borrowers unseen renewals limit','YesNo'), ('UnsubscribeReflectionDelay','',NULL,'Delay for locking unsubscribers', 'Integer'), ('UpdateItemLocationOnCheckin', '', 'NULL', 'This is a list of value pairs.\n Examples:\n\nPROC: FIC - causes an item in the Processing Center location to be updated into the Fiction location on check in.\nFIC: GEN - causes an item in the Fiction location to be updated into the General stacks location on check in.\n_BLANK_:FIC - causes an item that has no location to be updated into the Fiction location on check in.\nFIC: _BLANK_ - causes an item in location FIC to be updated to a blank location on check in.\n_ALL_:FIC - causes all items to be updated into the Fiction location on check in.\nPROC: _PERM_ - causes an item that is in the Processing Center to be updated to it''s permanent location.\n\nGeneral rule: if the location value on the left matches the item''s current location, it will be updated to match the location value on the right.\nNote: PROC and CART are special values, for these locations only can location and permanent_location differ, in all other cases an update will affect both. Items in the CART location will be returned to their permanent location on checkout.\n\nThe special term _BLANK_ may be used on either side of a value pair to update or remove the location from items with no location assigned.\nThe special term _ALL_ is used on the left side of the colon (:) to affect all items.\nThe special term _PERM_ is used on the right side of the colon (:) to return items to their permanent location.', 'Free'), ('UpdateNotForLoanStatusOnCheckin', '', 'NULL', 'This is a list of value pairs. When an item is checked in, if the not for loan value on the left matches the items not for loan value it will be updated to the right-hand value. E.g. ''-1: 0'' will cause an item that was set to ''Ordered'' to now be available for loan. Each pair of values should be on a separate line.', 'Free'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index e949eac982..4652402e74 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -307,6 +307,12 @@ Circulation: no: "Don't send" - a renewal notice according to patron checkout alert preferences. - + - pref: UnseenRenewals + choices: + yes: Allow + no: "Don't allow" + - renewals to be recorded as "unseen" by the library, and count against the borrowers unseen renewals limit + - - Prevent patrons from making holds on the OPAC if they owe more than - pref: maxoutstanding class: currency -- 2.11.0