diff --git a/app/Services/SuperAdminProgramSettingsClient.php b/app/Services/SuperAdminProgramSettingsClient.php index 7f3d956..63ddca1 100644 --- a/app/Services/SuperAdminProgramSettingsClient.php +++ b/app/Services/SuperAdminProgramSettingsClient.php @@ -309,18 +309,48 @@ class SuperAdminProgramSettingsClient $out = []; foreach ($candidates as $host) { - if ($host === '' || in_array($host, $out, true)) { - continue; + foreach ($this->expandDomainAliases($host) as $alias) { + if ($alias === '' || in_array($alias, $out, true)) { + continue; + } + if (in_array($alias, ['localhost', '127.0.0.1', '::1'], true)) { + continue; + } + $out[] = $alias; } - if (in_array($host, ['localhost', '127.0.0.1', '::1'], true)) { - continue; - } - $out[] = $host; } return $out; } + /** + * admin.example.com / www.example.com → example.com هم امتحان شود. + * + * @return list + */ + private function expandDomainAliases(string $host): array + { + $host = $this->normalizeHost($host); + if ($host === '') { + return []; + } + + $aliases = [$host]; + foreach (['www.', 'admin.', 'panel.', 'app.'] as $prefix) { + if (str_starts_with($host, $prefix)) { + $bare = substr($host, strlen($prefix)); + if ($bare !== '') { + $aliases[] = $bare; + } + } + } + if (! str_starts_with($host, 'www.')) { + $aliases[] = 'www.'.$host; + } + + return array_values(array_unique($aliases)); + } + private function normalizeHost(string $value): string { $host = strtolower(trim($value)); diff --git a/app/Services/SuperAdminProgramSettingsOverlay.php b/app/Services/SuperAdminProgramSettingsOverlay.php index dff6848..77d95db 100644 --- a/app/Services/SuperAdminProgramSettingsOverlay.php +++ b/app/Services/SuperAdminProgramSettingsOverlay.php @@ -2,6 +2,8 @@ namespace App\Services; +use App\Models\Setting; + /** * تنظیمات پیشرفته سوپرادمین برای ConfigService و get_settings. * هر درخواست HTTP یک بار از سوپرادمین می‌خواند (memo فقط داخل همان درخواست) — بدون کش Redis. @@ -102,6 +104,9 @@ class SuperAdminProgramSettingsOverlay $items[(string) $key] = (string) $value; } + // در DB لوکال هم بنویس تا اگر درخواست بعدی به سوپرادمین نرسد، منو/فلگ‌ها از آخرین مقدار درست بمانند + $this->persistOwnedToLocal($map); + return [ 'ok' => true, 'count' => count($items), @@ -111,6 +116,39 @@ class SuperAdminProgramSettingsOverlay ]; } + /** + * آخرین مقادیر ۱۴ دسترسی را در settings لوکال ذخیره می‌کند (can_edit=0). + * + * @param array> $map + */ + private function persistOwnedToLocal(array $map): void + { + foreach ($map as $key => $row) { + if (! is_array($row) || ! self::isSuperAdminOwned((string) $key)) { + continue; + } + $value = $row['value'] ?? null; + if ($value === null || $value === '') { + continue; + } + + $setting = Setting::query()->firstOrNew(['key' => (string) $key]); + $setting->value = (string) $value; + $setting->can_edit = 0; + $setting->is_active = 1; + if (Setting::hasTypeColumn()) { + $setting->type = (string) ($row['type'] ?? $setting->type ?? 'switch'); + } + if (! $setting->exists || trim((string) ($setting->title_fa ?? '')) === '') { + $setting->title_fa = (string) ($row['title_fa'] ?? $key); + } + if (array_key_exists('description', $row) && $row['description'] !== null && $row['description'] !== '') { + $setting->description = (string) $row['description']; + } + $setting->save(); + } + } + /** * همهٔ کلیدهای سوپرادمین (حتی value خالی). null = سوپرادمین در دسترس نبود. *