From ac54d831df9d865f600f20e42ef29a7a2833bd4c Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 12 Oct 2017 13:13:41 +0200 Subject: [PATCH] Bug 19452: [17.05.x] Remove the truncate option The truncate option is not really useful. Its result is probably not what most users of this script expect or need. It truncates both tables borrower_message_preferences and borrower_message_transport_preferences. This (unfortunately) includes deleting messaging preferences for patron categories. After that, adding preferences again will not add categories again, but only borrower preferences which are all disabled. Furthermore, we do not need to disable the foreign key check. Neither do we actually need to truncate, deleting records seems sufficient. Also deleting transport preferences is not needed, since it will be done by a cascade from messaging preferences. Note that the subsequent call of SetMessagingPreferencesFromDefaults will already delete the records. This makes it possible to remove the truncate option altogether. Test plan: [1] Select a patron category (say ST) and change days_in_advance to x. [2] Select a ST patron and set days_advance to y in his msg prefs. [3] Run borrowers-force-messaging-defaults.pl -doit [4] Verify that the patron has been reset to the default prefs (incl. value x in days_in_advance). [5] Verify that the patron category prefs are still intact. Signed-off-by: Marcel de Rooy Signed-off-by: Charles Farmer Signed-off-by: Nick Clemens Signed-off-by: Fridolin Somers --- .../borrowers-force-messaging-defaults | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/misc/maintenance/borrowers-force-messaging-defaults b/misc/maintenance/borrowers-force-messaging-defaults index b17137e03c..73aef14a8b 100755 --- a/misc/maintenance/borrowers-force-messaging-defaults +++ b/misc/maintenance/borrowers-force-messaging-defaults @@ -39,7 +39,7 @@ sub usage { sub force_borrower_messaging_defaults { - my ($doit, $truncate, $since) = @_; + my ($doit, $since) = @_; $since = '0000-00-00' if (!$since); print $since; @@ -47,13 +47,6 @@ sub force_borrower_messaging_defaults { my $dbh = C4::Context->dbh; $dbh->{AutoCommit} = 0; - if ( $doit && $truncate ) { - $dbh->do(q|SET FOREIGN_KEY_CHECKS = 0|); - $dbh->do(q|TRUNCATE borrower_message_transport_preferences|); - $dbh->do(q|TRUNCATE borrower_message_preferences|); - $dbh->do(q|SET FOREIGN_KEY_CHECKS = 1|); - } - my $sth = $dbh->prepare("SELECT borrowernumber, categorycode FROM borrowers WHERE dateenrolled >= ?"); $sth->execute($since); while ( my ($borrowernumber, $categorycode) = $sth->fetchrow ) { @@ -68,17 +61,16 @@ sub force_borrower_messaging_defaults { } -my ($doit, $truncate, $since, $help); +my ($doit, $since, $help); my $result = GetOptions( 'doit' => \$doit, - 'truncate' => \$truncate, 'since:s' => \$since, 'help|h' => \$help, ); usage() if $help; -force_borrower_messaging_defaults( $doit, $truncate, $since ); +force_borrower_messaging_defaults( $doit, $since ); =head1 NAME @@ -89,7 +81,6 @@ force-borrower-messaging-defaults force-borrower-messaging-defaults force-borrower-messaging-defaults --help force-borrower-messaging-defaults --doit - force-borrower-messaging-defaults --doit --truncate =head1 DESCRIPTION @@ -112,11 +103,6 @@ Prints this help Process actually the borrowers. -=item B<--truncate> - -Truncate all borrowers transport preferences before (re-)creating them. It -affects borrower_message_preferences table. - =back =cut -- 2.39.5