프리셋 키 (DeliveryMemoPresetEnum 값과 일치) */ private const PRESET_KEYS = ['door', 'security', 'parcel_box', 'call']; public function name(): string { return 'BackfillDeliveryMemoLabel'; } public function run(UpgradeContext $context): void { if (! Schema::hasTable(self::TABLE) || ! Schema::hasColumn(self::TABLE, 'delivery_memo') || ! Schema::hasColumn(self::TABLE, 'delivery_memo_label')) { $context->logger->info('[ecommerce:1.0.0] delivery_memo_label 백필 — 대상 스키마 부재로 스킵'); return; } $locale = config('app.locale', 'ko'); $labels = $this->presetLabels($locale); $count = 0; DB::table(self::TABLE) ->whereNotNull('delivery_memo') ->where('delivery_memo', '<>', '') ->whereNull('delivery_memo_label') ->orderBy('id') ->chunkById(200, function ($rows) use ($labels, &$count) { foreach ($rows as $row) { $memo = $row->delivery_memo; // 프리셋이면 라벨로, 자유 텍스트면 원문 보존 $label = $labels[$memo] ?? $memo; DB::table(self::TABLE) ->where('id', $row->id) ->update(['delivery_memo_label' => $label]); $count++; } }); $context->logger->info("[ecommerce:1.0.0] delivery_memo_label 백필 완료: {$count} 건 (locale={$locale})"); } /** * 프리셋 키 → 대상 로케일 라벨 맵을 반환합니다. * * @param string $locale 대상 로케일 * @return array 키-라벨 맵 */ private function presetLabels(string $locale): array { $map = []; foreach (self::PRESET_KEYS as $key) { $map[$key] = __('sirsoft-ecommerce::enums.delivery_memo_preset.'.$key, [], $locale); } return $map; } }