user->id) ->where('legacy_code', $legacy) ->first(); if ($mapRec) { $meta = is_array($mapRec->meta) ? $mapRec->meta : []; if (!$targetStabileId) { $mappedId = data_get($meta, 'target_stabile_id'); if ($mappedId) { $targetStabileId = (int) $mappedId; } } if (!$targetStabileCode) { $mappedCode = data_get($meta, 'target_stabile_code'); if ($mappedCode) { $targetStabileCode = (string) $mappedCode; } } if (!$splitMode) { $mappedSplit = data_get($meta, $filtersKey . '.split_mode'); if (is_string($mappedSplit) && $mappedSplit !== '') { $splitMode = $mappedSplit; } } $targetAdminId = data_get($meta, 'target_admin_id'); $targetAdminId = $targetAdminId ? (int) $targetAdminId : null; if ($mapCallback) { [$targetStabileId, $targetStabileCode, $splitMode, $targetAdminId] = $mapCallback( $meta, [$targetStabileId, $targetStabileCode, $splitMode, $targetAdminId] ); } } } catch (Throwable $e) { $targetAdminId = null; } return [$targetStabileId, $targetStabileCode, $splitMode, $targetAdminId]; } protected function canTargetAdmin(ImportContext $context, int $targetAdminId): bool { if ($context->isSuperAdmin) { return true; } return $context->currentAmministratore && $context->currentAmministratore->id === $targetAdminId; } protected function persistMappingMeta( ImportContext $context, string $legacy, ?int $targetStabileId, ?string $targetStabileCode, ?int $targetAdminId, array $filters, string $filtersKey ): void { try { $mapping = GesconImportMapping::firstOrCreate( ['user_id' => $context->user->id, 'legacy_code' => $legacy], ['status' => 'pending'] ); $meta = is_array($mapping->meta) ? $mapping->meta : []; if ($targetStabileId !== null) { $meta['target_stabile_id'] = $targetStabileId; } else { unset($meta['target_stabile_id']); } if ($targetStabileCode !== null) { $meta['target_stabile_code'] = $targetStabileCode; } else { unset($meta['target_stabile_code']); } if ($targetAdminId) { $meta['target_admin_id'] = $targetAdminId; } else { unset($meta['target_admin_id']); } $meta[$filtersKey] = $filters; $mapping->meta = $meta; $mapping->save(); } catch (Throwable $e) { // best-effort } } protected function buildArtisanParams(array $options): array { $params = []; foreach ($options as $key => $value) { if ($value === null || $value === '' || $value === false) { continue; } if ($value === true) { $params[$key] = true; } else { $params[$key] = $value; } } return $params; } }