aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Open311
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2012-10-04 13:43:49 +0100
committerStruan Donald <struan@exo.org.uk>2012-10-04 13:43:49 +0100
commit42e455a374b629185036cc2227e8273547d324f1 (patch)
tree703b3de7d4a520161f734a35684abec9a4bbf7be /perllib/Open311
parentf716ba282936ad04c46322c273b123af5e957d38 (diff)
simplfy state change code and also correct bugs
Diffstat (limited to 'perllib/Open311')
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm44
1 files changed, 27 insertions, 17 deletions
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index c9bb7a91b..c0b9dcac0 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -96,23 +96,16 @@ sub update_comments {
# do not change the status of the problem as it's
# tricky to determine the right thing to do.
if ( $comment->created_local > $p->lastupdate_local ) {
- my $incoming_status = lc( $request->{status} );
- my $internal_status = $incoming_status;
- $internal_status =~ s/_/ /g;
-
- $internal_status = 'not responsible' if $internal_status eq 'not councils responsibility';
- if ( $p->is_open and ( $incoming_status eq 'closed' or $incoming_status eq 'fixed' ) ) {
- $p->state( 'fixed - council' );
- $comment->problem_state( 'fixed - council' );
- } elsif ( ( $p->is_closed || $p->is_fixed ) and (
- $incoming_status eq 'open' or FixMyStreet::DB::Result::Problem->open_states()->{ $internal_status }
- ) ) {
- $p->state( 'confirmed' );
- $comment->problem_state( 'confirmed' );
- } else {
- if ( FixMyStreet::DB::Result::Problem->council_states()->{ $internal_status } ) {
- $p->state( $internal_status );
- $comment->problem_state( $internal_status );
+ my $state = $self->map_state( $request->{status} );
+
+ # do not change a fixed problem to a closed one
+ if ( $p->is_fixed && FixMyStreet::DB::Result::Problem->open_states()->{$state} ) {
+ $p->state($state);
+ $comment->problem_state($state);
+ } elsif ( ( $p->is_open || $p->is_closed ) && $p->state ne $state ) {
+ if ( FixMyStreet::DB::Result::Problem->council_states() ->{$state} ) {
+ $p->state($state);
+ $comment->problem_state($state);
}
}
}
@@ -141,4 +134,21 @@ sub update_comments {
return 1;
}
+sub map_state {
+ my $self = shift;
+ my $incoming_state = shift;
+
+ $incoming_state = lc($incoming_state);
+ $incoming_state =~ s/_/ /g;
+
+ my %state_map = (
+ fixed => 'fixed - council',
+ 'not councils responsibility' => 'not responsible',
+ open => 'confirmed',
+ closed => 'fixed - council'
+ );
+
+ return $state_map{$incoming_state} || $incoming_state;
+}
+
1;