From 61e79643ac0d48a06c4751650228c639e358f093 Mon Sep 17 00:00:00 2001 From: Nik Gupta Date: Wed, 29 Jan 2025 15:01:50 +0000 Subject: [PATCH] Only update 'lastupdate' when the update is new. https://github.com/mysociety/societyworks/issues/4748 --- perllib/Open311/UpdatesBase.pm | 4 +++- t/cobrand/brent.t | 2 ++ t/cobrand/bromley_waste.t | 2 ++ t/cobrand/sutton.t | 4 +++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/perllib/Open311/UpdatesBase.pm b/perllib/Open311/UpdatesBase.pm index 2eb7d82a0f6..90071f8707a 100644 --- a/perllib/Open311/UpdatesBase.pm +++ b/perllib/Open311/UpdatesBase.pm @@ -281,7 +281,9 @@ sub _process_update { # insertion. We also then need a clone, otherwise the setting of lastupdate # will *also* reshift comment->created's time zone to TIME_ZONE. my $created = $comment->created->set_time_zone(FixMyStreet->local_time_zone); - $p->lastupdate($created->clone); + if ($created > $p->lastupdate) { + $p->lastupdate($created->clone); + } return $comment unless $self->commit; diff --git a/t/cobrand/brent.t b/t/cobrand/brent.t index 920cd8fe2da..cc008de90e3 100644 --- a/t/cobrand/brent.t +++ b/t/cobrand/brent.t @@ -762,6 +762,8 @@ subtest 'push updating of reports' => sub { ($report, $report2) = $mech->create_problems_for_body(2, $brent->id, 'Graffiti', { category => 'Graffiti', }); + # Set last update to before the time of the first update we've mocked. + $report->update({ lastupdate => DateTime->new(year => 2020, month => 06, day => 23, hour => 15) }); my $report_id = $report->id; my $cobrand = FixMyStreet::Cobrand::Brent->new; diff --git a/t/cobrand/bromley_waste.t b/t/cobrand/bromley_waste.t index 582a568c0be..345ac66a038 100644 --- a/t/cobrand/bromley_waste.t +++ b/t/cobrand/bromley_waste.t @@ -582,6 +582,8 @@ subtest 'updating of waste reports' => sub { }); $reports[1]->update({ external_id => 'something-else' }); # To test loop $report = $reports[0]; + # Set last update to before the time of the first update we've mocked. + $report->update({ lastupdate => DateTime->new(year => 2020, month => 06, day => 23, hour => 15) }); my $cobrand = FixMyStreet::Cobrand::Bromley->new; $report->update({ external_id => 'waste-15001-' }); diff --git a/t/cobrand/sutton.t b/t/cobrand/sutton.t index 1b2e9876229..3ad436a1aea 100644 --- a/t/cobrand/sutton.t +++ b/t/cobrand/sutton.t @@ -16,6 +16,7 @@ FixMyStreet::App->log->disable('info'); END { FixMyStreet::App->log->enable('info'); } # Create test data +my $date = DateTime->now->subtract(days => 1)->strftime('%Y-%m-%dT%H:%M:%SZ'); my $user = $mech->create_user_ok( 'sutton@example.com', name => 'Sutton Council' ); my $normal_user = $mech->create_user_ok( 'user@example.com', name => 'Norma Normal' ); my $body = $mech->create_body_ok( 2498, 'Sutton Council', { @@ -167,7 +168,6 @@ sub new { my $c = shift; bless { @_ }, $c; } package main; subtest 'updating of waste reports' => sub { - my $date = DateTime->now->subtract(days => 1)->strftime('%Y-%m-%dT%H:%M:%SZ'); my $integ = Test::MockModule->new('SOAP::Lite'); $integ->mock(call => sub { my ($cls, @args) = @_; @@ -216,6 +216,8 @@ subtest 'updating of waste reports' => sub { }); $reports[1]->update({ external_id => 'something-else' }); # To test loop $report = $reports[0]; + # Set last update to before the time of the first update we've mocked. + $report->update({ lastupdate => $date }); FixMyStreet::override_config { ALLOWED_COBRANDS => 'sutton',