Skip to content

Commit

Permalink
register modules in queue
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Nov 8, 2023
1 parent 111cbb1 commit 244d73e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
5 changes: 5 additions & 0 deletions app/Providers/Queue.php
Expand Up @@ -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.
*
Expand Down Expand Up @@ -52,6 +55,8 @@ public function boot()
}

$company->makeCurrent();

$this->registerModules();
});

app('events')->listen(JobFailed::class, function ($event) {
Expand Down
5 changes: 5 additions & 0 deletions app/Traits/Modules.php
Expand Up @@ -560,4 +560,9 @@ public function getDataKeyOfModules($data = [])

return $result;
}

public function registerModules(): void
{
app(\Akaunting\Module\Contracts\ActivatorInterface::class)->register();
}
}
29 changes: 21 additions & 8 deletions app/Utilities/ModuleActivator.php
Expand Up @@ -27,7 +27,8 @@ public function __construct(Container $app)
{
$this->cache = $app['cache'];
$this->config = $app['config'];
$this->statuses = $this->getStatuses();

$this->load();
}

public function is(Module $module, bool $active): bool
Expand Down Expand Up @@ -99,7 +100,19 @@ public function delete(Module $module): void
$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();
Expand Down Expand Up @@ -146,17 +159,17 @@ public function readDatabase(): array
return $modules;
}

public function reset(): void
public function flushCache(): void
{
$this->statuses = [];
$key = $this->config->get('module.cache.key') . '.statuses';

$this->flushCache();
$this->cache->forget($key);
}

public function flushCache(): void
public function register(): void
{
$key = $this->config->get('module.cache.key') . '.statuses';
$this->load();

$this->cache->forget($key);
app()->register(\Akaunting\Module\Providers\Bootstrap::class, true);
}
}
10 changes: 10 additions & 0 deletions app/Utilities/helpers.php
Expand Up @@ -179,6 +179,16 @@ function running_in_queue(): bool
}
}

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
Expand Down

0 comments on commit 244d73e

Please sign in to comment.