aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/expire-sessions79
-rwxr-xr-xbin/fixmystreet.com/fixture23
-rwxr-xr-xbin/gettext-nget-patch4
-rwxr-xr-xbin/open311-populate-service-list4
-rwxr-xr-xbin/oxfordshire/open311_service_request.cgi2
-rwxr-xr-xbin/send-comments2
-rw-r--r--bin/site-specific-install.sh2
-rwxr-xr-xbin/update-all-reports2
8 files changed, 110 insertions, 8 deletions
diff --git a/bin/expire-sessions b/bin/expire-sessions
new file mode 100755
index 000000000..8cfdd57e3
--- /dev/null
+++ b/bin/expire-sessions
@@ -0,0 +1,79 @@
+#!/usr/bin/env perl
+
+# expire-sessions: Run regularly to remove old sessions (plus
+# can set up data for 'log user out' admin functionality).
+
+use strict;
+use warnings;
+require 5.8.0;
+
+BEGIN {
+ use File::Basename qw(dirname);
+ use File::Spec;
+ my $d = dirname(File::Spec->rel2abs($0));
+ require "$d/../setenv.pl";
+}
+
+use FixMyStreet::DB;
+use Getopt::Long;
+use List::Util qw(uniq);
+use MIME::Base64;
+use Storable;
+
+GetOptions(
+ 'init' => \my $init,
+);
+
+my $rs = FixMyStreet::DB->resultset("Session");
+
+# Delete expired sessions (including from in User object)
+while (my $session = $rs->search({ expires => { '<', time() } })->next) {
+ if (my $user = get_user($session)) {
+ my $id = get_id($session);
+ my $sessions = $user->get_extra_metadata('sessions');
+ my @new_sessions = grep { $_ ne $id } @$sessions;
+ update_user_sessions($user, \@new_sessions) if @new_sessions != @$sessions;
+ }
+ $session->delete;
+}
+
+if ($init) {
+ # Update sessions to make sure all present in User objects
+ print "Setting up sessions in user objects\n";
+ while (my $session = $rs->next) {
+ my $user = get_user($session) or next;
+ my $id = get_id($session);
+ my $sessions = $user->get_extra_metadata('sessions');
+ my @new_sessions = uniq @$sessions, $id;
+ update_user_sessions($user, \@new_sessions) if @new_sessions != @$sessions;
+ }
+}
+
+# ---
+
+sub get_user {
+ my $session = shift;
+ return unless $session->session_data;
+ my $data = Storable::thaw(MIME::Base64::decode($session->session_data));
+ return unless $data->{__user};
+ my $user = FixMyStreet::DB->resultset("User")->find($data->{__user}{id});
+ return $user;
+}
+
+sub get_id {
+ my $session = shift;
+ my $id = $session->id;
+ $id =~ s/^session://;
+ $id =~ s/\s+$//;
+ return $id;
+}
+
+sub update_user_sessions {
+ my ($user, $sessions) = @_;
+ if (@$sessions) {
+ $user->set_extra_metadata('sessions', $sessions);
+ } else {
+ $user->unset_extra_metadata('sessions');
+ }
+ $user->update;
+}
diff --git a/bin/fixmystreet.com/fixture b/bin/fixmystreet.com/fixture
index 194bdc48c..aceb75bd3 100755
--- a/bin/fixmystreet.com/fixture
+++ b/bin/fixmystreet.com/fixture
@@ -16,9 +16,11 @@ BEGIN {
}
use List::Util qw(shuffle);
+use Path::Tiny;
use FixMyStreet;
use FixMyStreet::Cobrand;
use FixMyStreet::DB::Factories;
+use FixMyStreet::App::Model::PhotoSet;
use DateTime::Format::Pg;
use Getopt::Long::Descriptive;
@@ -123,6 +125,12 @@ my %titles = (
'Graffiti' => ['Graffiti', 'Graffiti', 'Offensive graffiti', 'Graffiti on the bridge', 'Remove graffiti'],
'Other' => ['Loose drain cover', 'Flytipping on country lane', 'Vehicle blocking footpath', 'Hedge encroaching pavement', 'Full litter bins'],
);
+my %photos = (
+ 'Potholes' => [ '33717571655_46dfc6f65f_z.jpg', '37855543925_9dbbbecf41_z.jpg', '19119222668_a3c866d7c8_z.jpg', '12049724866_404b066875_z.jpg', '3705226606_eac71cf195_z.jpg', '6304445383_bd216ca892_z.jpg' ],
+ 'Street lighting' => ['38110448864_fd71227247_z.jpg', '27050321819_ac123400eb_z.jpg', '35732107202_b790c61f63_z.jpg', '31889115854_01cdf38b0d_z.jpg', undef ],
+ 'Graffiti' => ['12205918375_f37f0b27a9_z.jpg', '8895442578_376a9b0be0_z.jpg', '22998854352_17555b7536_z.jpg', '22593395257_3d48f23bfa_z.jpg', '20515339175_f4ed9fc1d9_z.jpg' ],
+ 'Other' => ['14347396807_20737504f7_z.jpg', '14792525771_167bc20e3d_z.jpg', undef, '36296226976_a83a118ff8_z.jpg', '23222004240_273977b2b2_z.jpg'],
+);
my %descriptions = (
'Potholes' => [
'6” deep pothole in the very centre of the Bristol road; cars are swerving to avoid it. Please treat this as a matter of urgency.',
@@ -186,6 +194,20 @@ for (1..$num) {
my $titles = $titles{$category};
my $descs = $descriptions{$category};
my $rand = int(rand(@$titles));
+
+ my $photo;
+ if (my $file = $photos{$category}->[$rand]) {
+ my $files = [ $file ];
+ if ($category eq 'Graffiti') {
+ push @$files, $photos{$category}->[int(rand(@$titles))];
+ }
+ $files = [ map { path(FixMyStreet->path_to("t/images/$_"))->slurp_raw } @$files ];
+ my $photoset = FixMyStreet::App::Model::PhotoSet->new({
+ data_items => $files,
+ });
+ $photo = $photoset->data;
+ }
+
push @$problems, FixMyStreet::DB::Factory::Problem->create({
body => $body,
areas => ',' . $opt->area_id . ',',
@@ -197,6 +219,7 @@ for (1..$num) {
cobrand => $cobrand,
title => $titles->[$rand],
detail => $descs->[$rand],
+ photo_id => $photo,
confirmed => DateTime::Format::Pg->format_datetime($confirmed),
});
}
diff --git a/bin/gettext-nget-patch b/bin/gettext-nget-patch
index 67f98e319..5d30cc922 100755
--- a/bin/gettext-nget-patch
+++ b/bin/gettext-nget-patch
@@ -15,9 +15,9 @@ find( sub {
next unless /nget/;
my $line = $.;
my $text = $_;
- do {
+ while ($text !~ /\)/) {
$text .= <FP>;
- } until $text =~ /\)/;
+ }
if ($text =~ /nget\(\s*(['"])(.*?)\1\s*,\s*(['"])(.*?)\3\s*,\s*(.*?)\s*\)/s) {
$out{$2} = {
file => $File::Find::name,
diff --git a/bin/open311-populate-service-list b/bin/open311-populate-service-list
index 8cb41a47b..9c05055c6 100755
--- a/bin/open311-populate-service-list
+++ b/bin/open311-populate-service-list
@@ -23,8 +23,8 @@ my ($opt, $usage) = describe_options(
print($usage->text), exit if $opt->help;
my $bodies = FixMyStreet::DB->resultset('Body')->search( {
- # Until Oxfordshire does, and Bristol stops erroring
- name => { -not_in => [ 'Oxfordshire County Council', 'Bristol City Council' ] },
+ # Until Oxfordshire does
+ name => { -not_in => [ 'Oxfordshire County Council' ] },
send_method => 'Open311'
} );
my $verbose = 0;
diff --git a/bin/oxfordshire/open311_service_request.cgi b/bin/oxfordshire/open311_service_request.cgi
index 4496ff213..95d3d34ef 100755
--- a/bin/oxfordshire/open311_service_request.cgi
+++ b/bin/oxfordshire/open311_service_request.cgi
@@ -114,7 +114,7 @@ XML
# returns true if this looks like a long/lat value
#------------------------------------------------------------------
sub is_longlat {
- return $_[0] =~ /^-?\d+\.\d+$/o? 1 : 0;
+ return $_[0] =~ /^-?\d+(\.\d+)?$/o ? 1 : 0;
}
#------------------------------------------------------------------
diff --git a/bin/send-comments b/bin/send-comments
index 7363d7a0d..aecedcb08 100755
--- a/bin/send-comments
+++ b/bin/send-comments
@@ -49,7 +49,7 @@ my $bodies = FixMyStreet::DB->resultset('Body')->search( {
while ( my $body = $bodies->next ) {
- # XXX Cobrand specific
+ # XXX Cobrand specific - see also list in Problem->updates_sent_to_body
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
diff --git a/bin/site-specific-install.sh b/bin/site-specific-install.sh
index cb8b630e3..57a3ad1f8 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:-v2.3}
+VERSION=${VERSION_OVERRIDE:-v2.3.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 1225a4c08..087c59d06 100755
--- a/bin/update-all-reports
+++ b/bin/update-all-reports
@@ -37,7 +37,7 @@ if ($opt->table) {
$data = FixMyStreet::Script::UpdateAllReports::generate($opt->areas);
output('all-reports', $data);
} elsif ($opt->all_bodies) {
- my $bodies = FixMyStreet::DB->resultset("Body")->search({ deleted => 0 });
+ my $bodies = FixMyStreet::DB->resultset("Body")->active;
while (my $body = $bodies->next) {
next unless $body->body_areas->first;
my $data = FixMyStreet::Script::UpdateAllReports::generate_dashboard($body);