when($this->option('tenant'), fn ($q, $id) => $q->whereKey($id)) ->get(); $failed = false; foreach ($tenants as $tenant) { // Même verrou que le bouton du back-office. $lock = Cache::lock("signature-sync:{$tenant->id}", 600); if (! $lock->get()) { $this->warn("{$tenant->name} : synchronisation déjà en cours, ignorée."); continue; } try { $s = $sync->run($tenant, (bool) $this->option('full')); $this->info(sprintf('%s : %d utilisateurs mis à jour, %d retirés, %d groupes, %d appartenances', $tenant->name, $s['users'], $s['removed'], $s['groups'], $s['memberships'])); } catch (Throwable $e) { $failed = true; $this->error("{$tenant->name} : {$e->getMessage()}"); } finally { $lock->release(); } } return $failed ? self::FAILURE : self::SUCCESS; } }