2018-07-27 15:23:58 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Listeners;
|
|
|
|
|
|
|
|
use App\Events\AccessoryCheckedIn;
|
|
|
|
use App\Events\AccessoryCheckedOut;
|
|
|
|
use App\Events\AssetCheckedIn;
|
|
|
|
use App\Events\AssetCheckedOut;
|
2018-09-10 07:40:26 -07:00
|
|
|
use App\Events\CheckoutableCheckedIn;
|
|
|
|
use App\Events\CheckoutableCheckedOut;
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Events\CheckoutAccepted;
|
|
|
|
use App\Events\CheckoutDeclined;
|
2018-07-27 15:23:58 -07:00
|
|
|
use App\Events\ComponentCheckedIn;
|
|
|
|
use App\Events\ComponentCheckedOut;
|
|
|
|
use App\Events\ConsumableCheckedOut;
|
2018-07-27 16:15:32 -07:00
|
|
|
use App\Events\ItemAccepted;
|
|
|
|
use App\Events\ItemDeclined;
|
2018-07-27 15:23:58 -07:00
|
|
|
use App\Events\LicenseCheckedIn;
|
|
|
|
use App\Events\LicenseCheckedOut;
|
|
|
|
use App\Models\Actionlog;
|
2023-03-17 16:41:33 -07:00
|
|
|
use App\Models\User;
|
2018-07-28 03:45:33 -07:00
|
|
|
use App\Models\LicenseSeat;
|
2023-03-17 16:41:33 -07:00
|
|
|
use App\Events\UserMerged;
|
2018-07-27 15:23:58 -07:00
|
|
|
|
|
|
|
class LogListener
|
|
|
|
{
|
2022-05-17 06:55:23 -07:00
|
|
|
/**
|
|
|
|
* These onBlah methods are used by the subscribe() method further down in this file.
|
|
|
|
* This one creates an action_logs entry for the checkin
|
|
|
|
* @param CheckoutableCheckedIn $event
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
*/
|
2021-06-10 13:15:52 -07:00
|
|
|
public function onCheckoutableCheckedIn(CheckoutableCheckedIn $event)
|
|
|
|
{
|
2019-03-13 21:36:32 -07:00
|
|
|
$event->checkoutable->logCheckin($event->checkedOutTo, $event->note, $event->action_date);
|
2018-07-27 15:23:58 -07:00
|
|
|
}
|
|
|
|
|
2022-05-17 06:55:23 -07:00
|
|
|
/**
|
|
|
|
* These onBlah methods are used by the subscribe() method further down in this file.
|
|
|
|
* This one creates an action_logs entry for the checkout
|
|
|
|
*
|
|
|
|
* @param CheckoutableCheckedOut $event
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
*/
|
2021-06-10 13:15:52 -07:00
|
|
|
public function onCheckoutableCheckedOut(CheckoutableCheckedOut $event)
|
|
|
|
{
|
2019-03-13 21:36:32 -07:00
|
|
|
$event->checkoutable->logCheckout($event->note, $event->checkedOutTo, $event->checkoutable->last_checkout);
|
2021-06-10 13:15:52 -07:00
|
|
|
}
|
2018-07-27 15:23:58 -07:00
|
|
|
|
2022-05-17 06:55:23 -07:00
|
|
|
/**
|
|
|
|
* These onBlah methods are used by the subscribe() method further down in this file.
|
|
|
|
* This creates the entry in the action_logs table for the accept/decline action
|
|
|
|
*/
|
2021-06-10 13:15:52 -07:00
|
|
|
public function onCheckoutAccepted(CheckoutAccepted $event)
|
|
|
|
{
|
2018-07-28 03:45:33 -07:00
|
|
|
|
2022-07-05 17:58:45 -07:00
|
|
|
\Log::debug('event passed to the onCheckoutAccepted listener:');
|
2022-03-14 19:38:36 -07:00
|
|
|
$logaction = new Actionlog();
|
2018-07-28 03:45:33 -07:00
|
|
|
$logaction->item()->associate($event->acceptance->checkoutable);
|
|
|
|
$logaction->target()->associate($event->acceptance->assignedTo);
|
|
|
|
$logaction->accept_signature = $event->acceptance->signature_filename;
|
2022-05-17 06:55:23 -07:00
|
|
|
$logaction->filename = $event->acceptance->stored_eula_file;
|
2018-07-27 16:15:32 -07:00
|
|
|
$logaction->action_type = 'accepted';
|
|
|
|
|
2018-07-28 03:45:33 -07:00
|
|
|
// TODO: log the actual license seat that was checked out
|
2021-06-10 13:15:52 -07:00
|
|
|
if ($event->acceptance->checkoutable instanceof LicenseSeat) {
|
2018-07-28 03:45:33 -07:00
|
|
|
$logaction->item()->associate($event->acceptance->checkoutable->license);
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2022-05-17 06:55:23 -07:00
|
|
|
\Log::debug('New onCheckoutAccepted Listener fired. logaction: '.print_r($logaction, true));
|
2018-07-27 16:15:32 -07:00
|
|
|
$logaction->save();
|
2021-06-10 13:15:52 -07:00
|
|
|
}
|
2018-07-27 16:15:32 -07:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
public function onCheckoutDeclined(CheckoutDeclined $event)
|
|
|
|
{
|
2018-07-27 16:15:32 -07:00
|
|
|
$logaction = new Actionlog();
|
2018-07-28 03:45:33 -07:00
|
|
|
$logaction->item()->associate($event->acceptance->checkoutable);
|
|
|
|
$logaction->target()->associate($event->acceptance->assignedTo);
|
|
|
|
$logaction->accept_signature = $event->acceptance->signature_filename;
|
2018-07-27 16:15:32 -07:00
|
|
|
$logaction->action_type = 'declined';
|
|
|
|
|
2018-07-28 03:45:33 -07:00
|
|
|
// TODO: log the actual license seat that was checked out
|
2021-06-10 13:15:52 -07:00
|
|
|
if ($event->acceptance->checkoutable instanceof LicenseSeat) {
|
2018-07-28 03:45:33 -07:00
|
|
|
$logaction->item()->associate($event->acceptance->checkoutable->license);
|
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$logaction->save();
|
|
|
|
}
|
2018-07-27 16:15:32 -07:00
|
|
|
|
2023-03-17 16:41:33 -07:00
|
|
|
|
|
|
|
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';
|
2023-03-17 16:50:02 -07:00
|
|
|
$logaction->note = trans('general.merged_log_this_user_from', $to_from_array);
|
2023-03-17 16:41:33 -07:00
|
|
|
$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';
|
2023-03-17 16:50:02 -07:00
|
|
|
$logaction->note = trans('general.merged_log_this_user_into', $to_from_array);
|
2023-03-17 16:41:33 -07:00
|
|
|
$logaction->user_id = $event->merged_to->admin_id;
|
|
|
|
$logaction->save();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-07-27 15:23:58 -07:00
|
|
|
/**
|
|
|
|
* Register the listeners for the subscriber.
|
|
|
|
*
|
|
|
|
* @param Illuminate\Events\Dispatcher $events
|
|
|
|
*/
|
|
|
|
public function subscribe($events)
|
|
|
|
{
|
|
|
|
$list = [
|
2018-09-10 07:40:26 -07:00
|
|
|
'CheckoutableCheckedIn',
|
|
|
|
'CheckoutableCheckedOut',
|
2018-07-28 03:45:33 -07:00
|
|
|
'CheckoutAccepted',
|
2021-06-10 13:15:52 -07:00
|
|
|
'CheckoutDeclined',
|
2023-03-17 16:41:33 -07:00
|
|
|
'UserMerged',
|
2018-07-27 15:23:58 -07:00
|
|
|
];
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
foreach ($list as $event) {
|
2018-07-27 15:23:58 -07:00
|
|
|
$events->listen(
|
2021-06-10 13:15:52 -07:00
|
|
|
'App\Events\\'.$event,
|
|
|
|
'App\Listeners\LogListener@on'.$event
|
2018-07-27 15:23:58 -07:00
|
|
|
);
|
2021-06-10 13:15:52 -07:00
|
|
|
}
|
2018-07-27 15:23:58 -07:00
|
|
|
}
|
2023-03-17 16:41:33 -07:00
|
|
|
|
|
|
|
|
2019-03-13 20:12:03 -07:00
|
|
|
}
|