diff options
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 29 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Alert.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/AlertType.pm | 17 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Comment.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm | 7 |
6 files changed, 32 insertions, 33 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 0cab853de..e340acf1e 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -462,7 +462,7 @@ sub bodies($) { my $self = shift; return {} unless $self->bodies_str; my $bodies = $self->bodies_str_ids; - my @bodies = FixMyStreet::App->model('DB::Body')->search({ id => $bodies })->all; + my @bodies = $self->result_source->schema->resultset('Body')->search({ id => $bodies })->all; return { map { $_->id => $_ } @bodies }; } @@ -648,7 +648,7 @@ order of title. sub response_templates { my $problem = shift; - return FixMyStreet::App->model('DB::ResponseTemplate')->search( + return $problem->result_source->schema->resultset('ResponseTemplate')->search( { body_id => $problem->bodies_str_ids }, @@ -754,20 +754,17 @@ sub update_from_open311_service_request { $status_notes = $request->{status_notes}; } - my $update = FixMyStreet::App->model('DB::Comment')->new( - { - problem_id => $self->id, - state => 'confirmed', - created => $updated || \'current_timestamp', - confirmed => \'current_timestamp', - text => $status_notes, - mark_open => 0, - mark_fixed => 0, - user => $system_user, - anonymous => 0, - name => $body->name, - } - ); + my $update = $self->new_related(comments => { + state => 'confirmed', + created => $updated || \'current_timestamp', + confirmed => \'current_timestamp', + text => $status_notes, + mark_open => 0, + mark_fixed => 0, + user => $system_user, + anonymous => 0, + name => $body->name, + }); my $w3c = DateTime::Format::W3CDTF->new; my $req_time = $w3c->parse_datetime( $request->{updated_datetime} ); diff --git a/perllib/FixMyStreet/DB/ResultSet/Alert.pm b/perllib/FixMyStreet/DB/ResultSet/Alert.pm index bb1c61141..1866e9b06 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Alert.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Alert.pm @@ -8,7 +8,7 @@ sub timeline_created { my ( $rs, $restriction ) = @_; my $prefetch = - FixMyStreet::App->model('DB')->schema->storage->sql_maker->quote_char ? + $rs->result_source->storage->sql_maker->quote_char ? [ qw/alert_type user/ ] : [ qw/alert_type/ ]; diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm index 114f79c6e..d4cf9ba8b 100644 --- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm +++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm @@ -11,6 +11,7 @@ use mySociety::MaPit; use IO::String; use RABX; +use FixMyStreet::Cobrand; use FixMyStreet::Email; # Child must have confirmed, id, email, state(!) columns @@ -73,7 +74,7 @@ sub email_alerts ($) { # this is for the new_updates alerts next if $row->{non_public} and $row->{user_id} != $row->{alert_user_id}; - FixMyStreet::App->model('DB::AlertSent')->create( { + $schema->resultset('AlertSent')->create( { alert_id => $row->{alert_id}, parameter => $row->{item_id}, } ); @@ -97,11 +98,11 @@ sub email_alerts ($) { if ( $cobrand->moniker ne 'zurich' && $row->{alert_user_id} == $row->{user_id} ) { # This is an alert to the same user who made the report - make this a login link # Don't bother with Zurich which has no accounts - my $user = FixMyStreet::App->model('DB::User')->find( { + my $user = $schema->resultset('User')->find( { id => $row->{alert_user_id} } ); $data{alert_email} = $user->email; - my $token_obj = FixMyStreet::App->model('DB::Token')->create( { + my $token_obj = $schema->resultset('Token')->create( { scope => 'alert_to_reporter', data => { id => $row->{id}, @@ -156,7 +157,7 @@ sub email_alerts ($) { # Nearby done separately as the table contains the parameters my $template = $rs->find( { ref => 'local_problems' } )->template; - my $query = FixMyStreet::App->model('DB::Alert')->search( { + my $query = $schema->resultset('Alert')->search( { alert_type => 'local_problems', whendisabled => undef, confirmed => 1 @@ -198,7 +199,7 @@ sub email_alerts ($) { $q = dbh()->prepare($q); $q->execute($latitude, $longitude, $d, $alert->whensubscribed, $alert->id, $alert->user->email); while (my $row = $q->fetchrow_hashref) { - FixMyStreet::App->model('DB::AlertSent')->create( { + $schema->resultset('AlertSent')->create( { alert_id => $alert->id, parameter => $row->{id}, } ); @@ -222,18 +223,18 @@ sub _send_aggregated_alert_email(%) { $cobrand->set_lang_and_domain( $data{lang}, 1, FixMyStreet->path_to('locale')->stringify ); if (!$data{alert_email}) { - my $user = FixMyStreet::App->model('DB::User')->find( { + my $user = $data{schema}->resultset('User')->find( { id => $data{alert_user_id} } ); $data{alert_email} = $user->email; } my ($domain) = $data{alert_email} =~ m{ @ (.*) \z }x; - return if FixMyStreet::App->model('DB::Abuse')->search( { + return if $data{schema}->resultset('Abuse')->search( { email => [ $data{alert_email}, $domain ] } )->first; - my $token = FixMyStreet::App->model("DB::Token")->new_result( { + my $token = $data{schema}->resultset("Token")->new_result( { scope => 'alert', data => { id => $data{alert_id}, diff --git a/perllib/FixMyStreet/DB/ResultSet/Comment.pm b/perllib/FixMyStreet/DB/ResultSet/Comment.pm index 1b6afb819..3059baab1 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Comment.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Comment.pm @@ -14,7 +14,7 @@ sub timeline { my ( $rs, $body_restriction ) = @_; my $prefetch = - FixMyStreet::App->model('DB')->schema->storage->sql_maker->quote_char ? + $rs->result_source->storage->sql_maker->quote_char ? [ qw/user/ ] : []; diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 0c2811b7b..8e6cc7333 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -10,7 +10,7 @@ use Utils; use mySociety::Config; use mySociety::MaPit; -use FixMyStreet::App; +use FixMyStreet::Cobrand; use FixMyStreet::Email; use FixMyStreet::SendReport; @@ -174,7 +174,7 @@ sub timeline { my ( $rs ) = @_; my $prefetch = - FixMyStreet::App->model('DB')->schema->storage->sql_maker->quote_char ? + $rs->result_source->storage->sql_maker->quote_char ? [ qw/user/ ] : []; @@ -336,14 +336,14 @@ sub send_reports { $cobrand->process_additional_metadata_for_email($row, \%h); } - my $bodies = FixMyStreet::App->model("DB::Body")->search( + my $bodies = $rs->result_source->schema->resultset('Body')->search( { id => $row->bodies_str_ids }, { order_by => 'name' }, ); my $missing; if ($row->bodies_missing) { - my @missing = FixMyStreet::App->model("DB::Body")->search( + my @missing = $rs->result_source->schema->resultset("Body")->search( { id => [ split /,/, $row->bodies_missing ] }, { order_by => 'name' } )->get_column('name')->all; diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm index f9d32f2c1..aca330960 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm @@ -7,6 +7,7 @@ use Encode; use Utils; use FixMyStreet::Email; +use FixMyStreet::Cobrand; sub send_questionnaires { my ( $rs, $params ) = @_; @@ -40,7 +41,7 @@ sub send_questionnaires_period { ]; } - my $unsent = FixMyStreet::App->model('DB::Problem')->search( $q_params, { + my $unsent = $rs->result_source->schema->resultset('Problem')->search( $q_params, { order_by => { -desc => 'confirmed' } } ); @@ -70,7 +71,7 @@ sub send_questionnaires_period { my %h = map { $_ => $row->$_ } qw/name title detail category/; $h{created} = Utils::prettify_duration( time() - $row->confirmed->epoch, 'week' ); - my $questionnaire = FixMyStreet::App->model('DB::Questionnaire')->create( { + my $questionnaire = $rs->create( { problem_id => $row->id, whensent => \'current_timestamp', } ); @@ -80,7 +81,7 @@ sub send_questionnaires_period { $row->send_questionnaire( 0 ) if $params->{site} ne 'emptyhomes' || $period eq '26 weeks'; - my $token = FixMyStreet::App->model("DB::Token")->new_result( { + my $token = $rs->result_source->schema->resultset("Token")->new_result( { scope => 'questionnaire', data => $questionnaire->id, } ); |