mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Fixed checkin/checkout notification crashing
This commit is contained in:
parent
a91e81fc42
commit
52848ca8d8
|
@ -57,22 +57,32 @@ class CheckoutableListener
|
||||||
* Notify the user about the checked in checkoutable
|
* Notify the user about the checked in checkoutable
|
||||||
*/
|
*/
|
||||||
public function onCheckedIn($event) {
|
public function onCheckedIn($event) {
|
||||||
|
|
||||||
|
\Log::debug('checkin fired');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When the item wasn't checked out to a user, we can't send notifications
|
* When the item wasn't checked out to a user, we can't send notifications
|
||||||
*/
|
*/
|
||||||
if(!$event->checkedOutTo instanceof User) {
|
if(!$event->checkedOutTo instanceof User) {
|
||||||
|
\Log::debug('checked out to not a user');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the appropriate notification
|
* Send the appropriate notification
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
\Log::debug('checked out to a user');
|
||||||
if(!$event->checkedOutTo->locale){
|
if(!$event->checkedOutTo->locale){
|
||||||
|
\Log::debug('Use default settings locale');
|
||||||
Notification::locale(Setting::getSettings()->locale)->send(
|
Notification::locale(Setting::getSettings()->locale)->send(
|
||||||
$this->getNotifiables($event),
|
$this->getNotifiables($event),
|
||||||
$this->getCheckinNotification($event)
|
$this->getCheckinNotification($event)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
\Log::debug('Use user locale? I do not think this works as expected yet');
|
||||||
|
// \Log::debug(print_r($this->getNotifiables($event), true));
|
||||||
Notification::send(
|
Notification::send(
|
||||||
$this->getNotifiables($event),
|
$this->getNotifiables($event),
|
||||||
$this->getCheckinNotification($event)
|
$this->getCheckinNotification($event)
|
||||||
|
@ -130,7 +140,9 @@ class CheckoutableListener
|
||||||
*/
|
*/
|
||||||
private function getCheckinNotification($event) {
|
private function getCheckinNotification($event) {
|
||||||
|
|
||||||
$model = get_class($event->checkoutable);
|
// $model = get_class($event->checkoutable);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$notificationClass = null;
|
$notificationClass = null;
|
||||||
|
|
||||||
|
@ -145,7 +157,8 @@ class CheckoutableListener
|
||||||
$notificationClass = CheckinLicenseSeatNotification::class;
|
$notificationClass = CheckinLicenseSeatNotification::class;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
\Log::debug('Notification class: '.$notificationClass);
|
||||||
return new $notificationClass($event->checkoutable, $event->checkedOutTo, $event->checkedInBy, $event->note);
|
return new $notificationClass($event->checkoutable, $event->checkedOutTo, $event->checkedInBy, $event->note);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,38 +122,38 @@ trait Loggable
|
||||||
|
|
||||||
$log->logaction('checkin from');
|
$log->logaction('checkin from');
|
||||||
|
|
||||||
$params = [
|
// $params = [
|
||||||
'target' => $target,
|
// 'target' => $target,
|
||||||
'item' => $log->item,
|
// 'item' => $log->item,
|
||||||
'admin' => $log->user,
|
// 'admin' => $log->user,
|
||||||
'note' => $note,
|
// 'note' => $note,
|
||||||
'target_type' => $log->target_type,
|
// 'target_type' => $log->target_type,
|
||||||
'settings' => $settings,
|
// 'settings' => $settings,
|
||||||
];
|
// ];
|
||||||
|
//
|
||||||
|
//
|
||||||
$checkinClass = null;
|
// $checkinClass = null;
|
||||||
|
//
|
||||||
if (method_exists($target, 'notify')) {
|
// if (method_exists($target, 'notify')) {
|
||||||
try {
|
// try {
|
||||||
$target->notify(new static::$checkinClass($params));
|
// $target->notify(new static::$checkinClass($params));
|
||||||
} catch (\Exception $e) {
|
// } catch (\Exception $e) {
|
||||||
\Log::debug($e);
|
// \Log::debug($e);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// Send to the admin, if settings dictate
|
// // Send to the admin, if settings dictate
|
||||||
$recipient = new \App\Models\Recipients\AdminRecipient();
|
// $recipient = new \App\Models\Recipients\AdminRecipient();
|
||||||
|
//
|
||||||
if (($settings->admin_cc_email!='') && (static::$checkinClass!='')) {
|
// if (($settings->admin_cc_email!='') && (static::$checkinClass!='')) {
|
||||||
try {
|
// try {
|
||||||
$recipient->notify(new static::$checkinClass($params));
|
// $recipient->notify(new static::$checkinClass($params));
|
||||||
} catch (\Exception $e) {
|
// } catch (\Exception $e) {
|
||||||
\Log::debug($e);
|
// \Log::debug($e);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
return $log;
|
return $log;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ class CheckinAccessoryNotification extends Notification
|
||||||
$this->admin = $checkedInby;
|
$this->admin = $checkedInby;
|
||||||
$this->note = $note;
|
$this->note = $note;
|
||||||
$this->settings = Setting::getSettings();
|
$this->settings = Setting::getSettings();
|
||||||
|
\Log::debug('Constructor for notification fired');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,23 +36,63 @@ class CheckinAccessoryNotification extends Notification
|
||||||
*/
|
*/
|
||||||
public function via()
|
public function via()
|
||||||
{
|
{
|
||||||
|
\Log::debug('via called');
|
||||||
$notifyBy = [];
|
$notifyBy = [];
|
||||||
|
|
||||||
if (Setting::getSettings()->slack_endpoint) {
|
if (Setting::getSettings()->slack_endpoint) {
|
||||||
$notifyBy[] = 'slack';
|
$notifyBy[] = 'slack';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
if (Setting::getSettings()->slack_endpoint!='') {
|
||||||
* Only send checkin notifications to users if the category
|
$notifyBy[] = 'slack';
|
||||||
* has the corresponding checkbox checked.
|
|
||||||
*/
|
|
||||||
if ($this->item->checkin_email() && $this->target instanceof User && $this->target->email != '')
|
|
||||||
{
|
|
||||||
\Log::debug('use email');
|
|
||||||
$notifyBy[] = 'mail';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only send notifications to users that have email addresses
|
||||||
|
*/
|
||||||
|
if ($this->target instanceof User && $this->target->email != '') {
|
||||||
|
|
||||||
|
\Log::debug('The target is a user');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send an email if the asset requires acceptance,
|
||||||
|
* so the user can accept or decline the asset
|
||||||
|
*/
|
||||||
|
if (($this->item->requireAcceptance()) || ($this->item->getEula()) || ($this->item->checkin_email())) {
|
||||||
|
$notifyBy[] = 'mail';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send an email if the asset requires acceptance,
|
||||||
|
* so the user can accept or decline the asset
|
||||||
|
*/
|
||||||
|
if ($this->item->requireAcceptance()) {
|
||||||
|
\Log::debug('This accessory requires acceptance');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send an email if the item has a EULA, since the user should always receive it
|
||||||
|
*/
|
||||||
|
if ($this->item->getEula()) {
|
||||||
|
\Log::debug('This accessory has a EULA');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send an email if an email should be sent at checkin/checkout
|
||||||
|
*/
|
||||||
|
if ($this->item->checkin_email()) {
|
||||||
|
\Log::debug('This accessory has a checkin_email()');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
\Log::debug('checkin_email on this category is '.$this->item->checkin_email());
|
||||||
|
|
||||||
return $notifyBy;
|
return $notifyBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +127,7 @@ class CheckinAccessoryNotification extends Notification
|
||||||
*/
|
*/
|
||||||
public function toMail()
|
public function toMail()
|
||||||
{
|
{
|
||||||
|
\Log::debug('to email called');
|
||||||
return (new MailMessage)->markdown('notifications.markdown.checkin-accessory',
|
return (new MailMessage)->markdown('notifications.markdown.checkin-accessory',
|
||||||
[
|
[
|
||||||
'item' => $this->item,
|
'item' => $this->item,
|
||||||
|
|
Loading…
Reference in a new issue