ldc-boutique-cnc-sable/app/Http/Controllers/Bo/EmployeesController.php
Jérémy Munsch 353b899c3f
refactor(bo): change dispatch method for employee sync job
Updated the dispatch method to use dispatchAfterResponse for the employee sync job.
2026-10-27 09:58:55 +01:00

41 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers\Bo;
use App\Http\Controllers\Controller;
use App\Jobs\FetchAndUpsertArcadiaEmployees;
use App\Services\FlashMessageService;
use Illuminate\Bus\Dispatcher;
use Illuminate\Bus\UniqueLock;
use Illuminate\Contracts\Cache\Repository as CacheRepository;
use Illuminate\Http\RedirectResponse;
class EmployeesController extends Controller
{
public function __construct(
private readonly FlashMessageService $flashMessageService,
private readonly Dispatcher $dispatcher,
private readonly CacheRepository $cacheRepository,
) {
}
public function launchSyncJob(FetchAndUpsertArcadiaEmployees $syncJob): RedirectResponse
{
$this->authorize('dispatchArcadiaRefreshJob', FetchAndUpsertArcadiaEmployees::class);
$uniqueLock = new UniqueLock($this->cacheRepository);
if (! $uniqueLock->acquire($syncJob)) {
$this->flashMessageService->warning(__('An employee sync is already in progress.'));
return to_route('bo.dashboard');
}
$this->dispatcher->dispatchAfterResponse($syncJob);
$this->flashMessageService->success(__('The employee sync job has been dispatched'));
return to_route('bo.dashboard');
}
}