diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-08-31 16:15:46 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-08-31 16:15:46 +0100 |
commit | cec5c77a4207b341947affed8e6e8e57ec29965d (patch) | |
tree | 246900550b394f956a8ac4bd76ffbe943cc8fb1e /bin | |
parent | c590981f0c198fa0491801a312a65eed054a0778 (diff) | |
parent | 51a5bcc74982aefea4f7b364e2f4bc49596bd9bf (diff) |
Merge branch 'move-report-states-to-database'
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/fixmystreet.com/fixture | 2 | ||||
-rwxr-xr-x | bin/update-schema | 20 |
2 files changed, 20 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 32c00ff5e..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) { @@ -195,6 +212,7 @@ else { # (assuming schema change files are never half-applied, which should be the case) sub get_db_version { return 'EMPTY' if ! table_exists('problem'); + return '0054' if table_exists('state'); return '0053' if table_exists('report_extra_fields'); return '0052' if table_exists('translation'); return '0051' if column_exists('contacts', 'state'); |