diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-03-12 15:27:01 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-03-14 09:24:21 +0000 |
commit | 7305e916a9da3a72c8a4e9675d9bdcab6a4bc551 (patch) | |
tree | dbe870f27daaa195d61fe936939e40d53499d2a4 | |
parent | 45cb5c8567e0cb733004de4eb0d659e7c4467441 (diff) |
[Warwickshire] Add archive script data.
Add an update with each report closure.
-rwxr-xr-x | bin/oxfordshire/archive-old-enquiries | 9 | ||||
-rw-r--r-- | perllib/FixMyStreet/Script/ArchiveOldEnquiries.pm | 35 | ||||
-rw-r--r-- | t/app/script/archive_old_enquiries.t | 16 | ||||
-rw-r--r-- | templates/email/warwickshire/archive.txt | 26 |
4 files changed, 66 insertions, 20 deletions
diff --git a/bin/oxfordshire/archive-old-enquiries b/bin/oxfordshire/archive-old-enquiries index 7fe66703a..e82aa984e 100755 --- a/bin/oxfordshire/archive-old-enquiries +++ b/bin/oxfordshire/archive-old-enquiries @@ -17,10 +17,11 @@ use Getopt::Long::Descriptive; my ($opts, $usage) = describe_options( '%c %o', ['commit|c', "actually close reports and send emails. Omitting this flag will do a dry-run"], - ['body|b=s', "which body ID to close reports for"], - ['cobrand=s', "which cobrand template to use for sent emails"], - ['closure-cutoff=s', "Anything before this will be closed with no email"], - ['email-cutoff=s', "Anything before this will be closed with an email sent to the reporter"], + ['body|b=s', "which body ID to close reports for", { required => 1 } ], + ['user|u=s', "which user ID to assign closure updates to", { required => 1 } ], + ['cobrand=s', "which cobrand template to use for sent emails", { required => 1 } ], + ['closure-cutoff=s', "Anything before this will be closed with no email", { required => 1 } ], + ['email-cutoff=s', "Anything before this will be closed with an email sent to the reporter", { required => 1 } ], ['limit|l=s', "limit to a certain number of reports/users to be closed"], ['help|h', "print usage message and exit" ], ); diff --git a/perllib/FixMyStreet/Script/ArchiveOldEnquiries.pm b/perllib/FixMyStreet/Script/ArchiveOldEnquiries.pm index 5d1d45379..31876d83d 100644 --- a/perllib/FixMyStreet/Script/ArchiveOldEnquiries.pm +++ b/perllib/FixMyStreet/Script/ArchiveOldEnquiries.pm @@ -14,10 +14,6 @@ use FixMyStreet::Email; my $opts = { commit => 0, - body => '2237', - cobrand => 'oxfordshire', - closure_cutoff => "2015-01-01 00:00:00", - email_cutoff => "2016-01-01 00:00:00", }; sub query { @@ -84,11 +80,7 @@ sub archive { }); printf("Closing %d old reports, without sending emails: ", $problems_to_close->count); - - if ( $opts->{commit} ) { - $problems_to_close->update({ state => 'closed', send_questionnaire => 0 }); - } - + close_problems($problems_to_close); printf("done.\n") } @@ -132,10 +124,31 @@ sub send_email_and_close { unless ( $email_error ) { printf("done.\n Closing reports: "); - - $problems->update({ state => 'closed', send_questionnaire => 0 }); + close_problems($problems); printf("done.\n"); } else { printf("error! Not closing reports for this user.\n") } } + +sub close_problems { + return unless $opts->{commit}; + + my $problems = shift; + while (my $problem = $problems->next) { + my $timestamp = \'current_timestamp'; + $problem->add_to_comments( { + text => '', + created => $timestamp, + confirmed => $timestamp, + user_id => $opts->{user}, + name => _('an administrator'), + mark_fixed => 0, + anonymous => 0, + state => 'confirmed', + problem_state => 'closed', + extra => { is_superuser => 1 }, + } ); + $problem->update({ state => 'closed', send_questionnaire => 0 }); + } +} diff --git a/t/app/script/archive_old_enquiries.t b/t/app/script/archive_old_enquiries.t index e1adeec85..0475cb9ea 100644 --- a/t/app/script/archive_old_enquiries.t +++ b/t/app/script/archive_old_enquiries.t @@ -5,15 +5,18 @@ my $mech = FixMyStreet::TestMech->new(); $mech->clear_emails_ok; -my $opts = { - commit => 1, -}; - my $user = $mech->create_user_ok('test@example.com', name => 'Test User'); my $oxfordshire = $mech->create_body_ok(2237, 'Oxfordshire County Council'); my $west_oxon = $mech->create_body_ok(2420, 'West Oxfordshire District Council'); -$opts->{body} = $oxfordshire->id; +my $opts = { + commit => 1, + body => $oxfordshire->id, + cobrand => 'oxfordshire', + closure_cutoff => "2015-01-01 00:00:00", + email_cutoff => "2016-01-01 00:00:00", + user => $user->id, +}; subtest 'sets reports to the correct status' => sub { FixMyStreet::override_config { @@ -65,6 +68,9 @@ subtest 'sets reports to the correct status' => sub { is $report4->state, 'closed', 'Report 4 has been set to closed'; is $report5->state, 'closed', 'Report 5 has been set to closed'; + my $comment = $report1->comments->first; + is $comment->problem_state, 'closed'; + is $report->state, 'confirmed', 'Recent report has been left alone'; }; }; diff --git a/templates/email/warwickshire/archive.txt b/templates/email/warwickshire/archive.txt new file mode 100644 index 000000000..51ad37453 --- /dev/null +++ b/templates/email/warwickshire/archive.txt @@ -0,0 +1,26 @@ +Subject: Your reports on Warwickshire FixMyStreet + +Hello [% user.name %], + +FixMyStreet is being updated in Warwickshire to improve how problems get fixed. + +As part of these updates, we are closing old reports that appear to be resolved but remain open in the system. + +We noticed that you have [% report_count %] old [% nget('report', 'reports', report_count) %] on the system, which we've listed below. + +If your report is no longer an issue, you don't need to do anything. + +If you believe that your report is still a problem, you can reopen it by clicking or copying and pasting +the link marked 'View report' by a report and leaving an update. + +[% FOR report IN reports %] + +[% report.title %] + +Reported [% report.time_ago %] ago. + +View report: [% cobrand.base_url_for_report( report ) %][% report.tokenised_url( user, { reopen => 'true' } ) %]#update_form + +---- + +[% END %] |