Another slightly less ugly way for backward compatibility

Instead of using a constructor, add a special check in the boot-method for locations.
This seems to fit better in the system and does hopefully not break the existing tests.

Signed-off-by: Tobias Regnery <tobias.regnery@gmail.com>
This commit is contained in:
Tobias Regnery
2023-09-13 10:54:23 +02:00
parent 1318dc6111
commit 651d1c735b
2 changed files with 9 additions and 11 deletions
+1 -10
View File
@@ -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;