php/src/Core/Config/Console/ConfigPrimeCommand.php
Snider 208cb93c95
All checks were successful
CI / PHP 8.3 (pull_request) Successful in 2m32s
CI / PHP 8.4 (pull_request) Successful in 2m17s
fix(dx): code style fixes, strict_types, and test repair
- Remove non-existent src/Core/Service/ from CLAUDE.md L1 packages list
- Fix LifecycleEventsTest: remove dependency on McpToolHandler interface
  (lives in core-mcp, not needed since McpToolsRegistering stores class
  name strings)
- Run Laravel Pint to fix PSR-12 violations across all source and test files
- Add missing declare(strict_types=1) to 18 PHP files (tests, seeders,
  Layout.php, GenerateServiceOgImages.php)

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-17 09:03:50 +00:00

80 lines
2.2 KiB
PHP

<?php
/*
* Core PHP Framework
*
* Licensed under the European Union Public Licence (EUPL) v1.2.
* See LICENSE file for details.
*/
declare(strict_types=1);
namespace Core\Config\Console;
use Core\Config\ConfigService;
use Core\Tenant\Models\Workspace;
use Illuminate\Console\Command;
class ConfigPrimeCommand extends Command
{
protected $signature = 'config:prime
{workspace? : Workspace slug to prime (omit for all)}
{--system : Prime system config only}';
protected $description = 'Prime the config cache (compute resolution, store in cache)';
public function handle(ConfigService $config): int
{
$workspaceSlug = $this->argument('workspace');
$systemOnly = $this->option('system');
if ($systemOnly) {
$this->info('Priming system config cache...');
$config->prime(null);
$this->info('System config cached.');
return self::SUCCESS;
}
if ($workspaceSlug) {
if (! class_exists(Workspace::class)) {
$this->error('Tenant module not installed. Cannot prime workspace config.');
return self::FAILURE;
}
$workspace = Workspace::where('slug', $workspaceSlug)->first();
if (! $workspace) {
$this->error("Workspace not found: {$workspaceSlug}");
return self::FAILURE;
}
$this->info("Priming config cache for workspace: {$workspace->slug}");
$config->prime($workspace);
$this->info('Workspace config cached.');
return self::SUCCESS;
}
$this->info('Priming config cache for all workspaces...');
if (! class_exists(Workspace::class)) {
$this->warn('Tenant module not installed. Only priming system config.');
$config->prime(null);
$this->info('System config cached.');
return self::SUCCESS;
}
$this->withProgressBar(Workspace::all(), function ($workspace) use ($config) {
$config->prime($workspace);
});
$this->newLine();
$this->info('All config caches primed.');
return self::SUCCESS;
}
}