Skip to content

Commit

Permalink
Check extension is enabled before setting listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkwinkelmann committed Nov 13, 2022
1 parent 0ef0826 commit f8eacd4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Extend/Scout.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use ClarkWinkelmann\Scout\ScoutModelWrapper;
use Flarum\Extend\ExtenderInterface;
use Flarum\Extension\Extension;
use Flarum\Extension\ExtensionManager;
use Flarum\Foundation\ContainerUtil;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Events\Dispatcher;
Expand Down Expand Up @@ -123,6 +124,18 @@ public function extend(Container $container, Extension $extension = null)
return;
}

/**
* @var $manager ExtensionManager
*/
$manager = $container->make(ExtensionManager::class);

// By design extensions will always call the extender if Scout is installed without checking if it's enabled
// We could continue setting the container bindings which would just never be used
// But the model scope and event listeners must be skipped if the extension is disabled
if (!$manager->isEnabled('clarkwinkelmann-scout')) {
return;
}

// It looks like we can safely repeat this call, a new scope instance of the same scope class will just
// override the existing scope of the same class
$this->modelClass::addGlobalScope(new FlarumSearchableScope());
Expand Down

0 comments on commit f8eacd4

Please sign in to comment.