Files
Gnuboard7/app/Console/Commands/Template/ClearTemplateCacheCommand.php
T
HeuJung e819db9d42 fix(core): 공개 템플릿 config 캐시 무효화 누락과 확장 캐시 삭제 경로 동종 결함 정비
공개 config.json 의 고정 캐시 키(template.config.{identifier})가 어떤 갱신
경로에서도 forget 되지 않아 template:update/cache-clear/비활성화/삭제 후에도
최대 1시간(TTL) 이전 manifest 로 응답되던 결함(공개 )을 수정한다.

- TemplateManager::clearTemplateCache 공개화 — config/components_manifest(두
 변종)/현재 버전 routes·language 키 능동 forget, updateTemplate cleanup 호출
- forgetLayoutCacheKeys 가 편집기용 .with_source_meta 변종까지 삭제
- ext.cache_version 쓰기를 incrementExtensionCacheVersion 단일 지점으로 통일
- module/plugin:cache-clear 의 유령 키 forget 을 실재 캐시(레이아웃 서빙/해석
 캐시, 상태 키, 미들웨어 인덱스, 버전 bump) 무효화로 교체
- 공개 routes/language/layout API 의 ?v 생략 폴백을 0 → 현재 버전으로 교정
2026-08-17 13:22:48 +09:00

133 lines
4.3 KiB
PHP

<?php
namespace App\Console\Commands\Template;
use App\Extension\TemplateManager;
use App\Extension\Traits\ClearsTemplateCaches;
use App\Models\Template;
use App\Services\ExtensionBundleService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
class ClearTemplateCacheCommand extends Command
{
use ClearsTemplateCaches;
/**
* The name and signature of the console command.
*/
protected $signature = 'template:cache-clear
{identifier? : 특정 템플릿의 캐시만 삭제 (생략 시 모든 템플릿)}';
/**
* The console command description.
*/
protected $description = '템플릿 관련 캐시를 삭제합니다';
/**
* 템플릿 관리자
*/
public function __construct(
private TemplateManager $templateManager,
private ExtensionBundleService $bundleService
) {
parent::__construct();
}
/**
* Execute the console command.
*/
public function handle(): int
{
$identifier = $this->argument('identifier');
try {
// 템플릿 디렉토리 스캔 및 로드
$this->templateManager->loadTemplates();
if ($identifier) {
// 특정 템플릿 캐시만 삭제
$this->clearSingleTemplateCache($identifier);
} else {
// 모든 템플릿 캐시 삭제
$this->clearAllTemplateCache();
}
return Command::SUCCESS;
} catch (\Exception $e) {
$this->error('❌ '.$e->getMessage());
Log::error('템플릿 캐시 삭제 실패', [
'identifier' => $identifier,
'error' => $e->getMessage(),
]);
return Command::FAILURE;
}
}
/**
* 특정 템플릿의 캐시 삭제
*
* 라이프사이클(update/deactivate/uninstall)과 동일한 무효화 단일 지점
* (`TemplateManager::clearTemplateCache()`)을 경유한다 — 커맨드가 키 목록을
* 별도로 유지하면 키 규약 변경 시 유령 forget 으로 사문화된다 (#588, 공개 #119).
*/
private function clearSingleTemplateCache(string $identifier): void
{
// 템플릿 존재 확인
$template = $this->templateManager->getTemplate($identifier);
if (! $template) {
throw new \Exception(__('templates.errors.not_found', ['template' => $identifier]));
}
$this->info(__('templates.commands.cache_clear.clearing_single', ['template' => $identifier]));
// 고정 키(config/components_manifest) + 현재 버전 routes/language + 레이아웃 캐시
$clearedCount = $this->templateManager->clearTemplateCache($identifier);
// 상태 키(ext.templates.*) + 버전 포함 키 무효화 (버전 bump)
TemplateManager::invalidateTemplateStatusCache();
$this->incrementExtensionCacheVersion();
$this->info('✅ '.__('templates.commands.cache_clear.success_single', [
'template' => $identifier,
'count' => $clearedCount,
]));
Log::info(__('templates.commands.cache_clear.success_single', [
'template' => $identifier,
'count' => $clearedCount,
]));
}
/**
* 모든 템플릿 캐시 삭제
*/
private function clearAllTemplateCache(): void
{
$this->info(__('templates.commands.cache_clear.clearing_all'));
$clearedCount = 0;
// 모든 설치된 템플릿의 캐시 삭제 (설치 레코드 기준 — 라이프사이클과 동일 지점)
foreach (Template::all() as $templateRecord) {
$clearedCount += $this->templateManager->clearTemplateCache($templateRecord->identifier);
}
// 상태 키 + 버전 포함 키 무효화는 전체에서 1회면 충분
TemplateManager::invalidateTemplateStatusCache();
$this->incrementExtensionCacheVersion();
// 확장 프론트엔드 병합 번들 파일 전체 삭제 (템플릿 캐시 정리는 페이지 전면 갱신)
$clearedCount += $this->bundleService->clearBundles();
$this->info('✅ '.__('templates.commands.cache_clear.success_all', [
'count' => $clearedCount,
]));
Log::info(__('templates.commands.cache_clear.success_all', [
'count' => $clearedCount,
]));
}
}