aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2017-06-14 13:59:43 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2017-06-20 15:02:12 +0100
commit3b72526db1cdb4695f61a188261351ddd2aea395 (patch)
tree6817af03285d6695e11e59dd90cad5dfeb39a599 /bin
parente57cbf483790bedfef6496be3c7ffa42882c3ffc (diff)
Run each test file in a transaction.
This means that the tests can be run in parallel.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/update-all-reports74
1 files changed, 2 insertions, 72 deletions
diff --git a/bin/update-all-reports b/bin/update-all-reports
index 6691ff4f0..4545cf1a8 100755
--- a/bin/update-all-reports
+++ b/bin/update-all-reports
@@ -8,7 +8,6 @@
use strict;
use warnings;
-require 5.8.0;
BEGIN {
use File::Basename qw(dirname);
@@ -17,75 +16,6 @@ BEGIN {
require "$d/../setenv.pl";
}
-use FixMyStreet;
-use FixMyStreet::DB;
-
-use File::Path ();
-use File::Slurp;
-use JSON::MaybeXS;
-use List::MoreUtils qw(zip);
-
-my $fourweeks = 4*7*24*60*60;
-
-# Age problems from when they're confirmed, except on Zurich
-# where they appear as soon as they're created.
-my $age_column = 'confirmed';
-if ( FixMyStreet->config('BASE_URL') =~ /zurich|zueri/ ) {
- $age_column = 'created';
-}
-
-my $problems = FixMyStreet::DB->resultset('Problem')->search(
- {
- state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
- },
- {
- columns => [
- 'id', 'bodies_str', 'state', 'areas', 'cobrand',
- { duration => { extract => "epoch from current_timestamp-lastupdate" } },
- { age => { extract => "epoch from current_timestamp-$age_column" } },
- ]
- }
-);
-$problems = $problems->cursor; # Raw DB cursor for speed
-
-my ( %fixed, %open );
-my @cols = ( 'id', 'bodies_str', 'state', 'areas', 'cobrand', 'duration', 'age' );
-while ( my @problem = $problems->next ) {
- my %problem = zip @cols, @problem;
- my @bodies;
- my $cobrand = $problem{cobrand};
-
- if ( !$problem{bodies_str} ) {
- # Problem was not sent to any bodies, add to all areas
- @bodies = grep { $_ } split( /,/, $problem{areas} );
- $problem{bodies} = 0;
- } else {
- # Add to bodies it was sent to
- @bodies = split( /,/, $problem{bodies_str} );
- $problem{bodies} = scalar @bodies;
- }
- foreach my $body ( @bodies ) {
- my $duration_str = ( $problem{duration} > 2 * $fourweeks ) ? 'old' : 'new';
- my $type = ( $problem{duration} > 2 * $fourweeks )
- ? 'unknown'
- : ($problem{age} > $fourweeks ? 'older' : 'new');
- if (FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}} || FixMyStreet::DB::Result::Problem->closed_states()->{$problem{state}}) {
- # Fixed problems are either old or new
- $fixed{$body}{$duration_str}++;
- $fixed{$cobrand}{$body}{$duration_str}++;
- } else {
- # Open problems are either unknown, older, or new
- $open{$body}{$type}++;
- $open{$cobrand}{$body}{$type}++;
- }
- }
-}
-
-my $body = encode_json( {
- fixed => \%fixed,
- open => \%open,
-} );
-
-File::Path::mkpath( FixMyStreet->path_to( '../data/' )->stringify );
-File::Slurp::write_file( FixMyStreet->path_to( '../data/all-reports.json' )->stringify, \$body );
+use FixMyStreet::Script::UpdateAllReports;
+FixMyStreet::Script::UpdateAllReports::generate();