diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-08-22 16:27:32 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-08-31 15:37:09 +0100 |
commit | 27110ac506f071ad0c5925ef74de1321514c23c8 (patch) | |
tree | 61699c019d14a0b6abf4db20734b93f7c09d6093 /bin | |
parent | b43813d8f3c5bae07f0c7b9fe120bff32611d8bb (diff) |
Remove hardcoded states from Problem model.
We keep the internal states hardcoded, plus the core open (confirmed)
and closed ones, but the remainder are moved to the database.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/fixmystreet.com/fixture | 2 | ||||
-rwxr-xr-x | bin/update-schema | 19 |
2 files changed, 19 insertions, 2 deletions
diff --git a/bin/fixmystreet.com/fixture b/bin/fixmystreet.com/fixture index 6df675f7c..6cf5ad199 100755 --- a/bin/fixmystreet.com/fixture +++ b/bin/fixmystreet.com/fixture @@ -54,7 +54,7 @@ BEGIN END $func$; }) or die $!; - $db->dbh->do( scalar FixMyStreet->path_to('db/alert_types.sql')->slurp ) or die $!; + $db->dbh->do( scalar FixMyStreet->path_to('db/fixture.sql')->slurp ) or die $!; $db->dbh->do( scalar FixMyStreet->path_to('db/generate_secret.sql')->slurp ) or die $!; say "Emptied database"; } diff --git a/bin/update-schema b/bin/update-schema index 9a4f05813..a27bbbba1 100755 --- a/bin/update-schema +++ b/bin/update-schema @@ -40,6 +40,7 @@ BEGIN { } use FixMyStreet; +use FixMyStreet::Cobrand; use FixMyStreet::DB; use mySociety::MaPit; use Getopt::Long; @@ -112,7 +113,7 @@ if ($upgrade && $current_version eq 'EMPTY') { if ($commit) { run_statements(get_statements("$bin_dir/../db/schema.sql")); run_statements(get_statements("$bin_dir/../db/generate_secret.sql")); - run_statements(get_statements("$bin_dir/../db/alert_types.sql")); + run_statements(get_statements("$bin_dir/../db/fixture.sql")); } } elsif ($upgrade) { if ($version) { @@ -139,12 +140,28 @@ if ($upgrade && $current_version eq 'EMPTY') { my $area_ids = $db->dbh->selectcol_arrayref('SELECT area_id FROM body_areas'); if ( @$area_ids ) { my $areas = mySociety::MaPit::call('areas', $area_ids); + $db->txn_begin; foreach (values %$areas) { $db->dbh->do('UPDATE body SET name=? WHERE id=?', {}, $_->{name}, $_->{id}); } $db->txn_commit; } } + + if ( $commit && $current_version lt '0054' ) { + $nothing = 0; + print "States created, importing names\n"; + my @avail = FixMyStreet::Cobrand->available_cobrand_classes; + # Pick first available cobrand and language for database name import + my $cobrand = $avail[0] ? FixMyStreet::Cobrand::class($avail[0]) : 'FixMyStreet::Cobrand::Default'; + my $lang = $cobrand->new->set_lang_and_domain(undef, 1, FixMyStreet->path_to('locale')->stringify); + my $names = $db->dbh->selectcol_arrayref('SELECT name FROM state'); + $db->txn_begin; + foreach (@$names) { + $db->dbh->do('UPDATE state SET name=? WHERE name=?', {}, _($_), $_); + } + $db->txn_commit; + } } if ($downgrade) { |