v7.0.0-beta.4 release

This commit is contained in:
HeuJung committed 2026-05-11 11:29:41 +09:00
1 parent 05db17887d
commit 1db039ff34
1545 files changed
+136783 -11634

No files matched your search

@@ -2,102 +2,79 @@
namespace Database\Seeders\Sample;
use App\Enums\NotificationLogStatus;
use App\Models\NotificationLog;
use App\Traits\HasSeederCounts;
use Illuminate\Database\Seeder;
use App\Database\Sample\AbstractNotificationLogSampleSeeder;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Carbon;
/**
* 알림 발송 이력 개발용 시더
* 코어 알림 발송 이력 샘플 시더.
*
* 다양한 채널/타입의 알림 발송 이력 샘플 데이터를 생성합니다.
* 개발/테스트 용도이므로 설치 시 자동 실행되지 않습니다.
* extension_type='core' 인 알림 정의(welcome / reset_password / password_changed)
* 만 사용하여 코어 영역 발송 이력을 채운다. 모듈 알림은 각 모듈 자체 시더에서 처리.
*
* 수동 실행:
* php artisan db:seed --class="Database\Seeders\Sample\NotificationLogSeeder"
* php artisan db:seed --class="Database\Seeders\Sample\NotificationLogSeeder" --count=core_notification_logs=300
*/
class NotificationLogSeeder extends Seeder
class NotificationLogSeeder extends AbstractNotificationLogSampleSeeder
{
use HasSeederCounts;
/**
* 시더 실행.
* 코어 정의만 필터링.
*
* @return void
* @param Builder $query NotificationDefinition 쿼리
* @return Builder 코어 영역 쿼리
*/
public function run(): void
protected function applyDefinitionScope(Builder $query): Builder
{
$count = $this->getSeederCount('notification_logs', 50);
$this->command->info('알림 발송 이력 시딩 시작...');
$channels = ['mail', 'database'];
$types = [
['type' => 'welcome', 'ext_type' => 'core', 'ext_id' => 'core'],
['type' => 'reset_password', 'ext_type' => 'core', 'ext_id' => 'core'],
['type' => 'password_changed', 'ext_type' => 'core', 'ext_id' => 'core'],
['type' => 'order_confirmed', 'ext_type' => 'module', 'ext_id' => 'sirsoft-ecommerce'],
['type' => 'order_shipped', 'ext_type' => 'module', 'ext_id' => 'sirsoft-ecommerce'],
['type' => 'new_comment', 'ext_type' => 'module', 'ext_id' => 'sirsoft-board'],
['type' => 'new_post_admin', 'ext_type' => 'module', 'ext_id' => 'sirsoft-board'],
];
$recipients = $this->getRecipients();
for ($i = 0; $i < $count; $i++) {
$channel = $channels[array_rand($channels)];
$typeInfo = $types[array_rand($types)];
$recipient = $recipients[array_rand($recipients)];
$status = $this->randomStatus();
$sentAt = Carbon::now()->subDays(mt_rand(0, 30))->subHours(mt_rand(0, 23))->subMinutes(mt_rand(0, 59));
NotificationLog::create([
'channel' => $channel,
'notification_type' => $typeInfo['type'],
'extension_type' => $typeInfo['ext_type'],
'extension_identifier' => $typeInfo['ext_id'],
'recipient_identifier' => $channel === 'mail' ? $recipient['email'] : (string) ($i + 1),
'recipient_name' => $recipient['name'],
'subject' => "[G7] {$typeInfo['type']} 알림",
'status' => $status->value,
'error_message' => $status === NotificationLogStatus::Failed ? 'SMTP connection refused' : null,
'source' => 'notification',
'sent_at' => $sentAt,
]);
}
$this->command->info("알림 발송 이력 시딩 완료 ({$count}건)");
return $query->where('extension_type', 'core');
}
/**
* 샘플 수신자 목록.
*
* @return array
* @return string 카운트 옵션 키
*/
private function getRecipients(): array
protected function countKey(): string
{
return 'core_notification_logs';
}
/**
* @return int 기본 건수
*/
protected function defaultCount(): int
{
return 100;
}
/**
* @return string 영역 라벨
*/
protected function scopeLabel(): string
{
return '[코어]';
}
/**
* @return array<string, string>
*/
protected function subjectMap(): array
{
return [
['email' => 'hong@example.com', 'name' => '홍길동'],
['email' => 'kim@example.com', 'name' => '김철수'],
['email' => 'lee@example.com', 'name' => '이영희'],
['email' => 'park@example.com', 'name' => '박민수'],
['email' => 'john@example.com', 'name' => 'John Doe'],
['email' => 'jane@example.com', 'name' => 'Jane Smith'],
'welcome' => '[G7] 회원가입을 환영합니다',
'reset_password' => '[G7] 비밀번호 재설정 안내',
'password_changed' => '[G7] 비밀번호가 변경되었습니다',
];
}
/**
* 가중치 기반 랜덤 상태.
*
* @return NotificationLogStatus
* @return array<string, callable(User, Carbon): string>
*/
private function randomStatus(): NotificationLogStatus
protected function bodyMap(): array
{
$rand = mt_rand(1, 100);
if ($rand <= 80) {
return NotificationLogStatus::Sent;
} elseif ($rand <= 95) {
return NotificationLogStatus::Failed;
}
return NotificationLogStatus::Skipped;
return [
'welcome' => fn (User $u, Carbon $t) => "안녕하세요 {$u->name}님,\n\nG7에 가입해 주셔서 감사합니다.\n다양한 기능을 자유롭게 이용하실 수 있도록 도와드리겠습니다.\n\n감사합니다.\nG7 팀 드림",
'reset_password' => fn (User $u, Carbon $t) => "안녕하세요 {$u->name}님,\n\n비밀번호 재설정 요청이 접수되었습니다.\n아래 링크를 클릭하여 새 비밀번호를 설정해 주세요.\n링크는 30분간 유효합니다.\n\n본인이 요청하지 않으셨다면 이 메일을 무시하셔도 됩니다.",
'password_changed' => fn (User $u, Carbon $t) => "안녕하세요 {$u->name}님,\n\n계정 비밀번호가 정상적으로 변경되었습니다.\n변경 일시: {$t->format('Y-m-d H:i')}\n\n본인이 변경하지 않으셨다면 즉시 고객센터로 문의해 주세요.",
];
}
}