mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-24 04:03:34 -08:00
Added event and listener
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
82dc57aa18
commit
a54e50961e
24
app/Events/UserMerged.php
Normal file
24
app/Events/UserMerged.php
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Events\Dispatchable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class UserMerged
|
||||||
|
{
|
||||||
|
use Dispatchable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(User $from_user, User $to_user, User $admin)
|
||||||
|
{
|
||||||
|
$this->merged_from = $from_user;
|
||||||
|
$this->merged_to = $to_user;
|
||||||
|
$this->admin = $admin;
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,7 +18,9 @@ use App\Events\ItemDeclined;
|
||||||
use App\Events\LicenseCheckedIn;
|
use App\Events\LicenseCheckedIn;
|
||||||
use App\Events\LicenseCheckedOut;
|
use App\Events\LicenseCheckedOut;
|
||||||
use App\Models\Actionlog;
|
use App\Models\Actionlog;
|
||||||
|
use App\Models\User;
|
||||||
use App\Models\LicenseSeat;
|
use App\Models\LicenseSeat;
|
||||||
|
use App\Events\UserMerged;
|
||||||
|
|
||||||
class LogListener
|
class LogListener
|
||||||
{
|
{
|
||||||
|
@ -87,6 +89,43 @@ class LogListener
|
||||||
$logaction->save();
|
$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.
|
* Register the listeners for the subscriber.
|
||||||
*
|
*
|
||||||
|
@ -99,6 +138,7 @@ class LogListener
|
||||||
'CheckoutableCheckedOut',
|
'CheckoutableCheckedOut',
|
||||||
'CheckoutAccepted',
|
'CheckoutAccepted',
|
||||||
'CheckoutDeclined',
|
'CheckoutDeclined',
|
||||||
|
'UserMerged',
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($list as $event) {
|
foreach ($list as $event) {
|
||||||
|
@ -108,4 +148,6 @@ class LogListener
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue