aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB/Result/User.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2016-06-16 14:54:32 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-06-20 18:17:05 +0100
commit1ac833b14eddb275ae124035dc95650e725265d3 (patch)
tree6988ad8f439a17b356c8371e6f42410282f56b79 /perllib/FixMyStreet/DB/Result/User.pm
parent4deacd970890447947704692d55bea0a2b3d14ec (diff)
Allow users to update their email address.
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/User.pm')
-rw-r--r--perllib/FixMyStreet/DB/Result/User.pm27
1 files changed, 24 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm
index 054be3644..7356969d1 100644
--- a/perllib/FixMyStreet/DB/Result/User.pm
+++ b/perllib/FixMyStreet/DB/Result/User.pm
@@ -239,9 +239,30 @@ sub has_permission_to {
return $permission ? 1 : undef;
}
-sub print {
- my $self = shift;
- return '[' . (join '-', @_) . ']';
+sub adopt {
+ my ($self, $other) = @_;
+
+ return if $self->id == $other->id;
+
+ # Move most things from $other to $self
+ foreach (qw(Problem Comment Alert AdminLog )) {
+ $self->result_source->schema->resultset($_)
+ ->search({ user_id => $other->id })
+ ->update({ user_id => $self->id });
+ }
+
+ # It's possible the user permissions for the other user exist, so
+ # try updating, and then delete anyway.
+ foreach ($self->result_source->schema->resultset("UserBodyPermission")
+ ->search({ user_id => $other->id })->all) {
+ eval {
+ $_->update({ user_id => $self->id });
+ };
+ $_->delete if $@;
+ }
+
+ # Delete the now empty user
+ $other->delete;
}
1;