feat(message_bizppurio): 알림 템플릿 편집 통합·검수 의견·관리탭 개선 및 언어팩 번역 보존 결함군 수정

비즈뿌리오 알림톡 UX 개편 후속:
- 코어/게시판/이커머스 알림 템플릿 [편집] 모달에 확장 채널 편집 영역
 (extension_point 2종 + hidden_template_editor 채널 메타)을 신설하고,
 알림톡 템플릿·문자(SMS)·수신자 규칙을 한 창에서 통합 저장하도록 개정
 (행 하단은 상태 요약 전용, 승인 여부 2단 배지)
- 검수 신청에 검수자 전달 의견(comment) 동봉 — kapi request 로만 전달,
 행에는 저장하지 않음 (FormRequest 신설 + API 문서 백필)
- 관리 탭 모바일 카드뷰·도구줄 코어 관례 통일, 사이트맵 알림 정의
 다국어 라벨 결측 수정 + 코어 정의 라벨 패리티 테스트 신설

언어팩 번역 소실·보존 결함군 (보완 실측 → 커밋 전 점검에서 연쇄 확정,
전부 실패 테스트 선행 후 수정):
- [기본값 복원]이 활성 언어팩 번역(ja)을 영구 소실 → 복원 기본값에
 시딩과 같은 주입기(SSoT)로 팩 로케일 병합 (notification·identity)
- 코어 알림/본인인증 시더의 언어팩 주입 전면 불능 → 주입기가 연관/리스트
 양형태 수용 + identity 시더의 config 복합 키 보존
- 실패한 언어팩 업데이트가 active 팩을 installed 로 방치 → 상태 복원 확장
- 병합·제거의 사용자 수정 보존 판정 사문(연관 전제 isset) → dot-path 판정
 교정, 팩 주입 저장의 user_overrides 오염 차단(시딩 바인딩), 템플릿
 2모델 translatableTrackableFields 선언(beta.4 설계 누락), 같은 프로세스
 활성화 시 시더 번역 필터 stale(캡처 인스턴스 캐시) 교정
- 7.0.9 업그레이드 스텝 신설 — 활성 팩 seed 재동기화로 기설치본의 소실
 번역 자동 복구 (멱등·운영자 수정 보존·팩별 실패 격리)
This commit is contained in:
HeuJung committed 2026-08-24 14:51:37 +09:00
1 parent 40f62e79aa
commit e7fa1b5535
71 files changed
+7155 -8693

No files matched your search

