]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1505050 - make the request nagging script more robust
authorDylan William Hardison <dylan@hardison.net>
Wed, 14 Nov 2018 20:23:27 +0000 (15:23 -0500)
committerGitHub <noreply@github.com>
Wed, 14 Nov 2018 20:23:27 +0000 (15:23 -0500)
1. The nags script switches to the shadow database, but $dbh is defined
   before that happens and is thus the primary database. This is easily fixed by
   using Bugzilla->dbh
2. Since we have DBIx::Connector, we can run the sql in fixup mode, so that if
   it gets disconnected, it will retry the code. This is perfectly safe for the
   the two big sql queries.

extensions/RequestNagger/bin/send-request-nags.pl

index 824c0dc516b9a012022f05720375cdadabb2ee74..93652f100c2335e68f804dc24fb0b8e4765e6b2c 100755 (executable)
@@ -43,12 +43,11 @@ if (my $filename = shift @ARGV) {
     exit;
 }
 
-my $dbh     = Bugzilla->dbh;
-my $db_date = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)');
+my $db_date = Bugzilla->dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)');
 my $date    = format_time($db_date, '%a, %d %b %Y %T %z', 'UTC');
 
 # delete expired defers
-$dbh->do("DELETE FROM nag_defer WHERE defer_until <= CURRENT_DATE()");
+Bugzilla->dbh->do("DELETE FROM nag_defer WHERE defer_until <= CURRENT_DATE()");
 Bugzilla->switch_to_shadow_db();
 
 # send nags to requestees
@@ -77,9 +76,10 @@ sub send_nags {
     # get requests
 
     foreach my $report (@{ $args{reports} }) {
-
-        # collate requests
-        my $rows = $dbh->selectall_arrayref($args{$report . '_sql'}, { Slice => {} });
+        my $rows;
+        Bugzilla->dbh->connector->run(fixup => sub {
+            $rows = $_->selectall_arrayref($args{$report . '_sql'}, { Slice => {} });
+        });
         foreach my $request (@$rows) {
             next unless _include_request($request, $report);