From a54e50961e7ba733559c97d7fbb3138e1efa960e Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 17 Mar 2023 16:41:33 -0700 Subject: [PATCH] Added event and listener Signed-off-by: snipe --- app/Events/UserMerged.php | 24 ++++++++++++++++++++ app/Listeners/LogListener.php | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 app/Events/UserMerged.php diff --git a/app/Events/UserMerged.php b/app/Events/UserMerged.php new file mode 100644 index 0000000000..b045fdef03 --- /dev/null +++ b/app/Events/UserMerged.php @@ -0,0 +1,24 @@ +merged_from = $from_user; + $this->merged_to = $to_user; + $this->admin = $admin; + } +} diff --git a/app/Listeners/LogListener.php b/app/Listeners/LogListener.php index 791a84f57a..af329be869 100644 --- a/app/Listeners/LogListener.php +++ b/app/Listeners/LogListener.php @@ -18,7 +18,9 @@ use App\Events\ItemDeclined; use App\Events\LicenseCheckedIn; use App\Events\LicenseCheckedOut; use App\Models\Actionlog; +use App\Models\User; use App\Models\LicenseSeat; +use App\Events\UserMerged; class LogListener { @@ -87,6 +89,43 @@ class LogListener $logaction->save(); } + + public function onUserMerged(UserMerged $event) + { + + $to_from_array = [ + 'to_id' => $event->merged_to->id, + 'to_username' => $event->merged_to->username, + 'from_id' => $event->merged_from->id, + 'from_username' => $event->merged_from->username, + ]; + + // Add a record to the users being merged FROM + \Log::debug('Users merged: '.$event->merged_from->id .' ('.$event->merged_from->username.') merged into '. $event->merged_to->id. ' ('.$event->merged_to->username.')'); + $logaction = new Actionlog(); + $logaction->item_id = $event->merged_from->id; + $logaction->item_type = User::class; + $logaction->target_id = $event->merged_to->id; + $logaction->target_type = User::class; + $logaction->action_type = 'merged'; + $logaction->note = trans('general.merged_users_log_merged_into', $to_from_array); + $logaction->user_id = $event->admin->id; + $logaction->save(); + + // Add a record to the users being merged TO + $logaction = new Actionlog(); + $logaction->target_id = $event->merged_from->id; + $logaction->target_type = User::class; + $logaction->item_id = $event->merged_to->id; + $logaction->item_type = User::class; + $logaction->action_type = 'merged'; + $logaction->note = trans('general.merged_users_log_merged_from', $to_from_array); + $logaction->user_id = $event->merged_to->admin_id; + $logaction->save(); + + + } + /** * Register the listeners for the subscriber. * @@ -99,6 +138,7 @@ class LogListener 'CheckoutableCheckedOut', 'CheckoutAccepted', 'CheckoutDeclined', + 'UserMerged', ]; foreach ($list as $event) { @@ -108,4 +148,6 @@ class LogListener ); } } + + }