diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/View/Web.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/EmptyHomes.pm | 405 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Oxfordshire.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 58 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/EmptyHomes.pm | 9 |
7 files changed, 477 insertions, 19 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 687e54fbe..788e57be0 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -598,7 +598,6 @@ sub setup_categories_and_bodies : Private { # variables to populate my %bodies_to_list = (); # Bodies with categories assigned my @category_options = (); # categories to show - my $category_label = undef; # what to call them my %category_extras = (); # extra fields to fill in for open311 my %non_public_categories = (); # categories for which the reports are not public @@ -621,7 +620,6 @@ sub setup_categories_and_bodies : Private { _('Empty pub or bar'), _('Empty public building - school, hospital, etc.') ); - $category_label = _('Property type:'); } elsif ($first_area->{id} != COUNCIL_ID_BROMLEY && $first_area->{type} eq 'LBO') { @@ -636,7 +634,6 @@ sub setup_categories_and_bodies : Private { _('-- Pick a category --'), @local_categories ); - $category_label = _('Category'); } else { @@ -663,7 +660,6 @@ sub setup_categories_and_bodies : Private { # If there's an Other category present, put it at the bottom @category_options = ( _('-- Pick a category --'), grep { $_ ne _('Other') } @category_options ); push @category_options, _('Other') if $seen{_('Other')}; - $category_label = _('Category'); } } @@ -671,7 +667,6 @@ sub setup_categories_and_bodies : Private { $c->stash->{bodies} = \%bodies; $c->stash->{all_body_names} = [ map { $_->name } values %bodies ]; $c->stash->{bodies_to_list} = [ keys %bodies_to_list ]; - $c->stash->{category_label} = $category_label; $c->stash->{category_options} = \@category_options; $c->stash->{category_extras} = \%category_extras; $c->stash->{non_public_categories} = \%non_public_categories; @@ -838,6 +833,12 @@ sub process_report : Private { $bodies = join( ',', @{ $c->stash->{bodies_to_list} } ) || -1; $report->bodies_str( $bodies ); + my %extra; + $c->cobrand->process_extras( $c, undef, \%extra ); + if ( %extra ) { + $report->extra( \%extra ); + } + } elsif ( $first_area->{id} == COUNCIL_ID_BARNET ) { unless ( exists Utils::barnet_categories()->{ $report->category } ) { diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index febeaf3c1..8d3775ddc 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -121,10 +121,16 @@ sub add_links { $text =~ s/\r//g; $text = ent($text); - $text =~ s{(https?://[^\s]+)}{<a href="$1">$1</a>}g; + $text =~ s{(https?://)([^\s]+)}{"<a href='$1$2'>$1" . _space_slash($2) . '</a>'}ge; return $text; } +sub _space_slash { + my $t = shift; + $t =~ s{/(?!$)}{/ }g; + return $t; +} + =head2 escape_js Used to escape strings that are going to be put inside JavaScript. diff --git a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm index c3d13448d..ef27d2c4e 100644 --- a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm +++ b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm @@ -107,5 +107,410 @@ sub council_rss_alert_options { return ( \@options, @reported_to_options ? \@reported_to_options : undef ); } +sub process_extras { + my $self = shift; + my $ctx = shift; + my $body_id = shift; + my $extra = shift; + + my $value = $ctx->request->params->{address} || ''; + $ctx->stash->{field_errors}->{address} = _('This information is required') + unless $value; + $extra->{address} = $value; +} + +# A record of the number of reports from the Channel 4 site and other old data +sub old_site_stats { + return { + 2223 => 95, + 2238 => 82, + 2245 => 54, + 2248 => 31, + 2250 => 132, + 2253 => 15, + 2255 => 25, + 2256 => 8, + 2257 => 3, + 2258 => 14, + 2259 => 5, + 2260 => 22, + 2261 => 12, + 2262 => 21, + 2263 => 14, + 2264 => 1, + 2267 => 1, + 2271 => 13, + 2272 => 7, + 2273 => 13, + 2274 => 7, + 2275 => 15, + 2276 => 14, + 2277 => 10, + 2278 => 7, + 2279 => 23, + 2280 => 16, + 2281 => 25, + 2282 => 14, + 2283 => 10, + 2284 => 22, + 2285 => 25, + 2286 => 32, + 2287 => 13, + 2288 => 13, + 2289 => 16, + 2290 => 18, + 2291 => 1, + 2292 => 9, + 2293 => 15, + 2294 => 16, + 2295 => 12, + 2296 => 4, + 2299 => 2, + 2300 => 1, + 2304 => 10, + 2305 => 17, + 2306 => 6, + 2307 => 11, + 2308 => 17, + 2309 => 9, + 2310 => 6, + 2311 => 9, + 2312 => 26, + 2313 => 2, + 2314 => 34, + 2315 => 18, + 2316 => 13, + 2317 => 17, + 2318 => 7, + 2319 => 14, + 2320 => 4, + 2321 => 20, + 2322 => 7, + 2323 => 10, + 2324 => 7, + 2325 => 15, + 2326 => 12, + 2327 => 25, + 2328 => 23, + 2329 => 11, + 2330 => 4, + 2331 => 29, + 2332 => 12, + 2333 => 7, + 2334 => 5, + 2335 => 16, + 2336 => 7, + 2337 => 7, + 2338 => 2, + 2339 => 12, + 2340 => 2, + 2341 => 7, + 2342 => 14, + 2343 => 20, + 2344 => 13, + 2345 => 17, + 2346 => 6, + 2347 => 4, + 2348 => 6, + 2349 => 18, + 2350 => 13, + 2351 => 11, + 2352 => 24, + 2353 => 10, + 2354 => 20, + 2355 => 14, + 2356 => 13, + 2357 => 14, + 2358 => 8, + 2359 => 6, + 2360 => 10, + 2361 => 36, + 2362 => 17, + 2363 => 8, + 2364 => 7, + 2365 => 8, + 2366 => 26, + 2367 => 19, + 2368 => 20, + 2369 => 8, + 2370 => 14, + 2371 => 79, + 2372 => 10, + 2373 => 5, + 2374 => 4, + 2375 => 12, + 2376 => 10, + 2377 => 24, + 2378 => 9, + 2379 => 8, + 2380 => 25, + 2381 => 13, + 2382 => 11, + 2383 => 16, + 2384 => 18, + 2385 => 12, + 2386 => 18, + 2387 => 5, + 2388 => 8, + 2389 => 12, + 2390 => 11, + 2391 => 23, + 2392 => 11, + 2393 => 16, + 2394 => 9, + 2395 => 27, + 2396 => 8, + 2397 => 27, + 2398 => 14, + 2402 => 1, + 2403 => 18, + 2404 => 14, + 2405 => 7, + 2406 => 9, + 2407 => 12, + 2408 => 3, + 2409 => 8, + 2410 => 23, + 2411 => 27, + 2412 => 9, + 2413 => 20, + 2414 => 96, + 2415 => 11, + 2416 => 20, + 2417 => 18, + 2418 => 24, + 2419 => 18, + 2420 => 7, + 2421 => 29, + 2427 => 7, + 2428 => 15, + 2429 => 18, + 2430 => 32, + 2431 => 9, + 2432 => 17, + 2433 => 8, + 2434 => 10, + 2435 => 14, + 2436 => 13, + 2437 => 11, + 2438 => 5, + 2439 => 4, + 2440 => 23, + 2441 => 8, + 2442 => 18, + 2443 => 12, + 2444 => 3, + 2445 => 8, + 2446 => 31, + 2447 => 15, + 2448 => 3, + 2449 => 12, + 2450 => 11, + 2451 => 8, + 2452 => 20, + 2453 => 25, + 2454 => 8, + 2455 => 6, + 2456 => 24, + 2457 => 6, + 2458 => 10, + 2459 => 15, + 2460 => 17, + 2461 => 20, + 2462 => 12, + 2463 => 16, + 2464 => 5, + 2465 => 14, + 2466 => 20, + 2467 => 14, + 2468 => 12, + 2469 => 4, + 2470 => 1, + 2471 => 1, + 2474 => 9, + 2475 => 12, + 2476 => 11, + 2477 => 9, + 2478 => 10, + 2479 => 21, + 2480 => 26, + 2481 => 30, + 2482 => 38, + 2483 => 46, + 2484 => 63, + 2485 => 7, + 2486 => 14, + 2487 => 16, + 2488 => 14, + 2489 => 39, + 2490 => 112, + 2491 => 79, + 2492 => 137, + 2493 => 55, + 2494 => 18, + 2495 => 41, + 2496 => 41, + 2497 => 22, + 2498 => 26, + 2499 => 46, + 2500 => 62, + 2501 => 90, + 2502 => 47, + 2503 => 32, + 2504 => 33, + 2505 => 47, + 2506 => 56, + 2507 => 26, + 2508 => 48, + 2509 => 47, + 2510 => 16, + 2511 => 6, + 2512 => 4, + 2513 => 41, + 2514 => 138, + 2515 => 48, + 2516 => 65, + 2517 => 35, + 2518 => 40, + 2519 => 31, + 2520 => 27, + 2521 => 25, + 2522 => 34, + 2523 => 27, + 2524 => 47, + 2525 => 22, + 2526 => 125, + 2527 => 126, + 2528 => 93, + 2529 => 23, + 2530 => 28, + 2531 => 24, + 2532 => 46, + 2533 => 22, + 2534 => 24, + 2535 => 27, + 2536 => 44, + 2537 => 54, + 2538 => 17, + 2539 => 13, + 2540 => 29, + 2541 => 15, + 2542 => 19, + 2543 => 14, + 2544 => 34, + 2545 => 30, + 2546 => 38, + 2547 => 32, + 2548 => 22, + 2549 => 37, + 2550 => 9, + 2551 => 41, + 2552 => 17, + 2553 => 36, + 2554 => 10, + 2555 => 20, + 2556 => 13, + 2557 => 19, + 2558 => 13, + 2559 => 23, + 2560 => 13, + 2561 => 62, + 2562 => 29, + 2563 => 31, + 2564 => 34, + 2565 => 57, + 2566 => 16, + 2567 => 22, + 2568 => 40, + 2569 => 5, + 2570 => 38, + 2571 => 17, + 2572 => 9, + 2573 => 12, + 2574 => 10, + 2575 => 16, + 2576 => 2, + 2577 => 28, + 2578 => 37, + 2579 => 79, + 2580 => 17, + 2581 => 734, + 2582 => 11, + 2583 => 23, + 2584 => 16, + 2585 => 4, + 2586 => 33, + 2587 => 3, + 2588 => 22, + 2589 => 19, + 2590 => 14, + 2591 => 9, + 2592 => 19, + 2593 => 11, + 2594 => 14, + 2595 => 13, + 2596 => 21, + 2597 => 10, + 2598 => 16, + 2599 => 26, + 2600 => 1, + 2601 => 19, + 2602 => 23, + 2603 => 12, + 2604 => 31, + 2605 => 30, + 2606 => 5, + 2607 => 32, + 2608 => 14, + 2609 => 27, + 2610 => 15, + 2611 => 20, + 2612 => 22, + 2613 => 20, + 2614 => 97, + 2615 => 29, + 2616 => 6, + 2617 => 34, + 2618 => 16, + 2619 => 25, + 2620 => 12, + 2621 => 29, + 2622 => 18, + 2623 => 12, + 2624 => 58, + 2625 => 54, + 2626 => 15, + 2627 => 1, + 2629 => 17, + 2630 => 22, + 2636 => 13, + 2637 => 13, + 2638 => 25, + 2639 => 57, + 2640 => 15, + 2641 => 11, + 2642 => 14, + 2643 => 38, + 2644 => 19, + 2645 => 6, + 2646 => 1, + 2647 => 16, + 2648 => 25, + 2649 => 38, + 2650 => 12, + 2651 => 78, + 2652 => 12, + 2654 => 16, + 2655 => 13, + 2656 => 15, + 2657 => 44, + 2658 => 53, + 16869 => 73, + 21068 => 44, + 21069 => 57, + 21070 => 20, + }; +} + 1; diff --git a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm index 62550e626..950ea8127 100644 --- a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm +++ b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm @@ -49,6 +49,9 @@ sub example_places { return ( 'OX20 1SZ', 'Park St, Woodstock' ); } +# don't send questionnaires to people who used the OCC cobrand to report their problem +sub send_questionnaires { return 0; } + sub default_show_name { 0 } 1; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 08f6beb6e..ec15600b6 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -411,7 +411,7 @@ sub check_for_errors { { $errors{name} = _( 'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below' - ); + ) unless $self->cobrand eq 'emptyhomes'; } if ( $self->category diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index fe12f95e9..dc1c5c248 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -156,7 +156,7 @@ sub around_map { sub timeline { my ( $rs ) = @_; - my $prefetch = + my $prefetch = FixMyStreet::App->model('DB')->schema->storage->sql_maker->quote_char ? [ qw/user/ ] : []; @@ -220,7 +220,8 @@ sub send_reports { my ( $rs, $site_override ) = @_; # Set up site, language etc. - my ($verbose, $nomail) = CronFns::options(); + my ($verbose, $nomail, $debug_mode) = CronFns::options(); + my $base_url = mySociety::Config::get('BASE_URL'); my $site = $site_override || CronFns::site($base_url); @@ -237,18 +238,31 @@ sub send_reports { my $senders = $send_report->get_senders; my %sending_skipped_by_method; + my $debug_unsent_count = 0; + debug_print("starting to loop through unsent problem reports...") if $debug_mode; while (my $row = $unsent->next) { my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($row->cobrand)->new(); - # Cobranded and non-cobranded messages can share a database. In this case, the conf file - # should specify a vhost to send the reports for each cobrand, so that they don't get sent + if ($debug_mode) { + $debug_unsent_count++; + print "\n"; + debug_print("state=" . $row->state . ", bodies_str=" . $row->bodies_str . ($row->cobrand? ", cobrand=" . $row->cobrand : ""), $row->id); + } + + # Cobranded and non-cobranded messages can share a database. In this case, the conf file + # should specify a vhost to send the reports for each cobrand, so that they don't get sent # more than once if there are multiple vhosts running off the same database. The email_host # call checks if this is the host that sends mail for this cobrand. - next unless $cobrand->email_host(); + if (! $cobrand->email_host()) { + debug_print("skipping because this host does not send reports for cobrand " . $cobrand->moniker, $row->id) if $debug_mode; + next; + } + $cobrand->set_lang_and_domain($row->lang, 1); if ( $row->is_from_abuser ) { $row->update( { state => 'hidden' } ); + debug_print("hiding because its sender is flagged as an abuser", $row->id) if $debug_mode; next; } @@ -310,6 +324,7 @@ sub send_reports { my $sender = "FixMyStreet::SendReport::EmptyHomes"; $reporters{ $sender } = $sender->new() unless $reporters{$sender}; $reporters{ $sender }->add_body( $body ); + $sender_count = 1; } else { @@ -332,9 +347,11 @@ sub send_reports { $reporters{ $sender } ||= $sender->new(); if ( $reporters{ $sender }->should_skip( $row ) ) { - $sending_skipped_by_method{ $sender }++ if + debug_print("skipped by sender " . $sender_info->{method} . " (might be due to previous failed attempts?)", $row->id) if $debug_mode; + $sending_skipped_by_method{ $sender }++ if $reporters{ $sender }->skipped; } else { + debug_print("OK, adding recipient body " . $body->id . ":" . $body->name . ", " . $body->send_method, $row->id) if $debug_mode; push @dear, $body->name; $reporters{ $sender }->add_body( $body, $sender_info->{config} ); } @@ -360,7 +377,7 @@ sub send_reports { $h{multiple} = @dear>1 ? "[ " . _("This email has been sent to several councils covering the location of the problem, as the category selected is provided for all of them; please ignore it if you're not the correct council to deal with the issue.") . " ]\n\n" : ''; } - $h{missing} = ''; + $h{missing} = ''; if ($missing) { $h{missing} = '[ ' . sprintf(_('We realise this problem might be the responsibility of %s; however, we don\'t currently have any contact details for them. If you know of an appropriate contact address, please do get in touch.'), $missing->name) @@ -374,11 +391,14 @@ sub send_reports { die 'Report not going anywhere for ID ' . $row->id . '!'; } - next unless $sender_count; + if (! $sender_count) { + debug_print("can't send because sender count is zero", $row->id) if $debug_mode; + next; + } if (mySociety::Config::get('STAGING_SITE') && !mySociety::Config::get('SEND_REPORTS_ON_STAGING')) { # on a staging server send emails to ourselves rather than the bodies - %reporters = map { $_ => $reporters{$_} } grep { /FixMyStreet::SendReport::(Email|NI)/ } keys %reporters; + %reporters = map { $_ => $reporters{$_} } grep { /FixMyStreet::SendReport::(Email|NI|EmptyHomes)/ } keys %reporters; unless (%reporters) { %reporters = ( 'FixMyStreet::SendReport::Email' => FixMyStreet::SendReport::Email->new() ); } @@ -388,6 +408,7 @@ sub send_reports { my $result = -1; for my $sender ( keys %reporters ) { + debug_print("sending using " . $sender, $row->id) if $debug_mode; $result *= $reporters{ $sender }->send( $row, \%h ); if ( $reporters{ $sender }->unconfirmed_counts) { foreach my $e (keys %{ $reporters{ $sender }->unconfirmed_counts } ) { @@ -410,6 +431,7 @@ sub send_reports { if ( $cobrand->report_sent_confirmation_email && !$h{anonymous_report}) { _send_report_sent_email( $row, \%h, $nomail ); } + debug_print("send successful: OK", $row->id) if $debug_mode; } else { my @errors; for my $sender ( keys %reporters ) { @@ -418,10 +440,19 @@ sub send_reports { } } $row->update_send_failed( join( '|', @errors ) ); + debug_print("send FAILED: " . join( '|', @errors ), $row->id) if $debug_mode; + } + } + if ($debug_mode) { + print "\n"; + if ($debug_unsent_count) { + debug_print("processed all unsent reports (total: $debug_unsent_count)"); + } else { + debug_print("no unsent reports were found (must have whensent=null and suitable bodies_str & state) -- nothing to send"); } } - if ($verbose) { + if ($verbose || $debug_mode) { print "Council email addresses that need checking:\n" if keys %notgot; foreach my $e (keys %notgot) { foreach my $c (keys %{$notgot{$e}}) { @@ -481,4 +512,11 @@ sub _send_report_sent_email { ); } +sub debug_print { + my $msg = shift; + my $id = shift || ''; + $id = "report $id: " if $id; + print "[] $id$msg\n"; +} + 1; diff --git a/perllib/FixMyStreet/SendReport/EmptyHomes.pm b/perllib/FixMyStreet/SendReport/EmptyHomes.pm index b29c1fd3c..4bae6af46 100644 --- a/perllib/FixMyStreet/SendReport/EmptyHomes.pm +++ b/perllib/FixMyStreet/SendReport/EmptyHomes.pm @@ -33,15 +33,20 @@ sub build_recipient_list { push @{ $self->to }, [ $body_email, $body->name ]; $recips{$body_email} = 1; - my $area_info = mySociety::MaPit::call('area', $body->area_id); + my $area_info = mySociety::MaPit::call('area', $body->body_areas->first->area_id); my $country = $area_info->{country}; if ($country eq 'W') { - $recips{ 'shelter@' . mySociety::Config::get('EMAIL_DOMAIN') } = 1; + $recips{ 'wales@' . mySociety::Config::get('EMAIL_DOMAIN') } = 1; + } elsif ($country eq 'S') { + $recips{ 'scotland@' . mySociety::Config::get('EMAIL_DOMAIN') } = 1; } else { $recips{ 'eha@' . mySociety::Config::get('EMAIL_DOMAIN') } = 1; } } + # Set address email parameter from added data + $h->{address} = $row->extra->{address}; + return () unless $all_confirmed; return keys %recips; } |