From b6e3715cd80a91ae31f82f222791aae2a46cd521 Mon Sep 17 00:00:00 2001 From: Till Deeke Date: Fri, 20 Jul 2018 22:22:49 +0200 Subject: [PATCH 1/3] Fix: No Notifications for checking out Consumables (#5898) * Adds a method to consumables to check if a notification should be sent Adds the checkin_email method to Consumables, this gets checked in notifications when checking out the consumable. Without the method, no notifications get sent for checking out consumables. * Fixes the checkin_email method on the License model This should allow the License to also send checkout/checkin notifications again. --- app/Models/Consumable.php | 4 ++++ app/Models/License.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Models/Consumable.php b/app/Models/Consumable.php index 23487c5ba8..7f61c895f1 100644 --- a/app/Models/Consumable.php +++ b/app/Models/Consumable.php @@ -156,6 +156,10 @@ class Consumable extends SnipeModel return $this->belongsToMany('\App\Models\User', 'consumables_users', 'consumable_id', 'assigned_to')->count(); } + public function checkin_email() + { + return $this->category->checkin_email; + } public function requireAcceptance() { diff --git a/app/Models/License.php b/app/Models/License.php index 559b48ebe8..9685b4b8f6 100755 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -228,7 +228,7 @@ class License extends Depreciable public function checkin_email() { - return $this->model->category->checkin_email; + return $this->category->checkin_email; } public function requireAcceptance() From 45a2932f4bc87647ff3dd56a79685e1400ff673a Mon Sep 17 00:00:00 2001 From: Till Deeke Date: Fri, 20 Jul 2018 22:23:29 +0200 Subject: [PATCH 2/3] Fixes the generation of where conditions (#5902) --- app/Models/Traits/Searchable.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/Models/Traits/Searchable.php b/app/Models/Traits/Searchable.php index b6438b824d..01c20febda 100644 --- a/app/Models/Traits/Searchable.php +++ b/app/Models/Traits/Searchable.php @@ -68,6 +68,8 @@ trait Searchable { $table = $this->getTable(); + $firstConditionAdded = false; + foreach($this->getSearchableAttributes() as $column) { foreach($terms as $term) { @@ -80,6 +82,19 @@ trait Searchable { continue; } + /** + * We need to form the query properly, starting with a "where", + * otherwise the generated select is wrong. + * + * @todo This does the job, but is inelegant and fragile + */ + if (!$firstConditionAdded) { + $query = $query->where($table . '.' . $column, 'LIKE', '%'.$term.'%'); + + $firstConditionAdded = true; + continue; + } + $query = $query->orWhere($table . '.' . $column, 'LIKE', '%'.$term.'%'); } } From e1c095adca789977a100ee25b5eb208033994cd6 Mon Sep 17 00:00:00 2001 From: Till Deeke Date: Fri, 20 Jul 2018 22:23:44 +0200 Subject: [PATCH 3/3] Removes the typehint for search term string (#5904) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The „string“ typehint only works in PHP >= 7.0.0. Since we are still supporting versions below that, remove the type hint. --- app/Models/Traits/Searchable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Traits/Searchable.php b/app/Models/Traits/Searchable.php index 01c20febda..96e88f7cb5 100644 --- a/app/Models/Traits/Searchable.php +++ b/app/Models/Traits/Searchable.php @@ -53,7 +53,7 @@ trait Searchable { * @param string $search The search term * @return array An array of search terms */ - private function prepeareSearchTerms(string $search) { + private function prepeareSearchTerms($search) { return explode(' OR ', $search); }