diff options
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Comment.pm | 20 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Script/Questionnaires.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Script/Reports.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 2 | ||||
-rw-r--r-- | perllib/Open311.pm | 2 | ||||
-rwxr-xr-x | perllib/Open311/PostServiceRequestUpdates.pm | 3 | ||||
-rw-r--r-- | t/app/controller/admin.t | 2 |
8 files changed, 27 insertions, 8 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index b4e42b456..d27c5ea8c 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -115,6 +115,26 @@ my $stz = sub { around created => $stz; around confirmed => $stz; +=head2 get_cobrand_logged + +Get a cobrand object for the cobrand the update was made on. + +e.g. if an update was logged at www.fixmystreet.com, this will be a +FixMyStreet::Cobrand::FixMyStreet object. + +=cut + +has get_cobrand_logged => ( + is => 'ro', + lazy => 1, + default => sub { + my $self = shift; + my $cobrand_class = FixMyStreet::Cobrand->get_class_for_moniker( $self->cobrand ); + return $cobrand_class->new; + }, +); + + # You can replace this text with custom code or comments, and it will be preserved on regeneration sub check_for_errors { diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 76a6f72fb..113de6c35 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -780,7 +780,7 @@ sub duration_string { sub local_coords { my $self = shift; - my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($self->cobrand)->new; + my $cobrand = $self->get_cobrand_logged; if ($cobrand->moniker eq 'zurich') { my ($x, $y) = Geo::Coordinates::CH1903Plus::from_latlon($self->latitude, $self->longitude); return ( int($x+0.5), int($y+0.5) ); diff --git a/perllib/FixMyStreet/Script/Questionnaires.pm b/perllib/FixMyStreet/Script/Questionnaires.pm index d89f1bcf8..bcdaa06d6 100644 --- a/perllib/FixMyStreet/Script/Questionnaires.pm +++ b/perllib/FixMyStreet/Script/Questionnaires.pm @@ -43,7 +43,7 @@ sub send_questionnaires_period { while (my $row = $unsent->next) { - my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($row->cobrand)->new(); + my $cobrand = $row->get_cobrand_logged; $cobrand->set_lang_and_domain($row->lang, 1); FixMyStreet::Map::set_map_class($cobrand->map_type); diff --git a/perllib/FixMyStreet/Script/Reports.pm b/perllib/FixMyStreet/Script/Reports.pm index 87f9fd124..dd8f4e370 100644 --- a/perllib/FixMyStreet/Script/Reports.pm +++ b/perllib/FixMyStreet/Script/Reports.pm @@ -44,7 +44,7 @@ sub send(;$) { debug_print("starting to loop through unsent problem reports...") if $debug_mode; while (my $row = $unsent->next) { - my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($row->cobrand)->new(); + my $cobrand = $row->get_cobrand_logged; FixMyStreet::DB->schema->cobrand($cobrand); if ($debug_mode) { diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index 4307694a1..1b484aefe 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -71,7 +71,7 @@ sub send { } my ($verbose, $nomail) = CronFns::options(); - my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($row->cobrand)->new(); + my $cobrand = $row->get_cobrand_logged; $cobrand = $cobrand->call_hook(get_body_handler_for_problem => $row) || $cobrand; my $params = { diff --git a/perllib/Open311.pm b/perllib/Open311.pm index 6c6ec59cc..56fe567c5 100644 --- a/perllib/Open311.pm +++ b/perllib/Open311.pm @@ -397,7 +397,7 @@ sub _populate_service_request_update_params { } if ( $comment->photo ) { - my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($comment->cobrand)->new(); + my $cobrand = $comment->get_cobrand_logged; my $email_base_url = $cobrand->base_url($comment->cobrand_data); my $url = $email_base_url . $comment->photos->[0]->{url_full}; $params->{media_url} = $url; diff --git a/perllib/Open311/PostServiceRequestUpdates.pm b/perllib/Open311/PostServiceRequestUpdates.pm index c2b8c2494..dccd26184 100755 --- a/perllib/Open311/PostServiceRequestUpdates.pm +++ b/perllib/Open311/PostServiceRequestUpdates.pm @@ -99,8 +99,7 @@ sub process_body { ); while ( my $comment = $comments->next ) { - my $cobrand = $body->get_cobrand_handler || - FixMyStreet::Cobrand->get_class_for_moniker($comment->cobrand)->new(); + my $cobrand = $body->get_cobrand_handler || $comment->get_cobrand_logged; # Some cobrands (e.g. Buckinghamshire) don't want to receive updates # from anyone except the original problem reporter. diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index b69a711c8..a0a93d996 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -129,7 +129,7 @@ subtest 'check summary counts' => sub { subtest "Check admin_base_url" => sub { my $rs = FixMyStreet::App->model('DB::Problem'); - my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($report->cobrand)->new(); + my $cobrand = $report->get_cobrand_logged; is ($report->admin_url($cobrand), (sprintf 'http://www.example.org/admin/report_edit/%d', $report_id), |