diff options
| author | Matthew Somerville <matthew@mysociety.org> | 2020-07-10 14:38:17 +0100 |
|---|---|---|
| committer | Matthew Somerville <matthew@mysociety.org> | 2020-07-14 18:25:19 +0100 |
| commit | 67823bc788ce744e1228a8602b9a5aa805771ced (patch) | |
| tree | 0b1eddd4e071314573e52206d0061cab022e1cd0 /bin | |
| parent | eed6158981240afce10824e82fa86f14b38f3167 (diff) | |
Centralise update creation to include fields.
Given the user, we can infer the name if not provided, and the extra
data if a staff user. We can also provide defaults for various other
fields. Always have superuser take precedence over from_body.
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/fixmystreet.com/banes-close-reports | 1 | ||||
| -rwxr-xr-x | bin/fixmystreet.com/buckinghamshire-flytipping | 1 | ||||
| -rwxr-xr-x | bin/one-off-update-staff | 38 |
3 files changed, 38 insertions, 2 deletions
diff --git a/bin/fixmystreet.com/banes-close-reports b/bin/fixmystreet.com/banes-close-reports index bba4c88e0..79c1c44b9 100755 --- a/bin/fixmystreet.com/banes-close-reports +++ b/bin/fixmystreet.com/banes-close-reports @@ -50,7 +50,6 @@ my $q = FixMyStreet::DB->resultset("Problem")->search({ # Provide some variables to the archiving script FixMyStreet::Script::ArchiveOldEnquiries::update_options({ user => $body->comment_user->id, - user_name => $body->comment_user->name, closure_text => CLOSURE_TEXT, retain_alerts => 1, commit => $opts->commit, diff --git a/bin/fixmystreet.com/buckinghamshire-flytipping b/bin/fixmystreet.com/buckinghamshire-flytipping index a312f9fbe..65e87d30e 100755 --- a/bin/fixmystreet.com/buckinghamshire-flytipping +++ b/bin/fixmystreet.com/buckinghamshire-flytipping @@ -79,7 +79,6 @@ sub find_problems { # Provide some variables to the archiving script FixMyStreet::Script::ArchiveOldEnquiries::update_options({ user => $body->comment_user->id, - user_name => $body->comment_user->name, closure_text => $template->text, retain_alerts => $retain_alerts, commit => $opts->commit, diff --git a/bin/one-off-update-staff b/bin/one-off-update-staff new file mode 100755 index 000000000..d94d6b961 --- /dev/null +++ b/bin/one-off-update-staff @@ -0,0 +1,38 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; +} + +use FixMyStreet::DB; + +my $rs = FixMyStreet::DB->resultset("Comment")->search({ + 'user.from_body' => { '!=', undef }, + 'user.is_superuser' => 0, + 'me.extra' => [ undef, { -not_like => '%is_body_user%' } ], +}, { + "+columns" => ["user.from_body"], + join => 'user', +}); +while (my $row = $rs->next) { + my $id = $row->user->{_column_data}->{from_body}; # Avoid DB lookups + $row->set_extra_metadata( is_body_user => $id ); + $row->update; +} + +$rs = FixMyStreet::DB->resultset("Comment")->search({ + 'user.is_superuser' => 1, + 'me.extra' => [ undef, { -not_like => '%is_superuser%' } ], +}, { + join => 'user', +}); +while (my $row = $rs->next) { + $row->set_extra_metadata( is_superuser => 1 ); + $row->update; +} |