@@ -112,11 +112,13 @@ class RunSeedersOnLanguagePackLifecycle
*/
private function refreshRegistry(): void
{
// Singleton 캐시된 registry/injector 가 stale 활성 팩 목록을 들고 있을 수 있으므로 forget
$this->app->forgetInstance(LanguagePackRegistry::class);
$this->app->forgetInstance(LanguagePackSeedInjector::class);
// boot 시점에 등록된 seed 필터 클로저들은 injector→registry "인스턴스"를 캡처하고 있다.
// forgetInstance 로 바인딩을 교체하면 캡처된 구 인스턴스의 stale 캐시(활성 팩 목록)가
// 그대로 남아, 같은 프로세스에서 활성화된 신규 팩이 코어 시더의 번역 필터에 보이지
// 않는다 (오류 없이 해당 로케일만 미주입). 싱글톤을 유지한 채 내부 캐시만 무효화해
// 캡처된 참조에도 전파한다 (#597 에서 실측·교정).
$registry = $this->app->make(LanguagePackRegistry::class);
$registry->invalidate();
config([
'app.supported_locales' => $registry->getActiveCoreLocales(),
'app.locale_names' => $registry->getLocaleNames(),
@@ -9,17 +9,19 @@ use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
/**
* `core.language_packs.after_activate` / `after_deactivate` 액션 훅을 받아 DB JSON 다국어
* `core.language_packs.activated` / `deactivated` 액션 훅을 받아 DB JSON 다국어
* 컬럼을 동기화하는 thin Listener (G7 표준 HookManager::doAction → addAction 메커니즘).
*
* 영속/도메인 책임은 모두 LanguagePackTranslationRepository 에 위임. 본 클래스는 seed 파일
* 로딩 + Repository 호출 + 감사 로그 라우팅만 수행합니다.
*
* 정책 (계획서 §6.6, §9.4):
* 정책 (계획서 §6.6, §9.4) — 보존 판정은 운영자 수정의 실제 기록 형식인 dot-path
* 항목(`"{컬럼}.{로케일}"`, HasUserOverrides updating 이벤트가 기록)을 기준으로 한다:
* - Case A: 기존 row 의 다국어 JSON 에 해당 locale 키 부재 → 추가
* - Case B: locale 키 존재 + user_overrides 에 컬럼 등록 → 건너뜀 (사용자 수정 보존)
* - Case C: locale 키 존재 + user_overrides 미등록 → 시드 값으로 덮어쓰기
* - 비활성화/제거 시: user_overrides 등록 locale 은 JSON 에서 제거하지 않음
* - Case B: locale 키 존재 + user_overrides 에 `컬럼.로케일` 등록 → 건너뜀 (사용자 수정 보존)
* - Case C: locale 키 존재 + 해당 dot-path 미등록 → 시드 값으로 덮어쓰기
* (컬럼 전체 항목 `"subject"` 등은 시더 재실행 보호 선언이라 팩 병합을 막지 않는다)
* - 비활성화/제거 시: user_overrides 에 `컬럼.로케일` 등록된 locale 은 JSON 에서 제거하지 않음
*/
// audit:allow listener-must-implement-hooklistenerinterface reason: LanguagePackServiceProvider 가 HookManager::addAction 으로 직접 등록하는 명시 등록 패턴 (auto-discovery 대상 아님)
class SyncDatabaseTranslations
+11
View File
@@ -30,6 +30,17 @@ class IdentityMessageTemplate extends Model
'is_active',
];
/**
* 다국어 JSON 컬럼 — 운영자 수정을 dot-path(`"subject.ja"` 등) sub-key 단위로 기록.
* (NotificationTemplate 과 동형 — 미선언의 결과는 그쪽 주석 참조, #597 에서 교정)
*
* @var array<int, string>
*/
protected array $translatableTrackableFields = [
'subject',
'body',
];
/**
* 활동 로그 추적 필드.
*
+21 -7
View File
@@ -27,6 +27,20 @@ class NotificationTemplate extends Model
'is_active',
];
/**
* 다국어 JSON 컬럼 — 운영자 수정을 dot-path(`"subject.ja"` 등) sub-key 단위로 기록.
*
* 미선언 시 수정이 컬럼 전체 항목(`"subject"`)으로 기록되어 시더 재실행이 컬럼을
* 통째로 얼리고(다른 로케일 갱신·신규 팩 로케일 추가 불가), 언어팩 병합의
* 사용자 수정 보존(Case B)도 로케일 단위로 판정할 수 없다 (#597 에서 교정).
*
* @var array<int, string>
*/
protected array $translatableTrackableFields = [
'subject',
'body',
];
/**
* 모델 이벤트 등록 — 템플릿 변경 시 알림 정의 캐시 자동 삭제.
*/
@@ -110,13 +124,6 @@ class NotificationTemplate extends Model
return $this->belongsTo(User::class, 'updated_by');
}
/**
* 특정 채널의 템플릿 조회.
*
* @param Builder $query
* @param string $channel
* @return Builder
*/
/**
* 수신자 규칙이 설정되어 있는지 확인합니다.
*
@@ -127,6 +134,13 @@ class NotificationTemplate extends Model
return ! empty($this->recipients);
}
/**
* 특정 채널의 템플릿 조회.
*
* @param Builder $query
* @param string $channel
* @return Builder
*/
public function scopeByChannel(Builder $query, string $channel): Builder
{
return $query->where('channel', $channel);
@@ -41,29 +41,37 @@ class LanguagePackTranslationRepository implements LanguagePackTranslationReposi
*/
public function applySeedFromPack(LanguagePack $pack, array $seedBundle): array
{
$audit = [];
$locale = $pack->locale;
// 팩 주입은 시딩 컨텍스트다 — 바인딩 없이 저장하면 UserOverridesAwareBuilder 가
// 주입 자체를 "사용자 수정"으로 오인해 user_overrides 를 오염시키고, 그 선언이
// 이후 시더 재실행의 컬럼 갱신을 영구히 얼린다 (#597 에서 실측·교정).
app()->instance('user_overrides.seeding', true);
try {
$audit = [];
$locale = $pack->locale;
if (! empty($seedBundle['permissions'])) {
$this->applyByIdentifier(Permission::class, $pack, $seedBundle['permissions'], $locale, ['name', 'description'], 'identifier', $audit);
}
if (! empty($seedBundle['roles'])) {
$this->applyByIdentifier(Role::class, $pack, $seedBundle['roles'], $locale, ['name', 'description'], 'identifier', $audit);
}
if (! empty($seedBundle['menus']) && $pack->scope !== LanguagePackScope::Plugin->value) {
$this->applyByIdentifier(Menu::class, $pack, $seedBundle['menus'], $locale, ['name'], 'slug', $audit);
}
if (! empty($seedBundle['notifications'])) {
$this->applyNotifications($pack, $seedBundle['notifications'], $locale, $audit);
}
if (! empty($seedBundle['identity_messages'])) {
$this->applyIdentityMessages($pack, $seedBundle['identity_messages'], $locale, $audit);
}
if (! empty($seedBundle['manifest'])) {
$this->applyManifest($pack, $seedBundle['manifest'], $locale, $audit);
}
if (! empty($seedBundle['permissions'])) {
$this->applyByIdentifier(Permission::class, $pack, $seedBundle['permissions'], $locale, ['name', 'description'], 'identifier', $audit);
}
if (! empty($seedBundle['roles'])) {
$this->applyByIdentifier(Role::class, $pack, $seedBundle['roles'], $locale, ['name', 'description'], 'identifier', $audit);
}
if (! empty($seedBundle['menus']) && $pack->scope !== LanguagePackScope::Plugin->value) {
$this->applyByIdentifier(Menu::class, $pack, $seedBundle['menus'], $locale, ['name'], 'slug', $audit);
}
if (! empty($seedBundle['notifications'])) {
$this->applyNotifications($pack, $seedBundle['notifications'], $locale, $audit);
}
if (! empty($seedBundle['identity_messages'])) {
$this->applyIdentityMessages($pack, $seedBundle['identity_messages'], $locale, $audit);
}
if (! empty($seedBundle['manifest'])) {
$this->applyManifest($pack, $seedBundle['manifest'], $locale, $audit);
}
return $audit;
return $audit;
} finally {
app()->forgetInstance('user_overrides.seeding');
}
}
/**
@@ -73,6 +81,23 @@ class LanguagePackTranslationRepository implements LanguagePackTranslationReposi
* @return array<int, array<string, mixed>> 감사 로그 항목
*/
public function stripLocaleFromPack(LanguagePack $pack): array
{
// applySeedFromPack 과 동일 — 제거도 시딩 컨텍스트 (user_overrides 오염 차단)
app()->instance('user_overrides.seeding', true);
try {
return $this->stripLocaleFromPackBody($pack);
} finally {
app()->forgetInstance('user_overrides.seeding');
}
}
/**
* stripLocaleFromPack 의 본문 (시딩 바인딩 하에서 실행).
*
* @param LanguagePack $pack 비활성화된 언어팩
* @return array<int, array<string, mixed>> 감사 로그 항목
*/
private function stripLocaleFromPackBody(LanguagePack $pack): array
{
$audit = [];
$locale = $pack->locale;
@@ -402,7 +427,7 @@ class LanguagePackTranslationRepository implements LanguagePackTranslationReposi
}
$hasLocaleKey = array_key_exists($locale, $current);
$isOverridden = isset($overrides[$column]);
$isOverridden = $this->isColumnLocaleOverridden($overrides, $column, $locale);
if ($hasLocaleKey && $isOverridden) {
$audit[] = [
@@ -413,6 +438,7 @@ class LanguagePackTranslationRepository implements LanguagePackTranslationReposi
'locale' => $locale,
'reason' => 'user_overrides',
];
continue;
}
@@ -443,7 +469,7 @@ class LanguagePackTranslationRepository implements LanguagePackTranslationReposi
continue;
}
if (isset($overrides[$column])) {
if ($this->isColumnLocaleOverridden($overrides, $column, $locale)) {
$audit[] = [
'action' => 'preserved',
'table' => $row->getTable(),
@@ -452,6 +478,7 @@ class LanguagePackTranslationRepository implements LanguagePackTranslationReposi
'locale' => $locale,
'reason' => 'user_overrides',
];
continue;
}
@@ -464,4 +491,27 @@ class LanguagePackTranslationRepository implements LanguagePackTranslationReposi
$row->saveQuietly();
}
}
/**
* 해당 컬럼·로케일이 운영자 수정(user_overrides)으로 보존 대상인지 판정합니다.
*
* 운영자 수정의 실제 기록 형식은 dot-path 리스트(`"{column}.{locale}"` —
* HasUserOverrides 의 updating 이벤트가 기록, beta.4 가 레거시 항목을 dot-path 로
* 전환)이므로 그 형식만 본다. 종전의 `isset($overrides[$column])` 판정은 어떤
* 생산자도 쓰지 않는 연관 형식을 전제해 항상 false 였고, 그 결과 활성화/비활성화가
* 운영자 수정 번역을 오류 없이 덮어쓰거나 제거했다 (#597 에서 발견·교정).
*
* 컬럼 전체 항목(`"subject"` 등)은 의도적으로 보존 사유로 보지 않는다 — 그 형식은
* 시더 재실행(syncFromUpgrade)의 컬럼 보호 선언이며, 팩 병합까지 차단하면 팩
* 업데이트가 자기 로케일 번역을 갱신하지 못하게 된다 (종전에도 차단된 적 없음).
*
* @param array<int, string> $overrides user_overrides 리스트
* @param string $column 다국어 JSON 컬럼명
* @param string $locale 대상 로케일
* @return bool 보존 대상 여부
*/
protected function isColumnLocaleOverridden(array $overrides, string $column, string $locale): bool
{
return in_array($column.'.'.$locale, $overrides, true);
}
}
@@ -7,6 +7,7 @@ use App\Contracts\Repositories\IdentityMessageTemplateRepositoryInterface;
use App\Extension\HookManager;
use App\Models\IdentityMessageDefinition;
use App\Models\IdentityMessageTemplate;
use App\Services\LanguagePack\LanguagePackSeedInjector;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Auth;
@@ -37,6 +38,7 @@ class IdentityMessageTemplateService
private readonly IdentityMessageTemplateRepositoryInterface $repository,
private readonly IdentityMessageDefinitionService $definitionService,
private readonly CacheInterface $cache,
private readonly LanguagePackSeedInjector $seedInjector,
) {}
/**
@@ -271,11 +273,19 @@ class IdentityMessageTemplateService
{
$coreDefinitions = $this->loadCoreMessageDefinitions();
return HookManager::applyFilters(
$definitions = HookManager::applyFilters(
'core.identity.filter_default_message_definitions',
$coreDefinitions,
[]
);
// 활성 언어팩 seed 로케일 병합 — 시딩(seed.identity_messages.translations)과 같은 SSoT.
// 이 병합이 없으면 [기본값 복원]이 팩이 주입해 둔 로케일(ja 등)을 config 의
// ko/en 만으로 대체해 영구 소실시킨다 (notification 쪽 실사례의 동형 — #597 보완 실측).
// injectIdentityMessages 는 string 키('mail.purpose.signup' 등)로 seed 를 매칭하므로
// loadCoreMessageDefinitions 가 config 키를 보존해 넘긴다. 확장 리스너가 정수 키로
// append 한 항목은 seed 에 매칭되지 않아 그대로 통과한다.
return $this->seedInjector->injectIdentityMessages($definitions);
}
/**
@@ -292,13 +302,14 @@ class IdentityMessageTemplateService
$common = $this->commonVariables();
$result = [];
foreach ($messages as $data) {
foreach ($messages as $key => $data) {
if (($data['variables'] ?? null) === '__common__') {
$data['variables'] = $common;
}
$data['extension_type'] = 'core';
$data['extension_identifier'] = 'core';
$result[] = $data;
// config 키('mail.provider_default' 등)를 보존 — 언어팩 seed 매칭 키와 동일 (collectDefaultDefinitions 참조)
$result[$key] = $data;
}
return $result;
@@ -112,7 +112,7 @@ class LanguagePackSeedInjector
}
foreach ($definitions as $defIdx => $def) {
$type = $def['type'] ?? null;
$type = $this->resolveDefinitionType($defIdx, $def);
if (! $type || ! isset($seed[$type])) {
continue;
}
@@ -166,7 +166,7 @@ class LanguagePackSeedInjector
continue;
}
foreach ($definitions as $defIdx => $def) {
$type = $def['type'] ?? null;
$type = $this->resolveDefinitionType($defIdx, $def);
if (! $type || ! isset($seed[$type])) {
continue;
}
@@ -722,4 +722,30 @@ class LanguagePackSeedInjector
return $config;
}
/**
* 정의 배열 항목에서 알림 type 을 해석합니다.
*
* 코어 시더(`loadConfigSeed('core.notification_definitions', ...)`)는 config 원형
* (연관 배열 — 키가 곧 type, 항목에 type 필드 없음)을 그대로 필터에 넘기고,
* 확장 시더(ModuleManager/PluginManager)와 [기본값 복원] 경로는 각 항목에 type
* 필드를 포함한 리스트를 넘긴다. 양쪽 형태를 모두 수용한다 —
* 문자열 키가 있으면 그것이 type 이고, 아니면 항목의 type 필드를 본다.
* (형태 불일치 시 예외 없이 전 항목이 스킵되어 ja 가 조용히 주입되지 않는
* 회귀가 있었다 — 2026-08-24 #597 보완 실측. NotificationSeedInjectionTest 가 고정.)
*
* @param int|string $defIdx 정의 배열의 키
* @param mixed $def 정의 항목
* @return string|null 해석된 type (해석 불가 시 null)
*/
private function resolveDefinitionType(int|string $defIdx, mixed $def): ?string
{
if (is_string($defIdx) && $defIdx !== '') {
return $defIdx;
}
$type = is_array($def) ? ($def['type'] ?? null) : null;
return is_string($type) && $type !== '' ? $type : null;
}
}
+13 -2
View File
@@ -1814,10 +1814,21 @@ class LanguagePackService
}
}
// 상태 복원 (DB 행이 finalizeInstall 에서 status 를 다시 쓰지 않은 경우만)
// 상태 복원 — 파일은 위에서 백업으로 원상 복원되므로 상태도 이전 상태로 되돌린다.
// Updating: 설치 트랜잭션 이전에 실패한 경우.
// Installed: 설치 트랜잭션이 installed 를 기록한 뒤(활성화 단계 이전/도중) 실패한 경우 —
// 여기서 복원하지 않으면 active 였던 팩이 installed 로 방치되어 해당 로케일의
// 백엔드 번역이 오류·로그 없이 통째로 폴백된다 (#597 보완 실측에서 유사 상태 실측).
// 활성화가 성공적으로 끝난 뒤(active) 실패한 경우는 덮어쓰지 않는다.
try {
$current = $this->repository->findByIdentifier($identifier);
if ($current && $current->status === LanguagePackStatus::Updating->value) {
$restorable = [
LanguagePackStatus::Updating->value,
LanguagePackStatus::Installed->value,
];
if ($current
&& $current->status !== $previousStatus
&& in_array($current->status, $restorable, true)) {
$this->repository->update($current, ['status' => $previousStatus]);
}
} catch (Throwable $statusError) {
@@ -7,6 +7,7 @@ use App\Contracts\Repositories\NotificationDefinitionRepositoryInterface;
use App\Contracts\Repositories\NotificationTemplateRepositoryInterface;
use App\Extension\HookManager;
use App\Models\NotificationTemplate;
use App\Services\LanguagePack\LanguagePackSeedInjector;
use Illuminate\Database\Eloquent\Collection;
class NotificationTemplateService
@@ -33,6 +34,7 @@ class NotificationTemplateService
private readonly NotificationTemplateRepositoryInterface $templateRepository,
private readonly NotificationDefinitionRepositoryInterface $definitionRepository,
private readonly CacheInterface $cache,
private readonly LanguagePackSeedInjector $seedInjector,
) {}
/**
@@ -189,6 +191,11 @@ class NotificationTemplateService
['type' => $type, 'channel' => $channel]
);
// 활성 언어팩 seed 로케일 병합 — 시딩(seed.notifications.translations)과 같은 SSoT.
// 이 병합이 없으면 [기본값 복원]이 팩이 주입해 둔 로케일(ja 등)을 config 의
// ko/en 만으로 대체해 영구 소실시킨다 (2026-08-23 실사례 — #597 보완 실측).
$definitions = $this->mergeLanguagePackLocalesIntoDefaults($definitions);
foreach ($definitions as $def) {
if ($def['type'] === $type) {
foreach ($def['templates'] as $tpl) {
@@ -207,6 +214,36 @@ class NotificationTemplateService
return [];
}
/**
* 기본 정의 배열에 활성 언어팩 seed 로케일을 병합합니다.
*
* 코어 소유 정의는 활성 코어 팩(injectNotifications), 확장 소유 정의는
* 해당 확장의 활성 모듈/플러그인 팩(injectExtensionNotifications)이 공급한다.
* definition type 은 전역 고유(UNIQUE)이므로 확장별 호출이 다른 확장의
* 정의에 오병합될 여지는 없다.
*
* @param array<int, array<string, mixed>> $definitions type 필드를 포함한 기본 정의 배열
* @return array<int, array<string, mixed>> 활성 팩 로케일이 병합된 정의 배열
*/
private function mergeLanguagePackLocalesIntoDefaults(array $definitions): array
{
$definitions = $this->seedInjector->injectNotifications($definitions);
$extensionIdentifiers = [];
foreach ($definitions as $def) {
$identifier = is_array($def) ? ($def['extension_identifier'] ?? null) : null;
if (is_string($identifier) && $identifier !== '' && $identifier !== 'core') {
$extensionIdentifiers[$identifier] = true;
}
}
foreach (array_keys($extensionIdentifiers) as $identifier) {
$definitions = $this->seedInjector->injectExtensionNotifications($definitions, $identifier);
}
return $definitions;
}
/**
* 미리보기용 렌더링.
*