diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 21 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Factories.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Contact.pm | 28 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/ContactsHistory.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Contact.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Open311.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/TestMech.pm | 3 | ||||
-rw-r--r-- | perllib/Open311/PopulateServiceList.pm | 13 |
9 files changed, 43 insertions, 55 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index d354e6929..fc21aeedb 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -96,11 +96,11 @@ sub index : Path : Args(0) { my $contacts = $c->model('DB::Contact')->summary_count(); my %contact_counts = - map { $_->confirmed => $_->get_column('confirmed_count') } $contacts->all; + map { $_->state => $_->get_column('state_count') } $contacts->all; - $contact_counts{0} ||= 0; - $contact_counts{1} ||= 0; - $contact_counts{total} = $contact_counts{0} + $contact_counts{1}; + $contact_counts{confirmed} ||= 0; + $contact_counts{unconfirmed} ||= 0; + $contact_counts{total} = $contact_counts{confirmed} + $contact_counts{unconfirmed}; $c->stash->{contacts} = \%contact_counts; @@ -264,8 +264,8 @@ sub bodies : Path('bodies') : Args(0) { my $contacts = $c->model('DB::Contact')->search( undef, { - select => [ 'body_id', { count => 'id' }, { count => \'case when deleted then 1 else null end' }, - { count => \'case when confirmed then 1 else null end' } ], + select => [ 'body_id', { count => 'id' }, { count => \'case when state = \'deleted\' then 1 else null end' }, + { count => \'case when state = \'confirmed\' then 1 else null end' } ], as => [qw/body_id c deleted confirmed/], group_by => [ 'body_id' ], result_class => 'DBIx::Class::ResultClass::HashRefInflator' @@ -364,8 +364,7 @@ sub update_contacts : Private { } $contact->email( $email ); - $contact->confirmed( $c->get_param('confirmed') ? 1 : 0 ); - $contact->deleted( $c->get_param('deleted') ? 1 : 0 ); + $contact->state( $c->get_param('state') ); $contact->non_public( $c->get_param('non_public') ? 1 : 0 ); $contact->note( $c->get_param('note') ); $contact->whenedited( \'current_timestamp' ); @@ -420,7 +419,7 @@ sub update_contacts : Private { $contacts->update( { - confirmed => 1, + state => 'confirmed', whenedited => \'current_timestamp', note => 'Confirmed', editor => $editor, @@ -484,8 +483,8 @@ sub fetch_contacts : Private { my $contacts = $c->stash->{body}->contacts->search(undef, { order_by => [ 'category' ] } ); $c->stash->{contacts} = $contacts; - $c->stash->{live_contacts} = $contacts->search({ deleted => 0 }); - $c->stash->{any_not_confirmed} = $contacts->search({ confirmed => 0 })->count; + $c->stash->{live_contacts} = $contacts->search({ state => { '!=' => 'deleted' } }); + $c->stash->{any_not_confirmed} = $contacts->search({ state => 'unconfirmed' })->count; if ( $c->get_param('text') && $c->get_param('text') eq '1' ) { $c->stash->{template} = 'admin/council_contacts.txt'; diff --git a/perllib/FixMyStreet/DB/Factories.pm b/perllib/FixMyStreet/DB/Factories.pm index acf88063e..ec4dd630a 100644 --- a/perllib/FixMyStreet/DB/Factories.pm +++ b/perllib/FixMyStreet/DB/Factories.pm @@ -91,8 +91,7 @@ __PACKAGE__->fields({ (my $email = lc $_) =~ s/ /-/g; lc $category . '@example.org'; }), - confirmed => 1, - deleted => 0, + state => 'confirmed', editor => 'Factory', whenedited => \'current_timestamp', note => 'Created by factory', diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm index a620b7358..3454c5806 100644 --- a/perllib/FixMyStreet/DB/Result/Contact.pm +++ b/perllib/FixMyStreet/DB/Result/Contact.pm @@ -11,8 +11,17 @@ use base 'DBIx::Class::Core'; __PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime", "EncodedColumn"); __PACKAGE__->table("contacts"); __PACKAGE__->add_columns( + "id", + { + data_type => "integer", + is_auto_increment => 1, + is_nullable => 0, + sequence => "contacts_id_seq", + }, "body_id", { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "category", + { data_type => "text", default_value => "Other", is_nullable => 0 }, "email", { data_type => "text", is_nullable => 0 }, "editor", @@ -21,19 +30,6 @@ __PACKAGE__->add_columns( { data_type => "timestamp", is_nullable => 0 }, "note", { data_type => "text", is_nullable => 0 }, - "confirmed", - { data_type => "boolean", is_nullable => 0 }, - "category", - { data_type => "text", default_value => "Other", is_nullable => 0 }, - "deleted", - { data_type => "boolean", is_nullable => 0 }, - "id", - { - data_type => "integer", - is_auto_increment => 1, - is_nullable => 0, - sequence => "contacts_id_seq", - }, "extra", { data_type => "text", is_nullable => 1 }, "non_public", @@ -46,6 +42,8 @@ __PACKAGE__->add_columns( { data_type => "text", default_value => "", is_nullable => 1 }, "send_method", { data_type => "text", is_nullable => 1 }, + "state", + { data_type => "text", is_nullable => 0 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("contacts_body_id_category_idx", ["body_id", "category"]); @@ -75,8 +73,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-02-13 15:11:11 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:f9VepR/oPyr3z6PUpJ4w2A +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-07-08 20:45:04 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:t/VtPP11R8bbqPZdEVXffw __PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); __PACKAGE__->rabx_column('extra'); diff --git a/perllib/FixMyStreet/DB/Result/ContactsHistory.pm b/perllib/FixMyStreet/DB/Result/ContactsHistory.pm index 7126d91c9..c90bb9d66 100644 --- a/perllib/FixMyStreet/DB/Result/ContactsHistory.pm +++ b/perllib/FixMyStreet/DB/Result/ContactsHistory.pm @@ -26,22 +26,20 @@ __PACKAGE__->add_columns( { data_type => "text", default_value => "Other", is_nullable => 0 }, "email", { data_type => "text", is_nullable => 0 }, - "confirmed", - { data_type => "boolean", is_nullable => 0 }, - "deleted", - { data_type => "boolean", is_nullable => 0 }, "editor", { data_type => "text", is_nullable => 0 }, "whenedited", { data_type => "timestamp", is_nullable => 0 }, "note", { data_type => "text", is_nullable => 0 }, + "state", + { data_type => "text", is_nullable => 0 }, ); __PACKAGE__->set_primary_key("contacts_history_id"); -# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-12 16:37:16 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:sxflEBBn0Mn0s3MroWnWFA +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-07-08 20:45:04 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:HTt0g29yXTM/WyHKN179FA # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/perllib/FixMyStreet/DB/ResultSet/Contact.pm b/perllib/FixMyStreet/DB/ResultSet/Contact.pm index f402b5461..d32453942 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Contact.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Contact.pm @@ -10,13 +10,13 @@ sub me { join('.', shift->current_source_alias, shift || q{}) } $rs = $rs->not_deleted(); -Filter down to not deleted contacts - which have C<deleted> set to false; +Filter down to not deleted contacts (so active or inactive). =cut sub not_deleted { my $rs = shift; - return $rs->search( { $rs->me('deleted') => 0 } ); + return $rs->search( { $rs->me('state') => { '!=' => 'deleted' } } ); } sub summary_count { @@ -25,9 +25,9 @@ sub summary_count { return $rs->search( $restriction, { - group_by => ['confirmed'], - select => [ 'confirmed', { count => 'id' } ], - as => [qw/confirmed confirmed_count/] + group_by => ['state'], + select => [ 'state', { count => 'id' } ], + as => [qw/state state_count/] } ); } diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index 28f3411d0..eefb14553 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -12,15 +12,14 @@ sub build_recipient_list { my $all_confirmed = 1; foreach my $body ( @{ $self->bodies } ) { - my $contact = $row->result_source->schema->resultset("Contact")->find( { - deleted => 0, + my $contact = $row->result_source->schema->resultset("Contact")->not_deleted->find( { body_id => $body->id, category => $row->category } ); - my ($body_email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note ); + my ($body_email, $state, $note) = ( $contact->email, $contact->state, $contact->note ); - unless ($confirmed) { + unless ($state eq 'confirmed') { $all_confirmed = 0; $note = 'Body ' . $row->bodies_str . ' deleted' unless $note; diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm index 059690612..eaa223bb2 100644 --- a/perllib/FixMyStreet/SendReport/Open311.pm +++ b/perllib/FixMyStreet/SendReport/Open311.pm @@ -35,8 +35,7 @@ sub send { # Try and fill in some ones that we've been asked for, but not asked the user for - my $contact = $row->result_source->schema->resultset("Contact")->find( { - deleted => 0, + my $contact = $row->result_source->schema->resultset("Contact")->not_deleted->find( { body_id => $body->id, category => $row->category } ); diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm index 92588a598..eef767ce6 100644 --- a/perllib/FixMyStreet/TestMech.pm +++ b/perllib/FixMyStreet/TestMech.pm @@ -656,8 +656,7 @@ sub delete_defect_type { sub create_contact_ok { my $self = shift; my %contact_params = ( - confirmed => 1, - deleted => 0, + state => 'confirmed', editor => 'Test', whenedited => \'current_timestamp', note => 'Created for test', diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm index c5f17334b..540425bf1 100644 --- a/perllib/Open311/PopulateServiceList.pm +++ b/perllib/Open311/PopulateServiceList.pm @@ -131,14 +131,13 @@ sub _handle_existing_contact { print $self->_current_body->id . " already has a contact for service code " . $self->_current_service->{service_code} . "\n" if $self->verbose >= 2; - if ( $contact->deleted || $service_name ne $contact->category || $self->_current_service->{service_code} ne $contact->email ) { + if ( $contact->state eq 'deleted' || $service_name ne $contact->category || $self->_current_service->{service_code} ne $contact->email ) { eval { $contact->update( { category => $service_name, email => $self->_current_service->{service_code}, - confirmed => 1, - deleted => 0, + state => 'confirmed', editor => $0, whenedited => \'current_timestamp', note => 'automatically undeleted by script', @@ -175,8 +174,7 @@ sub _create_contact { email => $self->_current_service->{service_code}, body_id => $self->_current_body->id, category => $service_name, - confirmed => 1, - deleted => 0, + state => 'confirmed', editor => $0, whenedited => \'current_timestamp', note => 'created automatically by script', @@ -278,11 +276,10 @@ sub _normalize_service_name { sub _delete_contacts_not_in_service_list { my $self = shift; - my $found_contacts = $self->schema->resultset('Contact')->search( + my $found_contacts = $self->schema->resultset('Contact')->not_deleted->search( { email => { -not_in => $self->found_contacts }, body_id => $self->_current_body->id, - deleted => 0, } ); @@ -299,7 +296,7 @@ sub _delete_contacts_not_in_service_list { $found_contacts->update( { - deleted => 1, + state => 'deleted', editor => $0, whenedited => \'current_timestamp', note => 'automatically marked as deleted by script' |