From 8dbd234e7d1466fa317c503183d1f2c0616b2105 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Thu, 28 Jan 2021 12:55:33 +0100 Subject: [PATCH] Fixes model visibility Model Visibility extender does not take into consideration missing dependencies. For instance flarum/tags adds a policy on the Flag model from flarum/flags. But because flarum/flags might as well not be installed we need to check for the existence of that model. Otherwise the exception is thrown or flarum fails to boot. --- src/Extend/ModelVisibility.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Extend/ModelVisibility.php b/src/Extend/ModelVisibility.php index 92e81e6d1b..3313b0ea8f 100644 --- a/src/Extend/ModelVisibility.php +++ b/src/Extend/ModelVisibility.php @@ -44,7 +44,7 @@ public function __construct(string $modelClass) { $this->modelClass = $modelClass; - if (! method_exists($modelClass, 'registerVisibilityScoper')) { + if (class_exists($this->modelClass) && ! is_callable([$modelClass, 'registerVisibilityScoper'])) { throw new Exception("Model $modelClass cannot be visibility scoped as it does not use Flarum\Database\ScopeVisibilityTrait."); } } @@ -89,6 +89,10 @@ public function scopeAll($callback) public function extend(Container $container, Extension $extension = null) { + if (! class_exists($this->modelClass)) { + return; + } + foreach ($this->scopers as $ability => $scopers) { foreach ($scopers as $scoper) { $this->modelClass::registerVisibilityScoper(ContainerUtil::wrapCallback($scoper, $container), $ability);