Skip to content

A free open source IT asset/license management system

Another slightly less ugly way for backward compatibility

Tobias Regnery651d1c735b83
diff --git a/app/Models/CompanyableTrait.php b/app/Models/CompanyableTrait.php
index 04a620d8e3..c4b9b89fbf 100644
--- a/app/Models/CompanyableTrait.php
+++ b/app/Models/CompanyableTrait.php
@@ -13,6 +13,13 @@ trait CompanyableTrait
*/
public static function bootCompanyableTrait()
{
- static::addGlobalScope(new CompanyableScope);
+ // In Version 7.0 and before locations weren't scoped by companies, so add a check for the backward compatibility setting
+ if (__CLASS__ != 'App\Models\Location') {
+ static::addGlobalScope(new CompanyableScope);
+ } else {
+ if (Setting::getSettings()->scope_locations_fmcs == 1) {
+ static::addGlobalScope(new CompanyableScope);
+ }
+ }
}
}
diff --git a/app/Models/Location.php b/app/Models/Location.php
index dee2fbd271..6d92e55b44 100755
--- a/app/Models/Location.php
+++ b/app/Models/Location.php
@@ -18,17 +18,8 @@ use Watson\Validating\ValidatingTrait;
class Location extends SnipeModel
{
- function __construct() {
- parent::__construct();
- // This is a workaround for backward compatibility with older versions where locations doesn't get scoped.
- // Normaly we would only add 'use CompanyableTrait;', but this has to be conditional on the setting.
- // So instead of using the trait, add the scope directly if no backward compatibility is used
- if (Setting::getSettings()->scope_locations_fmcs) {
- static::addGlobalScope(new CompanyableScope);
- }
- }
-
use HasFactory;
+ use CompanyableTrait;
protected $presenter = \App\Presenters\LocationPresenter::class;
use Presentable;