aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Open311
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/Open311')
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm13
-rw-r--r--perllib/Open311/GetUpdates.pm7
-rw-r--r--perllib/Open311/PopulateServiceList.pm12
3 files changed, 14 insertions, 18 deletions
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index 1e5f4dc6b..b7da43604 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -2,7 +2,7 @@ package Open311::GetServiceRequestUpdates;
use Moose;
use Open311;
-use FixMyStreet::App;
+use FixMyStreet::DB;
use DateTime::Format::W3CDTF;
has system_user => ( is => 'rw' );
@@ -10,6 +10,7 @@ has start_date => ( is => 'ro', default => undef );
has end_date => ( is => 'ro', default => 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 +18,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 +92,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 +100,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,
@@ -137,7 +138,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 +146,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..afbdd13b5 100644
--- a/perllib/Open311/GetUpdates.pm
+++ b/perllib/Open311/GetUpdates.pm
@@ -2,7 +2,7 @@ package Open311::GetUpdates;
use Moose;
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..fbb0ebc56 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 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;
@@ -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,