diff --git a/app/Providers/Queue.php b/app/Providers/Queue.php index 4b7709f50..659554a10 100644 --- a/app/Providers/Queue.php +++ b/app/Providers/Queue.php @@ -3,12 +3,15 @@ namespace App\Providers; use App\Notifications\Common\ImportFailed; +use App\Traits\Modules; use Illuminate\Queue\Events\JobFailed; use Illuminate\Queue\Events\JobProcessing; use Illuminate\Support\ServiceProvider as Provider; class Queue extends Provider { + use Modules; + /** * Register any application services. * @@ -52,6 +55,8 @@ class Queue extends Provider } $company->makeCurrent(); + + $this->registerModules(); }); app('events')->listen(JobFailed::class, function ($event) { diff --git a/app/Traits/Modules.php b/app/Traits/Modules.php index 582f54276..8382b19e6 100644 --- a/app/Traits/Modules.php +++ b/app/Traits/Modules.php @@ -560,4 +560,9 @@ trait Modules return $result; } + + public function registerModules(): void + { + app(\Akaunting\Module\Contracts\ActivatorInterface::class)->register(); + } } diff --git a/app/Utilities/ModuleActivator.php b/app/Utilities/ModuleActivator.php index d99926822..e56c8363a 100644 --- a/app/Utilities/ModuleActivator.php +++ b/app/Utilities/ModuleActivator.php @@ -27,7 +27,8 @@ class ModuleActivator implements ActivatorInterface { $this->cache = $app['cache']; $this->config = $app['config']; - $this->statuses = $this->getStatuses(); + + $this->load(); } public function is(Module $module, bool $active): bool @@ -99,7 +100,19 @@ class ModuleActivator implements ActivatorInterface $this->flushCache(); } - public function getStatuses(): array + public function reset(): void + { + $this->statuses = []; + + $this->flushCache(); + } + + public function load(): void + { + $this->statuses = $this->getStatusesByCompany(); + } + + public function getStatusesByCompany(): array { if (! $this->config->get('module.cache.enabled')) { return $this->readDatabase(); @@ -146,17 +159,17 @@ class ModuleActivator implements ActivatorInterface return $modules; } - public function reset(): void - { - $this->statuses = []; - - $this->flushCache(); - } - public function flushCache(): void { $key = $this->config->get('module.cache.key') . '.statuses'; $this->cache->forget($key); } + + public function register(): void + { + $this->load(); + + app()->register(\Akaunting\Module\Providers\Bootstrap::class, true); + } } diff --git a/app/Utilities/helpers.php b/app/Utilities/helpers.php index 75d40b29f..8061d1cfb 100644 --- a/app/Utilities/helpers.php +++ b/app/Utilities/helpers.php @@ -179,6 +179,16 @@ if (! function_exists('running_in_queue')) { } } +if (! function_exists('running_in_test')) { + /** + * Detect if application is running in test. + */ + function running_in_test(): bool + { + return env_is_testing() && app()->runningInConsole(); + } +} + if (! function_exists('simple_icons')) { /** * Get the simple icon content