aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2020-03-31 09:37:09 +0100
committerStruan Donald <struan@exo.org.uk>2020-03-31 09:58:59 +0100
commit10b16b9dac996f3593326245993579ceff5d74bd (patch)
tree8c58f367f0b48222051a5670c5ab76c35224e4d2
parent6973a7adb8b77f99dcf0ee9205cb94a0031f159c (diff)
[HE] script to add appropriate areas to HE
Adds all English unitary and county councils
-rwxr-xr-xbin/highwaysengland/update_areas_covered51
1 files changed, 51 insertions, 0 deletions
diff --git a/bin/highwaysengland/update_areas_covered b/bin/highwaysengland/update_areas_covered
new file mode 100755
index 000000000..3affe3adb
--- /dev/null
+++ b/bin/highwaysengland/update_areas_covered
@@ -0,0 +1,51 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw/ say /;
+
+BEGIN {
+ use File::Basename qw(dirname);
+ use File::Spec;
+ my $d = dirname(File::Spec->rel2abs($0));
+ require "$d/../../setenv.pl";
+}
+
+use FixMyStreet;
+use FixMyStreet::DB;
+use FixMyStreet::MapIt;
+use Term::ANSIColor;
+use Getopt::Long::Descriptive;
+
+my ($opt, $usage) = describe_options(
+ '%c %o',
+ [ 'commit', "Actually commit changes to the database" ],
+ [ 'help', "print usage message and exit", { shortcircuit => 1 } ],
+);
+print($usage->text), exit if $opt->help;
+
+my $areas = FixMyStreet::MapIt::call(
+ 'areas/CTY,UTA,MTD,LBO'
+);
+
+my $db;
+END {
+ if ($db) {
+ $opt->commit ? $db->txn_commit : $db->txn_rollback;
+ }
+}
+
+$db = FixMyStreet::DB->schema->storage;
+$db->txn_begin;
+if (!$opt->commit) {
+ say colored("NOT COMMITTING TO DATABASE", 'cyan');
+}
+
+my $body = FixMyStreet::DB->resultset('Body')->find({ name => 'Highways England' });
+die "Highways England not found\n" unless $body;
+
+for my $area ( values %{ $areas } ) {
+ next unless $area->{country} eq 'E';
+
+ FixMyStreet::DB->resultset('BodyArea')->find_or_create( { body => $body, area_id => $area->{id} } );
+}