aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Open311
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/Open311')
-rw-r--r--perllib/Open311/Endpoint.pm4
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm32
-rw-r--r--perllib/Open311/GetUpdates.pm9
-rw-r--r--perllib/Open311/PopulateServiceList.pm16
4 files changed, 35 insertions, 26 deletions
diff --git a/perllib/Open311/Endpoint.pm b/perllib/Open311/Endpoint.pm
index 7916d090f..425a708ef 100644
--- a/perllib/Open311/Endpoint.pm
+++ b/perllib/Open311/Endpoint.pm
@@ -8,7 +8,7 @@ Open311::Endpoint - a generic Open311 endpoint implementation
use Web::Simple;
-use JSON;
+use JSON::MaybeXS;
use XML::Simple;
use Open311::Endpoint::Result;
@@ -387,7 +387,7 @@ sub GET_Service_Definition {
key => $key,
name => $name,
}
- } $attribute->values_kv
+ } sort { $a->[0] cmp $b->[0] } $attribute->values_kv
]) : (),
map { $_ => $attribute->$_ }
qw/ code datatype datatype_description description /,
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index 1e5f4dc6b..11bc1e64f 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -1,15 +1,17 @@
package Open311::GetServiceRequestUpdates;
-use Moose;
+use Moo;
use Open311;
-use FixMyStreet::App;
+use FixMyStreet::DB;
+use FixMyStreet::App::Model::PhotoSet;
use DateTime::Format::W3CDTF;
has system_user => ( is => 'rw' );
-has start_date => ( is => 'ro', default => undef );
-has end_date => ( is => 'ro', default => undef );
+has start_date => ( is => 'ro', default => sub { undef } );
+has end_date => ( is => 'ro', default => sub { undef } );
has suppress_alerts => ( is => 'rw', default => 0 );
has verbose => ( is => 'ro', default => 0 );
+has schema => ( is =>'ro', lazy => 1, default => sub { FixMyStreet::DB->connect } );
Readonly::Scalar my $AREA_ID_BROMLEY => 2482;
Readonly::Scalar my $AREA_ID_OXFORDSHIRE => 2237;
@@ -17,7 +19,7 @@ Readonly::Scalar my $AREA_ID_OXFORDSHIRE => 2237;
sub fetch {
my $self = shift;
- my $bodies = FixMyStreet::App->model('DB::Body')->search(
+ my $bodies = $self->schema->resultset('Body')->search(
{
send_method => 'Open311',
send_comments => 1,
@@ -91,7 +93,7 @@ sub update_comments {
my $criteria = {
external_id => $request_id,
};
- $problem = FixMyStreet::App->model('DB::Problem')->to_body($body)->search( $criteria );
+ $problem = $self->schema->resultset('Problem')->to_body($body)->search( $criteria );
if (my $p = $problem->first) {
my $c = $p->comments->search( { external_id => $request->{update_id} } );
@@ -99,7 +101,7 @@ sub update_comments {
if ( !$c->first ) {
my $comment_time = DateTime::Format::W3CDTF->parse_datetime( $request->{updated_datetime} );
- my $comment = FixMyStreet::App->model('DB::Comment')->new(
+ my $comment = $self->schema->resultset('Comment')->new(
{
problem => $p,
user => $self->system_user,
@@ -115,6 +117,18 @@ 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 ],
+ });
+ $comment->photo($photoset->data);
+ }
+ }
+
# 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.
@@ -137,7 +151,7 @@ sub update_comments {
$comment->insert();
if ( $self->suppress_alerts ) {
- my @alerts = FixMyStreet::App->model('DB::Alert')->search( {
+ my @alerts = $self->schema->resultset('Alert')->search( {
alert_type => 'new_updates',
parameter => $p->id,
confirmed => 1,
@@ -145,7 +159,7 @@ sub update_comments {
} );
for my $alert (@alerts) {
- my $alerts_sent = FixMyStreet::App->model('DB::AlertSent')->find_or_create( {
+ my $alerts_sent = $self->schema->resultset('AlertSent')->find_or_create( {
alert_id => $alert->id,
parameter => $comment->id,
} );
diff --git a/perllib/Open311/GetUpdates.pm b/perllib/Open311/GetUpdates.pm
index bc55086f0..901e78809 100644
--- a/perllib/Open311/GetUpdates.pm
+++ b/perllib/Open311/GetUpdates.pm
@@ -1,8 +1,8 @@
package Open311::GetUpdates;
-use Moose;
+use Moo;
use Open311;
-use FixMyStreet::App;
+use FixMyStreet::Cobrand;
has body_list => ( is => 'ro' );
has system_user => ( is => 'ro' );
@@ -17,7 +17,7 @@ sub get_updates {
api_key => $body->api_key
);
- my $reports = FixMyStreet::App->model('DB::Problem')->to_body($body)->search(
+ my $reports = $body->result_source->schema->resultset('Problem')->to_body($body)->search(
{
state => { 'IN', [qw/confirmed fixed/] },
-and => [
@@ -62,8 +62,7 @@ sub update_reports {
my $request_id = $request->{service_request_id};
- my $problem =
- FixMyStreet::App->model('DB::Problem')
+ my $problem = $body->result_source->schema->resultset('Problem')
->search( { external_id => $request_id, } );
if (my $p = $problem->first) {
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index 5f45382e2..15a827217 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -1,21 +1,17 @@
package Open311::PopulateServiceList;
-use Moose;
-use LWP::Simple;
-use XML::Simple;
-use FixMyStreet::App;
+use Moo;
use Open311;
has bodies => ( is => 'ro' );
has found_contacts => ( is => 'rw', default => sub { [] } );
has verbose => ( is => 'ro', default => 0 );
+has schema => ( is => 'ro', lazy => 1, default => sub { FixMyStreet::DB->connect } );
has _current_body => ( is => 'rw' );
has _current_open311 => ( is => 'rw' );
has _current_service => ( is => 'rw' );
-my $bodies = FixMyStreet::App->model('DB::Body');
-
sub process_bodies {
my $self = shift;
@@ -43,7 +39,7 @@ sub process_body {
unless ( $list && $list->{service} ) {
if ($self->verbose >= 1) {
my $id = $self->_current_body->id;
- my $mapit_url = mySociety::Config::get('MAPIT_URL');
+ my $mapit_url = FixMyStreet->config('MAPIT_URL');
my $areas = join( ",", keys %{$self->_current_body->areas} );
warn "Body $id for areas $areas - $mapit_url/areas/$areas.html - did not return a service list\n";
warn $open311->error;
@@ -93,7 +89,7 @@ sub process_service {
$self->_current_service->{service_name};
print $self->_current_service->{service_code} . ': ' . $category . "\n" if $self->verbose >= 2;
- my $contacts = FixMyStreet::App->model( 'DB::Contact')->search(
+ my $contacts = $self->schema->resultset('Contact')->search(
{
body_id => $self->_current_body->id,
-OR => [
@@ -173,7 +169,7 @@ sub _create_contact {
my $contact;
eval {
- $contact = FixMyStreet::App->model( 'DB::Contact')->create(
+ $contact = $self->schema->resultset('Contact')->create(
{
email => $self->_current_service->{service_code},
body_id => $self->_current_body->id,
@@ -287,7 +283,7 @@ sub _normalize_service_name {
sub _delete_contacts_not_in_service_list {
my $self = shift;
- my $found_contacts = FixMyStreet::App->model( 'DB::Contact')->search(
+ my $found_contacts = $self->schema->resultset('Contact')->search(
{
email => { -not_in => $self->found_contacts },
body_id => $self->_current_body->id,