Skip to content

Commit

Permalink
Fixes model visibility (#2580)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
luceos authored Jan 29, 2021
1 parent 843daf6 commit 964f827
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Extend/ModelVisibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 964f827

Please sign in to comment.