diff options
Diffstat (limited to 'bin/zurich')
-rwxr-xr-x | bin/zurich/convert_internal_notes_to_comments | 73 | ||||
-rwxr-xr-x | bin/zurich/geocode | 45 |
2 files changed, 118 insertions, 0 deletions
diff --git a/bin/zurich/convert_internal_notes_to_comments b/bin/zurich/convert_internal_notes_to_comments new file mode 100755 index 000000000..ddf74851f --- /dev/null +++ b/bin/zurich/convert_internal_notes_to_comments @@ -0,0 +1,73 @@ +#!/usr/bin/env perl + +=head1 DESCRIPTION + +This is a Zurich specific migration script. + +It converts the internal notes that used to be stored on the problem in the +extra hash into comments instead. + + ./bin/zurich/convert_internal_notes_to_comments user_id + +You need to select a user to have the internal notes be associated with, perhaps +the superuser, or one created just for this purpose? + +=cut + +use strict; +use warnings; + +use FixMyStreet::App; + +# Because it is not possible to determine the user that last edited the +# internal_notes we need require a user to assign all the comments to. +my $comment_user_id = $ARGV[0] + || die "Usage: $0 id_of_user_for_comments"; +my $comment_user = FixMyStreet::App # + ->model('DB::User') # + ->find($comment_user_id) + || die "Could not find user with id '$comment_user_id'"; + +# We use now as the time for the internal note. This is not the time it was +# actually created, but I don't think that can be extracted from the problem. +my $comment_timestamp = DateTime->now(); + +# The state of 'hidden' seems most appropriate for these internal_notes - as +# they should not be shown to the public. Certainly more suitable than +# 'unconfirmed' or 'confirmed'. +my $comment_state = 'hidden'; + +# Load all the comments, more reliable than trying to search on the contents of +# the extra field. +my $problems = FixMyStreet::App->model('DB::Problem')->search(); + +while ( my $problem = $problems->next() ) { + + my $problem_id = $problem->id; + + # Extract the bits we are interested in. May not exist, in which case + # skip on. + my $extra = $problem->extra || {}; + next unless exists $extra->{internal_notes}; + + # If there is something to save create a comment with the notes in them + if ( my $internal_notes = $extra->{internal_notes} ) { + print "Creating internal note comment for problem '$problem_id'\n"; + $problem->add_to_comments( + { + text => $internal_notes, + created => $comment_timestamp, + user => $comment_user, + state => $comment_state, + mark_fixed => 0, + anonymous => 1, + extra => { is_internal_note => 1 }, + } + ); + } + + # Remove the notes from extra and save back to the problem + delete $extra->{internal_notes}; + $problem->update({ extra => $extra }); +} + diff --git a/bin/zurich/geocode b/bin/zurich/geocode new file mode 100755 index 000000000..9482b27e6 --- /dev/null +++ b/bin/zurich/geocode @@ -0,0 +1,45 @@ +#!/usr/bin/perl + +=head1 NAME + +zurich/geocode - commandline tool to test the Zurich geocoder + +=head1 SYNOPSIS + + # Firstly: + ## copy the GEOCODER config from a current Zurich conf to your conf/general.yml + $ eval `perl setenv.pl` + + $ bin/zurich/geocode Magnus + + # ... output from geocoder + +This can be used to test the results of, e.g. + + https://www.zueriwieneu.ch/ajax/geocode?term=Magnus + +but without the caching which FixMyStreet applies, and passing on any 500 +errors from the server. + +=cut + +use strict; +use warnings; +require 5.8.0; + + +use Data::Dumper; +use feature 'say'; + +use FixMyStreet; +use FixMyStreet::App; +use FixMyStreet::Geocode::Zurich; + +# TODO use FixMyStreet::override_config to get data from conf/general.yml.zurich if available +my $geocoder = FixMyStreet->config('GEOCODER') + or die "No GEOCODER config -- please copy appropriate Zurich conf to conf/general.yml"; + +my $c = FixMyStreet::App->new(); +my $s = join ' ', @ARGV; + +say Dumper( FixMyStreet::Geocode::Zurich::string( $s, $c ) ); |