diff options
author | Matthew Somerville <matthew@mysociety.org> | 2016-01-29 15:12:29 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2016-01-29 15:12:29 +0000 |
commit | 68dda6c87e0ea01e9934b18f1061c0066f352e9e (patch) | |
tree | 2de1c83495b7e905beb75d225a8d4044c0a718e2 /perllib | |
parent | 32cc764609a304fb09718e91ca836c8788db1f51 (diff) | |
parent | b4e69645bd2ff24fb603bf7461e2c80b316eaeaa (diff) |
Merge branch '1315-open311-update-media_url'
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/Open311/GetServiceRequestUpdates.pm | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm index 6d846de42..4b6d56146 100644 --- a/perllib/Open311/GetServiceRequestUpdates.pm +++ b/perllib/Open311/GetServiceRequestUpdates.pm @@ -3,6 +3,7 @@ package Open311::GetServiceRequestUpdates; use Moo; use Open311; use FixMyStreet::DB; +use FixMyStreet::App::Model::PhotoSet; use DateTime::Format::W3CDTF; has system_user => ( is => 'rw' ); @@ -116,6 +117,19 @@ sub update_comments { } ); + # ref test as XML::Simple will have returned an empty hashref for empty element + if ($request->{media_url} && !ref $request->{media_url}) { + my $ua = LWP::UserAgent->new; + my $res = $ua->get($request->{media_url}); + if ( $res->is_success && $res->content_type eq 'image/jpeg' ) { + my $photoset = FixMyStreet::App::Model::PhotoSet->new({ + data_items => [ $res->decoded_content ], + }); + my $data = $photoset->get_raw_image_data(0); + $comment->photo($data->[0]); + } + } + # if the comment is older than the last update # do not change the status of the problem as it's # tricky to determine the right thing to do. |