From edb81425cfecf5b90163cdbbc972a9abaae15131 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 28 Mar 2018 18:53:03 -0700 Subject: [PATCH] Fixed component checkout bug (#5282) --- app/Models/Asset.php | 2 +- app/Models/Component.php | 8 ++++++++ app/Models/Loggable.php | 17 +++++++++-------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 0e5121dd83..e7279ebd61 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -24,7 +24,7 @@ use App\Notifications\CheckoutAssetNotification; class Asset extends Depreciable { protected $presenter = 'App\Presenters\AssetPresenter'; - use Loggable, Requestable, Presentable, Notifiable, SoftDeletes, ValidatingTrait, UniqueUndeletedTrait; + use Loggable, Requestable, Presentable, SoftDeletes, ValidatingTrait, UniqueUndeletedTrait; const LOCATION = 'location'; const ASSET = 'asset'; diff --git a/app/Models/Component.php b/app/Models/Component.php index 38610277bb..f7b9bb9fcd 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -19,6 +19,14 @@ class Component extends SnipeModel protected $dates = ['deleted_at', 'purchase_date']; protected $table = 'components'; + + /** + * Set static properties to determine which checkout/checkin handlers we should use + */ + public static $checkoutClass = null; + public static $checkinClass = null; + + /** * Category validation rules */ diff --git a/app/Models/Loggable.php b/app/Models/Loggable.php index cd392f51b7..1a8cf3676a 100644 --- a/app/Models/Loggable.php +++ b/app/Models/Loggable.php @@ -73,16 +73,16 @@ trait Loggable 'settings' => $settings, ]; - - // Send to the admin, if settings dictate - $recipient = new \App\Models\Recipients\AdminRecipient(); - + $checkoutClass = null; if (method_exists($target, 'notify')) { $target->notify(new static::$checkoutClass($params)); } - if ($settings->admin_cc_email!='') { + // Send to the admin, if settings dictate + $recipient = new \App\Models\Recipients\AdminRecipient(); + + if (($settings->admin_cc_email!='') && (static::$checkoutClass!='')) { $recipient->notify(new static::$checkoutClass($params)); } @@ -140,8 +140,6 @@ trait Loggable 'settings' => $settings, ]; - // Send to the admin, if settings dictate - $recipient = new \App\Models\Recipients\AdminRecipient(); $checkoutClass = null; @@ -149,7 +147,10 @@ trait Loggable $target->notify(new static::$checkinClass($params)); } - if ($settings->admin_cc_email!='') { + // Send to the admin, if settings dictate + $recipient = new \App\Models\Recipients\AdminRecipient(); + + if (($settings->admin_cc_email!='') && (static::$checkoutClass!='')) { $recipient->notify(new static::$checkinClass($params)); }