aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/fixmystreet.com/add_emergency_message81
-rwxr-xr-xbin/northamptonshire/update-emergency-message59
2 files changed, 111 insertions, 29 deletions
diff --git a/bin/fixmystreet.com/add_emergency_message b/bin/fixmystreet.com/add_emergency_message
index 5167cea32..3cfeae83e 100755
--- a/bin/fixmystreet.com/add_emergency_message
+++ b/bin/fixmystreet.com/add_emergency_message
@@ -21,10 +21,15 @@ 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 } ],
+ ['mode' => 'hidden' => { one_of => [
+ ['questions' => 'add an emergency question'],
+ ['category' => 'add an emergency message'],
+ ], required => 1 }],
+ ['update' => 'only update existing messages'],
+ ['code=s', 'code to use for question'],
+ ['question=s', 'question to ask user first'],
+ ['yes=s', 'yes answer to question'],
+ ['no=s', 'no answer to question'],
['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" ],
@@ -35,27 +40,43 @@ 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 $field;
+
+if ( $opts->mode eq 'questions' ) {
+ die "questions, code, yes and no required"
+ unless $opts->questions && $opts->code && $opts->yes && $opts->no;
+
+ $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,
+ }
+ ],
+ };
+} else {
+ $field = {
+ order => 0,
+ protected => 'true',
+ disable_form => 'true',
+ code => '_fms_disable_',
+ description => $opts->message,
+ variable => 'false',
+ };
+}
my $body = FixMyStreet::DB->resultset("Body")->find({ name => $opts->body });
unless ($body) {
@@ -66,11 +87,13 @@ unless ($body) {
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);
+ my $found = $category->get_extra_field(code => $field->{code});
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;
+ say colored("Updating ", 'red') . $field->{code} . " message disable form on " . $category->category . ", " . $opts->body;
+ $category->update_extra_field($field);
+ } elsif (!$opts->update) {
+ say colored("Making ", 'green') . $field->{code} . " message disable form on " . $category->category . ", " . $opts->body;
+ $category->update_extra_field($field);
}
if ($opts->commit) {
diff --git a/bin/northamptonshire/update-emergency-message b/bin/northamptonshire/update-emergency-message
new file mode 100755
index 000000000..7248e9159
--- /dev/null
+++ b/bin/northamptonshire/update-emergency-message
@@ -0,0 +1,59 @@
+#!/usr/bin/env perl
+
+# update the emergency message on NCC categories
+
+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, $message);
+GetOptions(
+ 'commit' => \$commit,
+ 'message=s' => \$message,
+);
+
+if (!$commit) {
+ say "*** DRY RUN ***";
+}
+
+my $northants = FixMyStreet::DB->resultset("Body")->find({ name => 'Northamptonshire County Council' });
+if ($northants) {
+ my @northants_contacts = $northants->contacts->all;
+ my $found_total = 0;
+ foreach my $category (@northants_contacts) {
+ my $extra_fields = $category->get_extra_fields;
+ my $found = 0;
+ foreach (@$extra_fields) {
+ next unless $_->{code} eq 'emergency';
+ $found_total++;
+ $_->{code} = '_fms_disable_';
+ $_->{description} = $message;
+ $_->{protected} = 'true';
+ $_->{disable_form} = 'true';
+ $found = 1;
+ }
+ if ($found) {
+ $category->set_extra_fields(@$extra_fields);
+ say "Updating emergency message on " . $category->category . ", Northamptonshire";
+ if ($commit) {
+ $category->update;
+ }
+ }
+ }
+ if (!$found_total) {
+ say STDERR "No emergency messages found for Northamptonshire";
+ }
+} else {
+ say STDERR "Could not find Northamptonshire";
+}