diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/JSON.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Model/DB.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Model/PhotoSet.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UKCouncils.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Zurich.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB.pm | 5 | ||||
-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 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/EmptyHomes.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Open311.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Zurich.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/TestMech.pm | 16 |
18 files changed, 59 insertions, 61 deletions
diff --git a/perllib/FixMyStreet/App/Controller/JSON.pm b/perllib/FixMyStreet/App/Controller/JSON.pm index 959ead245..be738bb8b 100644 --- a/perllib/FixMyStreet/App/Controller/JSON.pm +++ b/perllib/FixMyStreet/App/Controller/JSON.pm @@ -8,7 +8,6 @@ use JSON; use DateTime; use DateTime::Format::ISO8601; use List::MoreUtils 'uniq'; -use FixMyStreet::App; =head1 NAME @@ -81,7 +80,7 @@ sub problems : Local { $date_col = 'lastupdate'; } - my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser; + my $dt_parser = $c->model('DB')->schema->storage->datetime_parser; my $one_day = DateTime::Duration->new( days => 1 ); my $query = { diff --git a/perllib/FixMyStreet/App/Model/DB.pm b/perllib/FixMyStreet/App/Model/DB.pm index f9e43172f..ac1f98dc9 100644 --- a/perllib/FixMyStreet/App/Model/DB.pm +++ b/perllib/FixMyStreet/App/Model/DB.pm @@ -8,7 +8,7 @@ use FixMyStreet; __PACKAGE__->config( schema_class => 'FixMyStreet::DB', - connect_info => FixMyStreet->dbic_connect_info, + connect_info => sub { FixMyStreet::DB->storage->dbh }, ); =head1 NAME diff --git a/perllib/FixMyStreet/App/Model/PhotoSet.pm b/perllib/FixMyStreet/App/Model/PhotoSet.pm index b18460821..f1334ff38 100644 --- a/perllib/FixMyStreet/App/Model/PhotoSet.pm +++ b/perllib/FixMyStreet/App/Model/PhotoSet.pm @@ -56,7 +56,7 @@ has upload_dir => ( lazy => 1, default => sub { my $self = shift; - my $cache_dir = path( $self->c->config->{UPLOAD_DIR} ); + my $cache_dir = path( FixMyStreet->config('UPLOAD_DIR') ); $cache_dir->mkpath; unless ( -d $cache_dir && -w $cache_dir ) { warn "Can't find/write to photo cache directory '$cache_dir'"; diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 9541f2601..48c997047 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -682,7 +682,7 @@ sub get_body_sender { if ( $body->can_be_devolved ) { # look up via category - my $config = FixMyStreet::App->model("DB::Contact")->search( { body_id => $body->id, category => $category } )->first; + my $config = $body->result_source->schema->resultset("Contact")->search( { body_id => $body->id, category => $category } )->first; if ( $config->send_method ) { return { method => $config->send_method, config => $config }; } else { diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm index 074da0915..66d8bd472 100644 --- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -113,7 +113,7 @@ sub owns_problem { if (ref $report eq 'HASH') { return unless $report->{bodies_str}; @bodies = split /,/, $report->{bodies_str}; - @bodies = FixMyStreet::App->model('DB::Body')->search({ id => \@bodies })->all; + @bodies = FixMyStreet::DB->resultset('Body')->search({ id => \@bodies })->all; } else { # Object @bodies = values %{$report->bodies}; } diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm index 6da3e566c..8c08b82b1 100644 --- a/perllib/FixMyStreet/Cobrand/Zurich.pm +++ b/perllib/FixMyStreet/Cobrand/Zurich.pm @@ -850,7 +850,7 @@ sub admin_report_edit { # Add new update from status_update if (my $update = $c->get_param('status_update')) { - FixMyStreet::App->model('DB::Comment')->create( { + $c->model('DB::Comment')->create( { text => $update, user => $c->user->obj, state => 'unconfirmed', @@ -1010,10 +1010,10 @@ sub _admin_send_email { } sub munge_sendreport_params { - my ($self, $c, $row, $h, $params) = @_; + my ($self, $row, $h, $params) = @_; if ($row->state =~ /^(closed|investigating)$/ && $row->get_extra_metadata('publish_photo')) { # we attach images to reports sent to external bodies - my $photoset = $row->get_photoset($c); + my $photoset = $row->get_photoset(); my @images = $photoset->all_images or return; my $index = 0; diff --git a/perllib/FixMyStreet/DB.pm b/perllib/FixMyStreet/DB.pm index a1767abe9..d920c809f 100644 --- a/perllib/FixMyStreet/DB.pm +++ b/perllib/FixMyStreet/DB.pm @@ -15,5 +15,8 @@ __PACKAGE__->load_namespaces; # Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CjFpUvon7KggFM7OF7VK/w -# You can replace this text with custom code or comments, and it will be preserved on regeneration +use FixMyStreet; + +__PACKAGE__->connection(FixMyStreet->dbic_connect_info); + 1; 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, } ); diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index 95c460006..bc526ded2 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -11,7 +11,7 @@ sub build_recipient_list { my $all_confirmed = 1; foreach my $body ( @{ $self->bodies } ) { - my $contact = FixMyStreet::App->model("DB::Contact")->find( { + my $contact = $row->result_source->schema->resultset("Contact")->find( { deleted => 0, body_id => $body->id, category => $row->category @@ -94,9 +94,7 @@ sub send { From => $self->send_from( $row ), }; - my $app = FixMyStreet::App->new( cobrand => $cobrand ); - - $cobrand->munge_sendreport_params($app, $row, $h, $params) if $cobrand->can('munge_sendreport_params'); + $cobrand->munge_sendreport_params($row, $h, $params) if $cobrand->can('munge_sendreport_params'); $params->{Bcc} = $self->bcc if @{$self->bcc}; diff --git a/perllib/FixMyStreet/SendReport/EmptyHomes.pm b/perllib/FixMyStreet/SendReport/EmptyHomes.pm index ce69aaac3..bf7164e21 100644 --- a/perllib/FixMyStreet/SendReport/EmptyHomes.pm +++ b/perllib/FixMyStreet/SendReport/EmptyHomes.pm @@ -12,7 +12,7 @@ sub build_recipient_list { my $all_confirmed = 1; foreach my $body ( @{ $self->bodies } ) { - my $contact = FixMyStreet::App->model("DB::Contact")->find( { + my $contact = $row->result_source->schema->resultset("Contact")->find( { deleted => 0, body_id => $body->id, category => 'Empty property', diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm index fa216466e..14dd65fa6 100644 --- a/perllib/FixMyStreet/SendReport/Open311.pm +++ b/perllib/FixMyStreet/SendReport/Open311.pm @@ -5,7 +5,6 @@ use namespace::autoclean; BEGIN { extends 'FixMyStreet::SendReport'; } -use FixMyStreet::App; use mySociety::Config; use DateTime::Format::W3CDTF; use Open311; @@ -85,7 +84,7 @@ sub send { } # FIXME: we've already looked this up before - my $contact = FixMyStreet::App->model("DB::Contact")->find( { + my $contact = $row->result_source->schema->resultset("Contact")->find( { deleted => 0, body_id => $body->id, category => $row->category diff --git a/perllib/FixMyStreet/SendReport/Zurich.pm b/perllib/FixMyStreet/SendReport/Zurich.pm index 2838440cb..7af4cf4f5 100644 --- a/perllib/FixMyStreet/SendReport/Zurich.pm +++ b/perllib/FixMyStreet/SendReport/Zurich.pm @@ -14,7 +14,7 @@ sub build_recipient_list { # Wunsch set, but external_message hasn't yet been filled in. TODO should # we instead be holding off sending?) if ( $row->external_body ) { - $body = FixMyStreet::App->model("DB::Body")->find( { id => $row->external_body } ); + $body = $row->result_source->schema->resultset("Body")->find( { id => $row->external_body } ); $h->{bodies_name} = $body->name; $h->{external_message} = $row->get_extra_metadata('external_message') || ''; } @@ -29,7 +29,7 @@ sub build_recipient_list { my $parent = $body->parent; if ($parent && !$parent->parent) { # Division, might have an individual contact email address - my $contact = FixMyStreet::App->model("DB::Contact")->find( { + my $contact = $row->result_source->schema->resultset("Contact")->find( { body_id => $body->id, category => $row->category } ); @@ -72,7 +72,7 @@ sub send_from { if ( $row->external_body ) { my $body = @{ $self->bodies }[0]; my $body_email = $body->endpoint; - my $contact = FixMyStreet::App->model("DB::Contact")->find( { + my $contact = $body->result_source->schema->resultset("Contact")->find( { body_id => $body->id, category => $row->category } ); diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm index cc5f9dd71..d3adce08b 100644 --- a/perllib/FixMyStreet/TestMech.pm +++ b/perllib/FixMyStreet/TestMech.pm @@ -66,7 +66,7 @@ sub create_user_ok { my ($email) = @_; my $user = - FixMyStreet::App->model('DB::User') + FixMyStreet::DB->resultset('User') ->find_or_create( { email => $email } ); ok $user, "found/created user for $email"; @@ -147,7 +147,7 @@ sub delete_user { my $user = ref $email_or_user ? $email_or_user - : FixMyStreet::App->model('DB::User') + : FixMyStreet::DB->resultset('User') ->find( { email => $email_or_user } ); # If no user found we can't delete them @@ -567,7 +567,7 @@ sub delete_problems_for_body { my $mech = shift; my $body = shift; - my $reports = FixMyStreet::App->model('DB::Problem')->search( { bodies_str => $body } ); + my $reports = FixMyStreet::DB->resultset('Problem')->search( { bodies_str => $body } ); if ( $reports ) { for my $r ( $reports->all ) { $r->comments->delete; @@ -587,7 +587,7 @@ sub create_contact_ok { note => 'Created for test', @_ ); - my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create( \%contact_params ); + my $contact = FixMyStreet::DB->resultset('Contact')->find_or_create( \%contact_params ); ok $contact, 'found/created contact ' . $contact->category;; return $contact; } @@ -596,7 +596,7 @@ sub create_body_ok { my $self = shift; my ( $area_id, $name, %extra ) = @_; - my $body = FixMyStreet::App->model('DB::Body'); + my $body = FixMyStreet::DB->resultset('Body'); my $params = { name => $name }; if ($extra{id}) { $body = $body->update_or_create({ %$params, id => $extra{id} }, { key => 'primary' }); @@ -606,7 +606,7 @@ sub create_body_ok { ok $body, "found/created body $name"; $body->body_areas->delete; - FixMyStreet::App->model('DB::BodyArea')->find_or_create({ + FixMyStreet::DB->resultset('BodyArea')->find_or_create({ area_id => $area_id, body_id => $body->id, }); @@ -621,7 +621,7 @@ sub create_problems_for_body { my $dt = $params->{dt} || DateTime->now(); my $user = $params->{user} || - FixMyStreet::App->model('DB::User') + FixMyStreet::DB->resultset('User') ->find_or_create( { email => 'test@example.com', name => 'Test User' } ); delete $params->{user}; @@ -656,7 +656,7 @@ sub create_problems_for_body { my %report_params = ( %$default_params, %$params ); my $problem = - FixMyStreet::App->model('DB::Problem')->create( \%report_params ); + FixMyStreet::DB->resultset('Problem')->create( \%report_params ); push @problems, $problem; $count--; |