Enable Discovery debug logging for production troubleshooting
- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
This commit is contained in:
124
src/Framework/Discovery/Commands/ClearDiscoveryCache.php
Normal file
124
src/Framework/Discovery/Commands/ClearDiscoveryCache.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\Discovery\Commands;
|
||||
|
||||
use App\Framework\Cache\Cache;
|
||||
use App\Framework\Console\ConsoleCommand;
|
||||
use App\Framework\Console\ConsoleInput;
|
||||
use App\Framework\Console\ConsoleOutput;
|
||||
use App\Framework\Core\PathProvider;
|
||||
use App\Framework\DateTime\Clock;
|
||||
use App\Framework\Discovery\DiscoveryCache;
|
||||
|
||||
/**
|
||||
* Unified console commands for clearing discovery-related caches
|
||||
*
|
||||
* Consolidates functionality from both Discovery and Core cache clearing commands:
|
||||
* - discovery:clear-cache: Clear only Discovery service cache
|
||||
* - discovery:clear: Clear all discovery-related caches (Discovery + Routes + Legacy)
|
||||
* - routes:clear: Clear only routes cache
|
||||
*/
|
||||
final readonly class ClearDiscoveryCache
|
||||
{
|
||||
public function __construct(
|
||||
private Cache $cache,
|
||||
private Clock $clock,
|
||||
private ConsoleOutput $output,
|
||||
private PathProvider $pathProvider
|
||||
) {
|
||||
}
|
||||
|
||||
#[ConsoleCommand(name: 'discovery:clear-cache', description: 'Clear Discovery cache')]
|
||||
public function handle(): int
|
||||
{
|
||||
$this->output->writeLine('Clearing Discovery cache...');
|
||||
|
||||
try {
|
||||
$discoveryCache = new DiscoveryCache($this->cache, $this->clock);
|
||||
|
||||
if ($discoveryCache->flush()) {
|
||||
$this->output->writeLine('<success>Discovery cache cleared successfully!</success>');
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
$this->output->writeLine('<error>Failed to clear Discovery cache - flush returned false</error>');
|
||||
|
||||
return 1;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$this->output->writeLine('<error>Failed to clear Discovery cache: ' . $e->getMessage() . '</error>');
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
#[ConsoleCommand(name: 'discovery:clear', description: 'Clear all discovery-related caches')]
|
||||
public function clearAll(): int
|
||||
{
|
||||
$this->output->writeLine('Clearing all discovery-related caches...');
|
||||
|
||||
$success = true;
|
||||
|
||||
// Clear discovery cache
|
||||
$discoveryCache = new DiscoveryCache($this->cache, $this->clock);
|
||||
if ($discoveryCache->flush()) {
|
||||
$this->output->writeLine('✓ Discovery cache cleared');
|
||||
} else {
|
||||
$this->output->writeLine('✗ Failed to clear Discovery cache');
|
||||
$success = false;
|
||||
}
|
||||
|
||||
// Clear legacy cache keys from old Core command
|
||||
$this->cache->forget('discovery_service');
|
||||
$this->cache->forget('unified_discovery_results');
|
||||
$this->output->writeLine('✓ Legacy discovery cache keys cleared');
|
||||
|
||||
// Clear routes cache
|
||||
if ($this->clearRoutesCache()) {
|
||||
$this->output->writeLine('✓ Routes cache cleared');
|
||||
} else {
|
||||
$this->output->writeLine('✗ Failed to clear routes cache');
|
||||
$success = false;
|
||||
}
|
||||
|
||||
if ($success) {
|
||||
$this->output->writeLine('<success>All discovery caches cleared successfully!</success>');
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
$this->output->writeLine('<error>Some caches could not be cleared</error>');
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
#[ConsoleCommand(name: 'routes:clear', description: 'Clear routes cache')]
|
||||
public function clearRoutes(ConsoleInput $input, ConsoleOutput $output): int
|
||||
{
|
||||
if ($this->clearRoutesCache()) {
|
||||
$output->writeLine('<success>Routes cache cleared successfully!</success>');
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
$output->writeLine('<error>Routes cache not found or could not be cleared</error>');
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear routes cache file
|
||||
*/
|
||||
private function clearRoutesCache(): bool
|
||||
{
|
||||
$routesCachePath = $this->pathProvider->resolvePath('/cache/routes.cache.php');
|
||||
|
||||
if (! file_exists($routesCachePath)) {
|
||||
return true; // Consider it success if file doesn't exist
|
||||
}
|
||||
|
||||
return unlink($routesCachePath);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user