diff options
author | Matthew Somerville <matthew@mysociety.org> | 2019-10-15 11:41:14 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2019-10-21 14:23:53 +0100 |
commit | f974c4952c9228a0ef60e7fb68704f4ef5c7cbb9 (patch) | |
tree | e20e6e817ba8fa64a838e6d74179990dc2de7dc6 /bin | |
parent | 86866375d761b2b2e6725c8d5ae948cc4b772dde (diff) |
[fixmystreet.com] Generalise emergency message script.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/fixmystreet.com/add_emergency_message | 83 | ||||
-rw-r--r-- | bin/fixmystreet.com/island_roads_setup_messages | 73 |
2 files changed, 83 insertions, 73 deletions
diff --git a/bin/fixmystreet.com/add_emergency_message b/bin/fixmystreet.com/add_emergency_message new file mode 100755 index 000000000..5167cea32 --- /dev/null +++ b/bin/fixmystreet.com/add_emergency_message @@ -0,0 +1,83 @@ +#!/usr/bin/env perl +# +# One off script to add emergency messages to a council + +use strict; +use warnings; +use v5.14; + +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../../setenv.pl"; +} + +use Getopt::Long::Descriptive; +use Term::ANSIColor; +use FixMyStreet::DB; + +my ($opts, $usage) = describe_options( + '%c %o', + ['commit', 'whether to commit changes to the database' ], + ['body=s', 'name of body to attach question to', { required => 1 } ], + ['code=s', 'code to use for question', { required => 1 } ], + ['question=s', 'question to ask user first', { required => 1 } ], + ['yes=s', 'yes answer to question', { required => 1 } ], + ['no=s', 'no answer to question', { required => 1 } ], + ['message=s', 'message to be shown if form disabled', { required => 1 } ], + ['send_method=s', 'send method to restrict categories to' ], + ['help|h', "print usage message and exit" ], +); +$usage->die if $opts->help; + +if (!$opts->commit) { + say colored("*** DRY RUN ***", 'cyan'); +} + +my $field = { + order => 0, + required => 'true', + protected => 'true', + code => $opts->code, + description => $opts->question, + datatype => 'singlevaluelist', + variable => 'true', + values => [ + { + key => 'yes', + name => $opts->yes, + disable => 1, + disable_message => $opts->message, + }, + { + key => 'no', + name => $opts->no, + } + ], +}; + +my $body = FixMyStreet::DB->resultset("Body")->find({ name => $opts->body }); +unless ($body) { + say STDERR "Could not find body " . $opts->body; + exit 1; +} + +my $contacts = $body->contacts->not_deleted; +$contacts = $contacts->search({ send_method => $opts->send_method }) if $opts->send_method; +foreach my $category ($contacts->all) { + my $found = $category->update_extra_field($field); + if ($found) { + say colored("Updating ", 'red') . $opts->code . " message disable form on " . $category->category . ", " . $opts->body; + } else { + say colored("Making ", 'green') . $opts->code . " message disable form on " . $category->category . ", " . $opts->body; + } + + if ($opts->commit) { + $category->update({ + editor => $0, + whenedited => \'current_timestamp', + note => $opts->code . ' extra field updated by script', + }); + } +} diff --git a/bin/fixmystreet.com/island_roads_setup_messages b/bin/fixmystreet.com/island_roads_setup_messages deleted file mode 100644 index 4969f18ba..000000000 --- a/bin/fixmystreet.com/island_roads_setup_messages +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env perl -# -# One off script to transfer the hardcoded JS messages to the database - -use strict; -use warnings; -use v5.14; - -BEGIN { - use File::Basename qw(dirname); - use File::Spec; - my $d = dirname(File::Spec->rel2abs($0)); - require "$d/../../setenv.pl"; -} - -use FixMyStreet::DB; - -use Getopt::Long; - -my $commit; -GetOptions( - 'commit' => \$commit, -); - -if (!$commit) { - say "*** DRY RUN ***"; -} - -my $urgent = { - order => 0, - required => 'true', - protected => 'true', - code => 'urgent', - description => 'To ensure your report is dealt with effectively, please tell us the severity of the issue:-', - datatype_description => 'You have indicated that the issue requires an urgent response, please phone Island Roads on 01983 822440 so that we can respond to the issue appropriately.', - datatype => 'singlevaluelist', - variable => 'true', - values => [ - { - key => 'urgent', - name => 'The issue requires an urgent response/action', - disable => 1, - }, - { - key => 'not_urgent', - name => 'The issue requires a routine/non-urgent response/action', - } - ], -}; - -my $iow = FixMyStreet::DB->resultset("Body")->find({ name => 'Isle of Wight Council' }); -if ($iow) { - my @iow_contacts = $iow->contacts->search({ send_method => 'Triage' })->all; - foreach my $category (@iow_contacts) { - my $extra_fields = $category->get_extra_fields; - my $found = 0; - foreach (@$extra_fields) { - next unless $_->{code} eq 'urgent'; - $_ = $urgent; - $found = 1; - } - if (!$found) { - push @$extra_fields, $urgent; - } - $category->set_extra_fields(@$extra_fields); - say "Making emergency message disable form on " . $category->category . ", Isle of Wight"; - if ($commit) { - $category->update; - } - } -} else { - say STDERR "Could not find IoW"; -} |