aboutsummaryrefslogtreecommitdiffstats
path: root/bin/fixmystreet.com/island_roads_setup_messages
blob: 4969f18bae39dadac84b74a3dfb3101b1e543a95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/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";
}