diff options
Diffstat (limited to 'bin/zurich')
-rwxr-xr-x | bin/zurich/geocode | 45 | ||||
-rwxr-xr-x | bin/zurich/overdue-alert | 83 |
2 files changed, 83 insertions, 45 deletions
diff --git a/bin/zurich/geocode b/bin/zurich/geocode deleted file mode 100755 index 9482b27e6..000000000 --- a/bin/zurich/geocode +++ /dev/null @@ -1,45 +0,0 @@ -#!/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 ) ); diff --git a/bin/zurich/overdue-alert b/bin/zurich/overdue-alert new file mode 100755 index 000000000..fd9c26cb9 --- /dev/null +++ b/bin/zurich/overdue-alert @@ -0,0 +1,83 @@ +#!/usr/bin/env perl + +# zurich/overdue-alert: +# Send email alerts to administrators for overdue admin activities. +# +# Copyright (c) 2012 UK Citizens Online Democracy. All rights reserved. +# Email: matthew@mysociety.org. WWW: http://www.mysociety.org + +use strict; +use warnings; +require 5.8.0; + +use DateTime; +use CronFns; +use FixMyStreet::App; + +my ($verbose, $nomail) = CronFns::options(); + +# Only run on working days +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; + +loop_through( 'alert-moderation-overdue.txt', 0, 1, [ 'unconfirmed' ] ); +loop_through( 'alert-overdue.txt', 1, 6, 'in progress' ); +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 $date_threshold = $dtf->format_datetime(FixMyStreet::Cobrand::Zurich::sub_days( $now, $days )); + + my $reports = FixMyStreet::App->model("DB::Problem")->search( { + state => $states, + created => { '<', $date_threshold }, + bodies_str => { '!=', undef }, + } ); + + my %to_send = (); + while (my $row = $reports->next) { + $to_send{$row->bodies_str} .= '* ' . $row->id . ": '" . $row->title . "'\n\n"; + } + + my $template_path = FixMyStreet->path_to( "templates", "email", "zurich", $template )->stringify; + $template = Utils::read_file( $template_path ); + + foreach my $body_id (keys %to_send) { + send_alert( $template, $body_id, $to_send{$body_id}, $include_parent ); + } +} + +sub send_alert { + my ( $template, $body_id, $data, $include_parent ) = @_; + + my $body = $bodies{$body_id}; + my $body_email = $body->endpoint; + + my $h = { + data => $data, + admin_url => $cobrand->admin_base_url, + }; + + my $to = [ [ $body_email, $body->name ] ]; + if ( $include_parent ) { + my $parent = $body->parent; + my $parent_email = $parent->endpoint; + push @$to, [ $parent_email, $parent->name ]; + } + + FixMyStreet::App->send_email_cron( + { + _template_ => $template, + _parameters_ => $h, + To => $to, + From => [ FixMyStreet->config('CONTACT_EMAIL'), FixMyStreet->config('CONTACT_NAME') ], + }, + FixMyStreet->config('CONTACT_EMAIL'), + $nomail + ); +} + |