Permalink
Browse files

Move user data to the anonymous user when deleting users.

  • Loading branch information...
nirix committed Dec 8, 2013
1 parent 2d101ef commit 68242e5e96bb7069f99d769a22a0de6c7d1eb682
Showing with 25 additions and 0 deletions.
  1. +25 −0 vendor/traq/models/user.php
@@ -367,4 +367,29 @@ public function __toArray($fields = null)
unset($data['password'], $data['email'], $data['login_hash']);
return $data;
}
/**
* Moves ticket and timeline data to the anonymous user before deleting the user.
*/
public function delete() {
$anon_id = Setting::find('setting', 'anonymous_user_id')->value;
// Update attachments, tickets, ticket updates and timeline events
$tables = array('attachments', 'tickets', 'ticket_history', 'timeline');
foreach ($tables as $table) {
static::db()->update($table)->set(array('user_id' => $anon_id))->where('user_id', $this->id)->exec();
}
// Update assigned tickets
static::db()->update('tickets')->set(array('assigned_to_id' => 0))->where('assigned_to_id', $this->id)->exec();
// Delete subscriptions
static::db()->delete()->from('subscriptions')->where('user_id', $this->id)->exec();
// Delete user project roles
static::db()->delete()->from('user_roles')->where('user_id', $this->id)->exec();
// Delete user
parent::delete();
}
}

0 comments on commit 68242e5

Please sign in to comment.