]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 227155 - make sure running collectstats.pl twice in a day, or migrating data...
authorgerv%gerv.net <>
Thu, 22 Jan 2004 16:10:53 +0000 (16:10 +0000)
committergerv%gerv.net <>
Thu, 22 Jan 2004 16:10:53 +0000 (16:10 +0000)
checksetup.pl
collectstats.pl

index 1d62408675d53b0c8277386b3c495c26bc97646b..255fc56e027cc1d95fb8dceef32fb3cd691037f9 100755 (executable)
@@ -3707,6 +3707,9 @@ if (!$series_exists) {
                                      "(series_id, date, value) " . 
                                      "VALUES (?, ?, ?)");
     
+    my $deletesth = $dbh->prepare("DELETE FROM series_data 
+                                   WHERE series_id = ? AND date = ?");
+                                     
     # Fields in the data file (matches the current collectstats.pl)
     my @statuses = 
                 qw(NEW ASSIGNED REOPENED UNCONFIRMED RESOLVED VERIFIED CLOSED);
@@ -3786,6 +3789,11 @@ if (!$series_exists) {
             # Insert values into series_data: series_id, date, value
             my %fielddata = %{$data{$field}};
             foreach my $date (keys %fielddata) {
+                # We need to delete in case the text file had duplicate entries
+                # in it.
+                $deletesth->execute($seriesids{$field},
+                                    $dbh->quote($date));
+                         
                 # We prepared this above
                 $seriesdatasth->execute($seriesids{$field},
                                         $dbh->quote($date), 
index 002d5fba20f95355c3fcf0a571dc9d84cbd20789..bc7b24884d8ff39cbb6610637a361887657718de 100755 (executable)
@@ -453,6 +453,12 @@ sub CollectSeriesData {
                             "(series_id, date, value) " .
                             "VALUES (?, " . $dbh->quote($today) . ", ?)");
 
+    # We delete from the table beforehand, to avoid SQL errors if people run
+    # collectstats.pl twice on the same day.
+    my $deletesth = $dbh->prepare("DELETE FROM series_data 
+                                   WHERE series_id = ? AND date = " .
+                                   $dbh->quote($today));
+                                     
     foreach my $series_id (keys %$serieses) {
         # We set up the user for Search.pm's permission checking - each series
         # runs with the permissions of its creator.
@@ -470,6 +476,7 @@ sub CollectSeriesData {
         
         my $count = scalar(@$data) || 0;
 
+        $deletesth->execute($series_id);
         $sth->execute($series_id, $count);
     }
 }