ldc-boutique-cnc-sable/app/Http/Controllers/Bo/EmployeesController.php

42 lines
1.3 KiB
PHP
Raw Permalink Normal View History

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