diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/fetch-comments | 3 | ||||
-rwxr-xr-x | bin/fetch-comments-24hs | 2 | ||||
-rwxr-xr-x | bin/fiksgatami/showroadinfo | 5 | ||||
-rwxr-xr-x | bin/fiksgatami/showroadstats | 5 | ||||
-rwxr-xr-x | bin/fixmystreet.com/populate_bing_cache | 4 | ||||
-rwxr-xr-x | bin/fixmystreet.com/update-send-questionnaire | 5 | ||||
-rwxr-xr-x | bin/handlemail | 206 | ||||
-rwxr-xr-x | bin/handlemail-support | 20 | ||||
-rwxr-xr-x | bin/open311-populate-service-list | 4 | ||||
-rwxr-xr-x | bin/open311-update-reports | 9 | ||||
-rwxr-xr-x | bin/problem-creation-graph | 4 | ||||
-rwxr-xr-x | bin/problems-filed-graph | 4 | ||||
-rwxr-xr-x | bin/send-alerts | 9 | ||||
-rwxr-xr-x | bin/send-comments | 43 | ||||
-rwxr-xr-x | bin/send-questionnaires | 11 | ||||
-rwxr-xr-x | bin/send-reports | 9 | ||||
-rw-r--r-- | bin/site-specific-install.sh | 2 | ||||
-rwxr-xr-x | bin/update-all-reports | 18 | ||||
-rwxr-xr-x | bin/update-schema | 14 | ||||
-rwxr-xr-x | bin/zerotb/import_clinic_list.pl | 14 | ||||
-rwxr-xr-x | bin/zurich/convert_internal_notes_to_comments | 8 | ||||
-rwxr-xr-x | bin/zurich/overdue-alert | 13 |
22 files changed, 271 insertions, 141 deletions
diff --git a/bin/fetch-comments b/bin/fetch-comments index 4eb9def14..55ba70d85 100755 --- a/bin/fetch-comments +++ b/bin/fetch-comments @@ -15,14 +15,11 @@ BEGIN { require "$d/../setenv.pl"; } -use FixMyStreet::App; use CronFns; my ($verbose, $nomail) = CronFns::options(); -use Open311; use Open311::GetServiceRequestUpdates; - my $updates = Open311::GetServiceRequestUpdates->new( verbose => $verbose ); $updates->fetch; diff --git a/bin/fetch-comments-24hs b/bin/fetch-comments-24hs index 27853bcc1..df208439e 100755 --- a/bin/fetch-comments-24hs +++ b/bin/fetch-comments-24hs @@ -19,11 +19,9 @@ BEGIN { use DateTime; use DateTime::Format::W3CDTF; -use FixMyStreet::App; use CronFns; my ($verbose, $nomail) = CronFns::options(); -use Open311; use Open311::GetServiceRequestUpdates; my $dt = DateTime->now(); diff --git a/bin/fiksgatami/showroadinfo b/bin/fiksgatami/showroadinfo index 658fca01c..fda6fbb6b 100755 --- a/bin/fiksgatami/showroadinfo +++ b/bin/fiksgatami/showroadinfo @@ -3,11 +3,12 @@ use strict; use warnings; -use FixMyStreet::App; +use FixMyStreet::Cobrand; +use FixMyStreet::DB; use FixMyStreet::Geocode::OSM; use Data::Dumper; -FixMyStreet::App->model('DB::Problem')->send_reports(); +FixMyStreet::DB->resultset('Problem')->send_reports(); my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('fiksgatami')->new(); diff --git a/bin/fiksgatami/showroadstats b/bin/fiksgatami/showroadstats index 83c3c4310..9bc8de70b 100755 --- a/bin/fiksgatami/showroadstats +++ b/bin/fiksgatami/showroadstats @@ -3,10 +3,11 @@ use strict; use warnings; -use FixMyStreet::App; +use FixMyStreet::Cobrand; +use FixMyStreet::DB; use FixMyStreet::Geocode::OSM; -my @reports = FixMyStreet::App->model('DB::Problem')->search({ +my @reports = FixMyStreet::DB->resultset('Problem')->search({ state => [ FixMyStreet::DB::Result::Problem->visible_states() ], }, { rows => 40, diff --git a/bin/fixmystreet.com/populate_bing_cache b/bin/fixmystreet.com/populate_bing_cache index 17c8911d0..c644b34fa 100755 --- a/bin/fixmystreet.com/populate_bing_cache +++ b/bin/fixmystreet.com/populate_bing_cache @@ -6,12 +6,12 @@ require 5.8.0; use Data::Dumper; -use FixMyStreet::App; +use FixMyStreet::DB; use FixMyStreet::Geocode::Bing; my $bing_culture = 'en-GB'; -my $reports = FixMyStreet::App->model('DB::Problem')->search( +my $reports = FixMyStreet::DB->resultset('Problem')->search( { geocode => undef, confirmed => { '!=', undef }, diff --git a/bin/fixmystreet.com/update-send-questionnaire b/bin/fixmystreet.com/update-send-questionnaire index 7a231b919..40549c6e4 100755 --- a/bin/fixmystreet.com/update-send-questionnaire +++ b/bin/fixmystreet.com/update-send-questionnaire @@ -10,7 +10,8 @@ reports in cobrands that don't send questionnaires at all. use strict; use warnings; -use FixMyStreet::App; +use FixMyStreet::Cobrand; +use FixMyStreet::DB; my @cobrands; foreach my $cobrand ( FixMyStreet::Cobrand->available_cobrand_classes() ) { @@ -19,7 +20,7 @@ foreach my $cobrand ( FixMyStreet::Cobrand->available_cobrand_classes() ) { push @cobrands, $cls->moniker if !$cls->send_questionnaires(); } -my $problems = FixMyStreet::App->model('DB::Problem')->search({ +my $problems = FixMyStreet::DB->resultset('Problem')->search({ cobrand => \@cobrands, send_questionnaire => 1, }); diff --git a/bin/handlemail b/bin/handlemail index 5d4ac753c..e91a8a3a0 100755 --- a/bin/handlemail +++ b/bin/handlemail @@ -3,68 +3,192 @@ # handlemail: # Handle an individual incoming mail message. # -# This script should be invoked through the .forward mechanism. It processes -# replies to non-reply emails and auto-replies accordingly. Could deal with -# bounces at some point too. +# This script should be invoked through the .forward mechanism. It +# processes bounce messages and replies and deals with them accordingly. # -# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. -# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ -# - -my $rcsid = ''; $rcsid .= '$Id: handlemail,v 1.2 2009-02-11 11:04:48 matthew Exp $'; +# Copyright (c) 2016 UK Citizens Online Democracy. All rights reserved. use strict; use warnings; require 5.8.0; -# Horrible boilerplate to set up appropriate library paths. -use FindBin; -use lib "$FindBin::Bin/../perllib"; -use lib "$FindBin::Bin/../commonlib/perllib"; - -use mySociety::Config; BEGIN { - mySociety::Config::set_file("$FindBin::Bin/../conf/general"); + 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::Email; use mySociety::Email; use mySociety::EmailUtil; use mySociety::HandleMail; -use mySociety::SystemMisc; +use mySociety::SystemMisc qw(print_log); # Don't print diagnostics to standard error, as this can result in bounce # messages being generated (only in response to non-bounce input, obviously). mySociety::SystemMisc::log_to_stderr(0); my %data = mySociety::HandleMail::get_message(); +my @lines = @{$data{lines}}; +my $token = get_envelope_token(); +my $verp = $token !~ /DO-NOT-REPLY/i; +my ($type, $object) = get_object_from_token(); if ($data{is_bounce_message}) { - #my $a = mySociety::HandleMail::get_bounce_recipient($data{message}); - #my $token = mySociety::HandleMail::get_token($a, - # 'fms-', mySociety::Config::get('EMAILDOMAIN') - #); - #exit(0) if $token eq 'DO-NOT-REPLY'; # A bounce we don't care about - exit(0); # drop all other bounces currently + if ($object) { + handle_bounce_to_verp_address(); + } else { + print_log('info', "bounce received for don't-care email"); + } +} else { + # This is not a bounce message. If it's to a VERP address, pass it on to + # the message sender; otherwise send an auto-reply + if ($object) { + handle_non_bounce_to_verp_address(); + } else { + handle_non_bounce_to_null_address(); + } } -# Not a bounce, send an automatic response -my $template = 'reply-autoresponse'; -open FP, "$FindBin::Bin/../templates/email/default/$template" or exit 75; -$template = join('', <FP>); -close FP; - -# We generate this as a bounce. -my $mail = mySociety::Email::construct_email({ - From => [ mySociety::Config::get('CONTACT_EMAIL'), 'FixMyStreet' ], - To => $data{return_path}, - _template_ => $template, - _parameters_ => { }, - _line_indent => '', -}); - -if (mySociety::EmailUtil::EMAIL_SUCCESS - != mySociety::EmailUtil::send_email($mail, '<>', $data{return_path})) { - exit(75); +exit(0); + +# --- + +sub get_envelope_token { + my $m = $data{message}; + + # If we have a special suffix header for the local part suffix, use that. + # This is set by our exim so we have access to it through the domain name + # forwarding and routers. + my $suffix = $m->head()->get("X-Delivered-Suffix"); + if ($suffix) { + chomp $suffix; + return substr($suffix, 1); + } + + # Otherwise, fall back to To header + my $a = mySociety::HandleMail::get_bounce_recipient($m); + + my $token = mySociety::HandleMail::get_token($a, + 'fms-', FixMyStreet->config('EMAIL_DOMAIN') + ); + exit 0 unless $token; # Don't care unless we have a token + + return $token; } -exit(0); +sub get_object_from_token { + return unless $verp; + + my ($type, $id) = FixMyStreet::Email::check_verp_token($token); + exit 0 unless $type; + + my $rs; + if ($type eq 'report') { + $rs = FixMyStreet::DB->resultset('Problem'); + } elsif ($type eq 'alert') { + $rs = FixMyStreet::DB->resultset('Alert'); + } + + my $object = $rs->find({ id => $id }); + exit(0) unless $object; + + return ($type, $object); +} +sub handle_permanent_bounce { + if ($type eq 'alert') { + print_log('info', "Received bounce for alert " . $object->id . ", unsubscribing"); + $object->disable(); + } elsif ($type eq 'report') { + print_log('info', "Received bounce for report " . $object->id . ", forwarding to support"); + forward_on_to(FixMyStreet->config('CONTACT_EMAIL')); + } +} + +sub is_out_of_office { + my (%attributes) = @_; + return 1 if $attributes{problem} && $attributes{problem} == mySociety::HandleMail::ERR_OUT_OF_OFFICE; + my $subject = $data{message}->head()->get("Subject"); + return 1 if $subject =~ /Auto(matic|mated)?[ -]?(reply|response|responder)|Thank you for (your email|contacting)|Thank_you_for_your_email|Out of Office|This office is closed until|^Re: (Problem Report|New updates)|^Auto: |^E-Mail Response$|^Message Received:|have received your email|Acknowledgement of your email/i; + return 0; +} + +sub handle_bounce_to_verp_address { + my %attributes = mySociety::HandleMail::parse_bounce(\@lines); + my $info = ''; + if ($attributes{is_dsn}) { + # If permanent failure, but not mailbox full + return handle_permanent_bounce() if $attributes{status} =~ /^5\./ && $attributes{status} ne '5.2.2'; + $info = ", Status $attributes{status}"; + } elsif ($attributes{problem}) { + my $err_type = mySociety::HandleMail::error_type($attributes{problem}); + return handle_permanent_bounce() if $err_type == mySociety::HandleMail::ERR_TYPE_PERMANENT; + $info = ", Bounce type $attributes{problem}"; + } + + # Check if the Subject looks like an auto-reply rather than a delivery bounce. + # If so, treat as if it were a normal email + if (is_out_of_office(%attributes)) { + print_log('info', "Treating bounce for $type " . $object->id . " as auto-reply to sender"); + handle_non_bounce_to_verp_address(); + } elsif (!$info) { + print_log('info', "Unparsed bounce received for $type " . $object->id . ", forwarding to support"); + forward_on_to(FixMyStreet->config('CONTACT_EMAIL')); + } else { + print_log('info', "Ignoring bounce received for $type " . $object->id . $info); + } +} + +sub handle_non_bounce_to_verp_address { + if ($type eq 'alert' && !is_out_of_office()) { + print_log('info', "Received non-bounce for alert " . $object->id . ", forwarding to support"); + forward_on_to(FixMyStreet->config('CONTACT_EMAIL')); + } elsif ($type eq 'report') { + print_log('info', "Received non-bounce for report " . $object->id . ", forwarding to report creator"); + forward_on_to($object->user->email); + } +} + +sub handle_non_bounce_to_null_address { + # Don't send a reply to out of office replies... + if (is_out_of_office()) { + print_log('info', "Received non-bounce auto-reply to null address, ignoring"); + return; + } + + # Send an automatic response + print_log('info', "Received non-bounce to null address, auto-replying"); + my $template = 'reply-autoresponse'; + my $fp = FixMyStreet->path_to("templates", "email", "default", $template)->open or exit 75; + $template = join('', <$fp>); + $fp->close; + + # We generate this as a bounce. + my $mail = mySociety::Email::construct_email({ + From => [ FixMyStreet->config('CONTACT_EMAIL'), 'FixMyStreet' ], + To => $data{return_path}, + _template_ => $template, + _parameters_ => { }, + _line_indent => '', + }); + send_mail($mail, '<>', $data{return_path}); +} + +sub forward_on_to { + my $recipient = shift; + my $text = join("\n", @lines) . "\n"; + my $sender = $data{return_path} || '<>'; + send_mail($text, $sender, $recipient); +} + +sub send_mail { + my ($text, $sender, $recipient) = @_; + if (mySociety::EmailUtil::EMAIL_SUCCESS + != mySociety::EmailUtil::send_email($text, $sender, $recipient)) { + exit(75); + } +} diff --git a/bin/handlemail-support b/bin/handlemail-support index 9808e447a..0ccde8ca7 100755 --- a/bin/handlemail-support +++ b/bin/handlemail-support @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl # # handlemail-support: # Handle an individual incoming mail message. @@ -11,17 +11,17 @@ # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ use strict; +use warnings; require 5.8.0; -# Horrible boilerplate to set up appropriate library paths. -use FindBin; -use lib "$FindBin::Bin/../perllib"; -use lib "$FindBin::Bin/../commonlib/perllib"; - -use mySociety::Config; BEGIN { - mySociety::Config::set_file("$FindBin::Bin/../conf/general"); + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; } + +use FixMyStreet; use mySociety::EmailUtil; use mySociety::HandleMail; @@ -32,7 +32,7 @@ forward_on(); # --- sub forward_on { - my ($l, $d) = split /\@/, mySociety::Config::get('CONTACT_EMAIL'); + my ($l, $d) = split /\@/, FixMyStreet->config('CONTACT_EMAIL'); if (mySociety::EmailUtil::EMAIL_SUCCESS != mySociety::EmailUtil::send_email( join("\n", @{$data{lines}}) . "\n", @@ -50,7 +50,7 @@ sub is_ignorable { my ($from, $subject, $body) = ($head->get('From'), $head->get('Subject'), $m->body); $body = join("\n", @$body); - open my $fp, "$FindBin::Bin/../../data/ignored-emails.csv" or exit 75; + my $fp = FixMyStreet->path_to("..", "data", "ignored-emails.csv")->open or exit 75; while (<$fp>) { chomp; my ($f, $s, $b) = split /,/; diff --git a/bin/open311-populate-service-list b/bin/open311-populate-service-list index 11f9005a5..211061258 100755 --- a/bin/open311-populate-service-list +++ b/bin/open311-populate-service-list @@ -10,7 +10,7 @@ BEGIN { require "$d/../setenv.pl"; } -use FixMyStreet::App; +use FixMyStreet::DB; use Open311::PopulateServiceList; use Getopt::Long::Descriptive; @@ -22,7 +22,7 @@ my ($opt, $usage) = describe_options( ); print($usage->text), exit if $opt->help; -my $bodies = FixMyStreet::App->model('DB::Body')->search( { +my $bodies = FixMyStreet::DB->resultset('Body')->search( { id => { '!=', 2237 }, # XXX Until Oxfordshire does do so send_method => 'Open311' } ); diff --git a/bin/open311-update-reports b/bin/open311-update-reports index 6a1c894d7..378f8e8bc 100755 --- a/bin/open311-update-reports +++ b/bin/open311-update-reports @@ -17,17 +17,18 @@ BEGIN { } use Open311::GetUpdates; -use FixMyStreet::App; +use FixMyStreet; +use FixMyStreet::DB; # FIXME - make this configurable and/or better -my $system_user = FixMyStreet::App->model('DB::User')->find_or_create( +my $system_user = FixMyStreet::DB->resultset('User')->find_or_create( { - email => FixMyStreet::App->config->{'CONTACT_EMAIL'}, + email => FixMyStreet->config('CONTACT_EMAIL'), name => 'System User', } ); -my $body_list = FixMyStreet::App->model('DB::Body'); +my $body_list = FixMyStreet::DB->resultset('Body'); my $update = Open311::GetUpdates->new( body_list => $body_list, diff --git a/bin/problem-creation-graph b/bin/problem-creation-graph index 3e46777f4..a8554058a 100755 --- a/bin/problem-creation-graph +++ b/bin/problem-creation-graph @@ -20,7 +20,7 @@ BEGIN { use File::Temp qw(tempfile); -use FixMyStreet::App; +use FixMyStreet::DB; my %config = ( gplot_output => "set terminal png font 'Vera.ttf' 9 size 1200,400", @@ -43,7 +43,7 @@ sub grab_data { my ($fh, $filename) = tempfile("fms-creation-rate-graph-data-XXXXXXXXXX", UNLINK => 1); $sources{$type} = $filename; - my @entries = FixMyStreet::App->model('DB::Problem')->search( + my @entries = FixMyStreet::DB->resultset('Problem')->search( $selection, { columns => [ { 'date' => { date => 'created' } }, diff --git a/bin/problems-filed-graph b/bin/problems-filed-graph index a930e4346..950797ebe 100755 --- a/bin/problems-filed-graph +++ b/bin/problems-filed-graph @@ -20,7 +20,7 @@ BEGIN { use File::Temp qw(tempfile); -use FixMyStreet::App; +use FixMyStreet::DB; my %config = ( gplot_output => "set terminal png font 'Vera.ttf' 9 size 1200,600", @@ -29,7 +29,7 @@ my %config = ( my ($fh, $source) = tempfile("fms-report-rate-graph-data-nonwmc-XXXXXXXXXX", UNLINK => 1); -my @entries = FixMyStreet::App->model('DB::Problem')->search({ +my @entries = FixMyStreet::DB->resultset('Problem')->search({ state => { -not_in => [ 'unconfirmed', 'hidden', 'partial' ] }, }, { columns => [ diff --git a/bin/send-alerts b/bin/send-alerts index 94f7d5509..5c8a5412c 100755 --- a/bin/send-alerts +++ b/bin/send-alerts @@ -17,14 +17,13 @@ BEGIN { require "$d/../setenv.pl"; } -use CGI; # XXX use CronFns; -use mySociety::Config; -use FixMyStreet::App; +use FixMyStreet; +use FixMyStreet::Script::Alerts; -my $site = CronFns::site(mySociety::Config::get('BASE_URL')); +my $site = CronFns::site(FixMyStreet->config('BASE_URL')); CronFns::language($site); -FixMyStreet::App->model('DB::AlertType')->email_alerts(); +FixMyStreet::Script::Alerts::send(); diff --git a/bin/send-comments b/bin/send-comments index fbbd57891..7363d7a0d 100755 --- a/bin/send-comments +++ b/bin/send-comments @@ -20,15 +20,12 @@ BEGIN { require "$d/../setenv.pl"; } -use Digest::MD5; -use Encode; use CronFns; -use FixMyStreet::App; - -use Utils; -use mySociety::Config; - +use DateTime; +use FixMyStreet; +use FixMyStreet::Cobrand; +use FixMyStreet::DB; use Open311; # send_method config values found in by-area config data, for selecting to appropriate method @@ -36,25 +33,33 @@ use constant SEND_METHOD_EMAIL => 'email'; use constant SEND_METHOD_OPEN311 => 'Open311'; use constant COUNCIL_ID_OXFORDSHIRE => 2237; +use constant COUNCIL_ID_BROMLEY => 2482; +use constant COUNCIL_ID_LEWISHAM => 2492; # Set up site, language etc. my ($verbose, $nomail) = CronFns::options(); -my $base_url = mySociety::Config::get('BASE_URL'); -my $site = CronFns::site($base_url); +my $base_url = FixMyStreet->config('BASE_URL'); +my $site = ''; +$site = 'fixmystreet.com' if $base_url eq "https://www.fixmystreet.com"; -my $bodies = FixMyStreet::App->model('DB::Body')->search( { +my $bodies = FixMyStreet::DB->resultset('Body')->search( { send_method => SEND_METHOD_OPEN311, send_comments => 1, } ); while ( my $body = $bodies->next ) { - # Oxfordshire (OCC) is special: - # we do *receive* service_request_updates (aka comments) for OCC, but we never *send* them, so skip this pass - next if $body->areas->{+COUNCIL_ID_OXFORDSHIRE}; + # XXX Cobrand specific + if ($site eq 'fixmystreet.com') { + # Oxfordshire (OCC) is special: + # we do *receive* service_request_updates (aka comments) for OCC, but we never *send* them, so skip this pass + next if $body->areas->{+COUNCIL_ID_OXFORDSHIRE}; + # Lewisham does not yet accept updates + next if $body->areas->{+COUNCIL_ID_LEWISHAM}; + } my $use_extended = 0; - my $comments = FixMyStreet::App->model('DB::Comment')->search( { + my $comments = FixMyStreet::DB->resultset('Comment')->search( { 'me.whensent' => undef, 'me.external_id' => undef, 'me.state' => 'confirmed', @@ -69,7 +74,7 @@ while ( my $body = $bodies->next ) { } ); - if ( $body->areas->{2482} ) { + if ( $site eq 'fixmystreet.com' && $body->areas->{+COUNCIL_ID_BROMLEY} ) { $use_extended = 1; } @@ -87,7 +92,7 @@ while ( my $body = $bodies->next ) { my $o = Open311->new( %open311_conf ); - if ( $body->areas->{2482} ) { + if ( $site eq 'fixmystreet.com' && $body->areas->{+COUNCIL_ID_BROMLEY} ) { my $endpoints = $o->endpoints; $endpoints->{update} = 'update.xml'; $endpoints->{service_request_updates} = 'update.xml'; @@ -110,10 +115,10 @@ while ( my $body = $bodies->next ) { } if ( $comment->send_fail_count ) { - next if bromley_retry_timeout( $comment ); + next if retry_timeout( $comment ); } - if ( $body->areas->{2482} ) { + if ( $site eq 'fixmystreet.com' && $body->areas->{+COUNCIL_ID_BROMLEY} ) { my $extra = $comment->extra; if ( !$extra ) { $extra = {}; @@ -142,7 +147,7 @@ while ( my $body = $bodies->next ) { } } -sub bromley_retry_timeout { +sub retry_timeout { my $row = shift; my $tz = FixMyStreet->local_time_zone; diff --git a/bin/send-questionnaires b/bin/send-questionnaires index 93d58ed77..85eef810c 100755 --- a/bin/send-questionnaires +++ b/bin/send-questionnaires @@ -17,17 +17,14 @@ BEGIN { require "$d/../setenv.pl"; } -use CGI; # XXX Awkward kludge -use Encode; use CronFns; - -use FixMyStreet::App; -use mySociety::Config; +use FixMyStreet; +use FixMyStreet::Script::Questionnaires; my %params; ( $params{verbose}, $params{nomail} ) = CronFns::options(); -$params{site} = CronFns::site(mySociety::Config::get('BASE_URL')); +$params{site} = CronFns::site(FixMyStreet->config('BASE_URL')); CronFns::language($params{site}); -FixMyStreet::App->model('DB::Questionnaire')->send_questionnaires( \%params ); +FixMyStreet::Script::Questionnaires::send( \%params ); diff --git a/bin/send-reports b/bin/send-reports index 3c6f26cdb..81be691e7 100755 --- a/bin/send-reports +++ b/bin/send-reports @@ -17,13 +17,12 @@ BEGIN { require "$d/../setenv.pl"; } -use CGI; # XXX use CronFns; -use mySociety::Config; -use FixMyStreet::App; +use FixMyStreet; +use FixMyStreet::Script::Reports; -my $site = CronFns::site(mySociety::Config::get('BASE_URL')); +my $site = CronFns::site(FixMyStreet->config('BASE_URL')); CronFns::language($site); -FixMyStreet::App->model('DB::Problem')->send_reports(); +FixMyStreet::Script::Reports::send(); diff --git a/bin/site-specific-install.sh b/bin/site-specific-install.sh index 4c39a1bd7..d20a15ea2 100644 --- a/bin/site-specific-install.sh +++ b/bin/site-specific-install.sh @@ -1,7 +1,7 @@ #!/bin/sh # Set this to the version we want to check out -VERSION=${VERSION_OVERRIDE:-v1.7} +VERSION=${VERSION_OVERRIDE:-v1.8.1} PARENT_SCRIPT_URL=https://github.com/mysociety/commonlib/blob/master/bin/install-site.sh diff --git a/bin/update-all-reports b/bin/update-all-reports index 0627cedc2..d951756e4 100755 --- a/bin/update-all-reports +++ b/bin/update-all-reports @@ -17,10 +17,12 @@ BEGIN { require "$d/../setenv.pl"; } -use FixMyStreet::App; +use FixMyStreet; +use FixMyStreet::DB; + use File::Path (); use File::Slurp; -use JSON; +use JSON::MaybeXS; use List::MoreUtils qw(zip); my $fourweeks = 4*7*24*60*60; @@ -32,13 +34,13 @@ if ( FixMyStreet->config('BASE_URL') =~ /zurich|zueri/ ) { $age_column = 'created'; } -my $problems = FixMyStreet::App->model("DB::Problem")->search( +my $problems = FixMyStreet::DB->resultset('Problem')->search( { state => [ FixMyStreet::DB::Result::Problem->visible_states() ], }, { columns => [ - 'id', 'bodies_str', 'state', 'areas', + 'id', 'bodies_str', 'state', 'areas', 'cobrand', { duration => { extract => "epoch from current_timestamp-lastupdate" } }, { age => { extract => "epoch from current_timestamp-$age_column" } }, ] @@ -47,10 +49,12 @@ my $problems = FixMyStreet::App->model("DB::Problem")->search( $problems = $problems->cursor; # Raw DB cursor for speed my ( %fixed, %open ); -my @cols = ( 'id', 'bodies_str', 'state', 'areas', 'duration', 'age' ); +my @cols = ( 'id', 'bodies_str', 'state', 'areas', 'cobrand', 'duration', 'age' ); while ( my @problem = $problems->next ) { my %problem = zip @cols, @problem; my @bodies; + my $cobrand = $problem{cobrand}; + if ( !$problem{bodies_str} ) { # Problem was not sent to any bodies, add to all areas @bodies = grep { $_ } split( /,/, $problem{areas} ); @@ -68,9 +72,11 @@ while ( my @problem = $problems->next ) { if (FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}} || FixMyStreet::DB::Result::Problem->closed_states()->{$problem{state}}) { # Fixed problems are either old or new $fixed{$body}{$duration_str}++; + $fixed{$cobrand}{$body}{$duration_str}++; } else { # Open problems are either unknown, older, or new $open{$body}{$type}++; + $open{$cobrand}{$body}{$type}++; } } } @@ -83,7 +89,7 @@ if ( FixMyStreet->config('BASE_URL') =~ /emptyhomes/ ) { } } -my $body = JSON->new->utf8(1)->encode( { +my $body = encode_json( { fixed => \%fixed, open => \%open, } ); diff --git a/bin/update-schema b/bin/update-schema index 1af08b002..1393178f8 100755 --- a/bin/update-schema +++ b/bin/update-schema @@ -39,20 +39,19 @@ BEGIN { require "$bin_dir/../setenv.pl"; } -use mySociety::Config; +use FixMyStreet; use mySociety::DBHandle qw(dbh); use mySociety::MaPit; use Getopt::Long; use Pod::Usage; -mySociety::Config::set_file("$bin_dir/../conf/general"); my %args = ( - Name => mySociety::Config::get('FMS_DB_NAME'), - User => mySociety::Config::get('FMS_DB_USER'), - Password => mySociety::Config::get('FMS_DB_PASS'), + Name => FixMyStreet->config('FMS_DB_NAME'), + User => FixMyStreet->config('FMS_DB_USER'), + Password => FixMyStreet->config('FMS_DB_PASS'), ); -$args{Host} = mySociety::Config::get('FMS_DB_HOST', undef) if mySociety::Config::get('FMS_DB_HOST'); -$args{Port} = mySociety::Config::get('FMS_DB_PORT', undef) if mySociety::Config::get('FMS_DB_PORT'); +$args{Host} = FixMyStreet->config('FMS_DB_HOST', undef) if FixMyStreet->config('FMS_DB_HOST'); +$args{Port} = FixMyStreet->config('FMS_DB_PORT', undef) if FixMyStreet->config('FMS_DB_PORT'); mySociety::DBHandle::configure( %args ); my ($commit, $version, $downgrade, $help); @@ -195,6 +194,7 @@ else { # By querying the database schema, we can see where we're currently at # (assuming schema change files are never half-applied, which should be the case) sub get_db_version { + return '0039' if column_exists('users', 'facebook_id'); return '0038' if column_exists('admin_log', 'time_spent'); return '0037' if table_exists('response_templates'); return '0036' if constraint_contains('problem_cobrand_check', 'a-z0-9_'); diff --git a/bin/zerotb/import_clinic_list.pl b/bin/zerotb/import_clinic_list.pl index 359a63925..f7bdbc092 100755 --- a/bin/zerotb/import_clinic_list.pl +++ b/bin/zerotb/import_clinic_list.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl use strict; -use FixMyStreet::App; +use FixMyStreet::DB; use Text::CSV; use Getopt::Long::Descriptive; @@ -23,7 +23,7 @@ my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attribute. or die "Cannot use CSV: ".Text::CSV->error_diag (); open my $fh, "<:encoding(utf8)", $opt->file or die "Failed to open " . $opt->file . ": $!"; -my $clinic_user = FixMyStreet::App->model('DB::User')->find_or_create({ +my $clinic_user = FixMyStreet::DB->resultset('User')->find_or_create({ email => $opt->email }); if ( not $clinic_user->in_storage ) { @@ -34,7 +34,7 @@ if ( not $clinic_user->in_storage ) { my $title_row = $csv->getline( $fh ); while ( my $row = $csv->getline( $fh ) ) { - my $clinics = FixMyStreet::App->model('DB::Problem')->search({ + my $clinics = FixMyStreet::DB->resultset('Problem')->search({ title => $row->[TITLE] }); @@ -42,7 +42,7 @@ while ( my $row = $csv->getline( $fh ) ) { my $p; my $count = $clinics->count; if ( $count == 0 ) { - $p = FixMyStreet::App->model('DB::Problem')->create({ + $p = FixMyStreet::DB->resultset('Problem')->create({ title => $row->[TITLE], latitude => $lat, longitude => $long, @@ -76,14 +76,14 @@ while ( my $row = $csv->getline( $fh ) ) { $p->discard_changes; # disabling existing alerts in case email addresses have changed - my $existing = FixMyStreet::App->model('DB::Alert')->search({ + my $existing = FixMyStreet::DB->resultset('Alert')->search({ alert_type => 'new_updates', parameter => $p->id }); $existing->update( { confirmed => 0 } ); if ( $row->[EMAIL] ) { - my $u = FixMyStreet::App->model('DB::User')->find_or_new({ + my $u = FixMyStreet::DB->resultset('User')->find_or_new({ email => $row->[EMAIL] }); $u->insert unless $u->in_storage; @@ -95,7 +95,7 @@ while ( my $row = $csv->getline( $fh ) ) { sub create_update_alert { my ( $user, $p, $verbose ) = @_; - my $a = FixMyStreet::App->model('DB::Alert')->find_or_new({ + my $a = FixMyStreet::DB->resultset('Alert')->find_or_new({ alert_type => 'new_updates', user => $user, parameter => $p->id, diff --git a/bin/zurich/convert_internal_notes_to_comments b/bin/zurich/convert_internal_notes_to_comments index ddf74851f..76db0a45b 100755 --- a/bin/zurich/convert_internal_notes_to_comments +++ b/bin/zurich/convert_internal_notes_to_comments @@ -17,15 +17,13 @@ the superuser, or one created just for this purpose? use strict; use warnings; -use FixMyStreet::App; +use FixMyStreet::DB; # 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) +my $comment_user = FixMyStreet::DB->resultset('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 @@ -39,7 +37,7 @@ 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(); +my $problems = FixMyStreet::DB->resultset('Problem')->search(); while ( my $problem = $problems->next() ) { diff --git a/bin/zurich/overdue-alert b/bin/zurich/overdue-alert index 700a642f4..0473208c5 100755 --- a/bin/zurich/overdue-alert +++ b/bin/zurich/overdue-alert @@ -19,7 +19,9 @@ BEGIN { use DateTime; use CronFns; -use FixMyStreet::App; +use FixMyStreet::Cobrand; +use FixMyStreet::DB; +use FixMyStreet::Email; my ($verbose, $nomail) = CronFns::options(); @@ -28,7 +30,7 @@ my $now = DateTime->now(); exit if FixMyStreet::Cobrand::Zurich::is_public_holiday($now) or FixMyStreet::Cobrand::Zurich::is_weekend($now); my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('zurich')->new(); -my %bodies = map { $_->id => $_ } FixMyStreet::App->model("DB::Body")->all; +my %bodies = map { $_->id => $_ } FixMyStreet::DB->resultset("Body")->all; loop_through( 'alert-moderation-overdue.txt', 0, 1, [ 'unconfirmed' ] ); loop_through( 'alert-overdue.txt', 1, 6, 'in progress' ); @@ -36,10 +38,10 @@ loop_through( 'alert-overdue.txt', 0, 6, ['confirmed', 'planned'] ); sub loop_through { my ( $template, $include_parent, $days, $states ) = @_; - my $dtf = FixMyStreet::App->model("DB")->storage->datetime_parser; + my $dtf = FixMyStreet::DB->storage->datetime_parser; my $date_threshold = $dtf->format_datetime(FixMyStreet::Cobrand::Zurich::sub_days( $now, $days )); - my $reports = FixMyStreet::App->model("DB::Problem")->search( { + my $reports = FixMyStreet::DB->resultset("Problem")->search( { state => $states, created => { '<', $date_threshold }, bodies_str => { '!=', undef }, @@ -76,7 +78,8 @@ sub send_alert { push @$to, [ $parent_email, $parent->name ]; } - FixMyStreet::App->send_email_cron( + FixMyStreet::Email::send_cron( + FixMyStreet::DB->storage->schema, { _template_ => $template, _parameters_ => $h, |