aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/expire-sessions64
-rwxr-xr-xbin/process-inactive-accounts43
-rwxr-xr-xbin/process-inactive-reports41
-rwxr-xr-xbin/update-schema1
4 files changed, 112 insertions, 37 deletions
diff --git a/bin/expire-sessions b/bin/expire-sessions
index 8cfdd57e3..375ba4c6f 100755
--- a/bin/expire-sessions
+++ b/bin/expire-sessions
@@ -1,11 +1,11 @@
#!/usr/bin/env perl
# expire-sessions: Run regularly to remove old sessions (plus
-# can set up data for 'log user out' admin functionality).
+# can set up data for 'log user out' admin functionality, and
+# inactive user processing).
-use strict;
+use v5.14;
use warnings;
-require 5.8.0;
BEGIN {
use File::Basename qw(dirname);
@@ -17,55 +17,46 @@ BEGIN {
use FixMyStreet::DB;
use Getopt::Long;
use List::Util qw(uniq);
-use MIME::Base64;
-use Storable;
GetOptions(
+ # Update sessions to make sure all present in User objects
'init' => \my $init,
);
my $rs = FixMyStreet::DB->resultset("Session");
+my $now = time();
# 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);
+# And update last active time of current sessions
+while (my $session = $rs->next) {
+ my $id = $session->id_code;
+ my $user = $session->user;
+ my $expires = $session->expires;
+ if (!$expires || $expires < $now) {
+ if ($user) {
+ 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;
+ } elsif ($user && $init) {
my $sessions = $user->get_extra_metadata('sessions');
my @new_sessions = uniq @$sessions, $id;
update_user_sessions($user, \@new_sessions) if @new_sessions != @$sessions;
}
+ if ($user) {
+ update_user_last_active($user, $expires);
+ $user->update;
+ }
}
# ---
-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_last_active {
+ my ($user, $expires) = @_;
+ return unless $expires;
+ my $t = DateTime->from_epoch(epoch => $expires)->subtract(weeks => 4);
+ $user->set_last_active($t) if !$user->last_active || $user->last_active < $t;
}
sub update_user_sessions {
@@ -75,5 +66,4 @@ sub update_user_sessions {
} else {
$user->unset_extra_metadata('sessions');
}
- $user->update;
}
diff --git a/bin/process-inactive-accounts b/bin/process-inactive-accounts
new file mode 100755
index 000000000..3df200d3d
--- /dev/null
+++ b/bin/process-inactive-accounts
@@ -0,0 +1,43 @@
+#!/usr/bin/env perl
+
+use v5.14;
+use warnings;
+
+BEGIN {
+ use File::Basename qw(dirname);
+ use File::Spec;
+ my $d = dirname(File::Spec->rel2abs($0));
+ require "$d/../setenv.pl";
+}
+
+use Getopt::Long;
+use FixMyStreet::Script::Inactive;
+use Pod::Usage;
+
+my %h;
+GetOptions(\%h, 'anonymize=i', 'email=i', 'verbose|v', 'help|h', 'dry-run|n');
+pod2usage(0) if $h{help};
+pod2usage(1) if !$h{anonymize};
+pod2usage("Anonymize time must be greater than email time")
+ if $h{email} && $h{email} >= $h{anonymize};
+
+FixMyStreet::Script::Inactive->new(%h)->users;
+
+__END__
+
+=head1 NAME
+
+process-inactive-accounts - deal with anonymizing old inactive accounts
+
+=head1 SYNOPSIS
+
+process-inactive-accounts --anonymize N [--email N]
+
+ Options:
+ --anonymize Anonymize accounts inactive longer than this time (months)
+ --email Email accounts inactive longer than this time (months)
+ --dry-run Don't actually anonymize anything or send any emails
+ --verbose Output as to which users are being affected
+ --help This help message
+
+=cut
diff --git a/bin/process-inactive-reports b/bin/process-inactive-reports
new file mode 100755
index 000000000..d2c030c2c
--- /dev/null
+++ b/bin/process-inactive-reports
@@ -0,0 +1,41 @@
+#!/usr/bin/env perl
+
+use v5.14;
+use warnings;
+
+BEGIN {
+ use File::Basename qw(dirname);
+ use File::Spec;
+ my $d = dirname(File::Spec->rel2abs($0));
+ require "$d/../setenv.pl";
+}
+
+use Getopt::Long;
+use FixMyStreet::Script::Inactive;
+use Pod::Usage;
+
+my %h;
+GetOptions(\%h, 'anonymize=i', 'close=i', 'verbose|v', 'help|h', 'dry-run|n');
+pod2usage(0) if $h{help};
+pod2usage(1) unless $h{anonymize} || $h{close};
+
+FixMyStreet::Script::Inactive->new(%h)->reports;
+
+__END__
+
+=head1 NAME
+
+process-inactive-reports - deal with anonymizing inactive non-open reports
+
+=head1 SYNOPSIS
+
+process-inactive-reports [--anonymize N] [--close N]
+
+ Options:
+ --anonymize Anonymize non-open reports (and related) inactive longer than this time (months)
+ --close Close comments on non-open reports inactive longer than this time (months)
+ --dry-run Don't actually anonymize anything or send any emails
+ --verbose Output as to which reports are being affected
+ --help This help message
+
+=cut
diff --git a/bin/update-schema b/bin/update-schema
index fb88c84a1..2ae374e61 100755
--- a/bin/update-schema
+++ b/bin/update-schema
@@ -212,6 +212,7 @@ else {
# (assuming schema change files are never half-applied, which should be the case)
sub get_db_version {
return 'EMPTY' if ! table_exists('problem');
+ return '0062' if column_exists('users', 'created');
return '0061' if column_exists('body', 'extra');
return '0060' if column_exists('body', 'convert_latlong');
return '0059' if column_exists('response_templates', 'external_status_code');