Phase 1 - 아카이브 복원 기능: - ArchiveService: 모델별 아카이브 로직 통합 (326줄) - RestoreService: 복원 로직 및 충돌 검사 (319줄) - ArchivedRecordController: restore, checkRestore 메서드 추가 - record_type enum→varchar 마이그레이션 - 복원 버튼 및 충돌 체크 UI (restore-check.blade.php) Phase 2 - 테넌트 필터링: - ArchivedRecord 모델: tenant_id fillable, tenant 관계 추가 - ArchiveService: tenant_id 저장 로직 (determineTenantId) - ArchivedRecordService: 테넌트별 필터링 쿼리 - 목록 UI: ID 컬럼, 대상 테넌트 컬럼 추가 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
105 lines
2.3 KiB
PHP
105 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Archives;
|
|
|
|
use App\Models\Tenants\Tenant;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class ArchivedRecord extends Model
|
|
{
|
|
protected $table = 'archived_records';
|
|
|
|
protected $fillable = [
|
|
'batch_id',
|
|
'batch_description',
|
|
'record_type',
|
|
'tenant_id',
|
|
'original_id',
|
|
'main_data',
|
|
'schema_version',
|
|
'deleted_by',
|
|
'deleted_at',
|
|
'notes',
|
|
];
|
|
|
|
protected $casts = [
|
|
'main_data' => 'array',
|
|
'deleted_at' => 'datetime',
|
|
'original_id' => 'integer',
|
|
'tenant_id' => 'integer',
|
|
'deleted_by' => 'integer',
|
|
];
|
|
|
|
/**
|
|
* 관계: 대상 테넌트
|
|
* NOTE: 삭제된 테넌트를 참조할 수 있어 FK 없음
|
|
*/
|
|
public function tenant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Tenant::class, 'tenant_id');
|
|
}
|
|
|
|
/**
|
|
* 관계: 삭제한 사용자
|
|
*/
|
|
public function deletedByUser(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'deleted_by');
|
|
}
|
|
|
|
/**
|
|
* 관계: 연관 테이블 데이터
|
|
*/
|
|
public function relations(): HasMany
|
|
{
|
|
return $this->hasMany(ArchivedRecordRelation::class, 'archived_record_id');
|
|
}
|
|
|
|
/**
|
|
* Scope: 테넌트 타입만
|
|
*/
|
|
public function scopeTenant($query)
|
|
{
|
|
return $query->where('record_type', 'tenant');
|
|
}
|
|
|
|
/**
|
|
* Scope: 사용자 타입만
|
|
*/
|
|
public function scopeUser($query)
|
|
{
|
|
return $query->where('record_type', 'user');
|
|
}
|
|
|
|
/**
|
|
* 레코드 타입 레이블
|
|
*/
|
|
public function getRecordTypeLabelAttribute(): string
|
|
{
|
|
return match ($this->record_type) {
|
|
'tenant' => '테넌트',
|
|
'user' => '사용자',
|
|
default => $this->record_type,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 메인 데이터 요약
|
|
*/
|
|
public function getMainDataSummaryAttribute(): string
|
|
{
|
|
if (empty($this->main_data)) {
|
|
return '-';
|
|
}
|
|
|
|
$data = $this->main_data;
|
|
$name = $data['name'] ?? $data['title'] ?? '-';
|
|
$id = $data['id'] ?? $this->original_id;
|
|
|
|
return "{$name} (ID: {$id})";
|
|
}
|
|
}
|