Skip to content

A free open source IT asset/license management system

Fixed checkin/checkout notification crashing

snipe52848ca8d842
diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php
index c209dac612..ce38d7253c 100644
--- a/app/Listeners/CheckoutableListener.php
+++ b/app/Listeners/CheckoutableListener.php
@@ -57,22 +57,32 @@ class CheckoutableListener
* Notify the user about the checked in checkoutable
*/
public function onCheckedIn($event) {
+
+ \Log::debug('checkin fired');
+
/**
* When the item wasn't checked out to a user, we can't send notifications
*/
if(!$event->checkedOutTo instanceof User) {
+ \Log::debug('checked out to not a user');
return;
}
/**
* Send the appropriate notification
*/
+
+
+ \Log::debug('checked out to a user');
if(!$event->checkedOutTo->locale){
+ \Log::debug('Use default settings locale');
Notification::locale(Setting::getSettings()->locale)->send(
$this->getNotifiables($event),
$this->getCheckinNotification($event)
);
} 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(
$this->getNotifiables($event),
$this->getCheckinNotification($event)
@@ -130,7 +140,9 @@ class CheckoutableListener
*/
private function getCheckinNotification($event) {
- $model = get_class($event->checkoutable);
+ // $model = get_class($event->checkoutable);
+
+
$notificationClass = null;
@@ -145,7 +157,8 @@ class CheckoutableListener
$notificationClass = CheckinLicenseSeatNotification::class;
break;
}
-
+
+ \Log::debug('Notification class: '.$notificationClass);
return new $notificationClass($event->checkoutable, $event->checkedOutTo, $event->checkedInBy, $event->note);
}
diff --git a/app/Models/Loggable.php b/app/Models/Loggable.php
index 61b79d3a75..501b5057ca 100644
--- a/app/Models/Loggable.php
+++ b/app/Models/Loggable.php
@@ -122,38 +122,38 @@ trait Loggable
$log->logaction('checkin from');
- $params = [
- 'target' => $target,
- 'item' => $log->item,
- 'admin' => $log->user,
- 'note' => $note,
- 'target_type' => $log->target_type,
- 'settings' => $settings,
- ];
-
-
- $checkinClass = null;
-
- if (method_exists($target, 'notify')) {
- try {
- $target->notify(new static::$checkinClass($params));
- } catch (\Exception $e) {
- \Log::debug($e);
- }
-
- }
-
- // Send to the admin, if settings dictate
- $recipient = new \App\Models\Recipients\AdminRecipient();
-
- if (($settings->admin_cc_email!='') && (static::$checkinClass!='')) {
- try {
- $recipient->notify(new static::$checkinClass($params));
- } catch (\Exception $e) {
- \Log::debug($e);
- }
-
- }
+// $params = [
+// 'target' => $target,
+// 'item' => $log->item,
+// 'admin' => $log->user,
+// 'note' => $note,
+// 'target_type' => $log->target_type,
+// 'settings' => $settings,
+// ];
+//
+//
+// $checkinClass = null;
+//
+// if (method_exists($target, 'notify')) {
+// try {
+// $target->notify(new static::$checkinClass($params));
+// } catch (\Exception $e) {
+// \Log::debug($e);
+// }
+//
+// }
+//
+// // Send to the admin, if settings dictate
+// $recipient = new \App\Models\Recipients\AdminRecipient();
+//
+// if (($settings->admin_cc_email!='') && (static::$checkinClass!='')) {
+// try {
+// $recipient->notify(new static::$checkinClass($params));
+// } catch (\Exception $e) {
+// \Log::debug($e);
+// }
+//
+// }
return $log;
}
diff --git a/app/Notifications/CheckinAccessoryNotification.php b/app/Notifications/CheckinAccessoryNotification.php
index 2f6b5a5685..cc712e271d 100644
--- a/app/Notifications/CheckinAccessoryNotification.php
+++ b/app/Notifications/CheckinAccessoryNotification.php
@@ -26,6 +26,7 @@ class CheckinAccessoryNotification extends Notification
$this->admin = $checkedInby;
$this->note = $note;
$this->settings = Setting::getSettings();
+ \Log::debug('Constructor for notification fired');
}
/**
@@ -35,23 +36,63 @@ class CheckinAccessoryNotification extends Notification
*/
public function via()
{
-
+ \Log::debug('via called');
$notifyBy = [];
if (Setting::getSettings()->slack_endpoint) {
$notifyBy[] = 'slack';
}
+ if (Setting::getSettings()->slack_endpoint!='') {
+ $notifyBy[] = 'slack';
+ }
+
+
/**
- * Only send checkin notifications to users if the category
- * has the corresponding checkbox checked.
+ * Only send notifications to users that have email addresses
*/
- if ($this->item->checkin_email() && $this->target instanceof User && $this->target->email != '')
- {
- \Log::debug('use email');
- $notifyBy[] = 'mail';
+ 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;
}
@@ -86,6 +127,7 @@ class CheckinAccessoryNotification extends Notification
*/
public function toMail()
{
+ \Log::debug('to email called');
return (new MailMessage)->markdown('notifications.markdown.checkin-accessory',
[
'item' => $this->item,