Files
sam-manage/app/Models/Audit/TriggerAuditLog.php
권혁성 9eeb62f819 feat: 트리거 감사로그 operation 단위 일괄 롤백 기능
- operation 상세 페이지 및 일괄 롤백 실행 기능 추가
- TriggerAuditLog에 scopeForOperation 스코프 추가
- 트리거 INSERT/UPDATE/DELETE에 operation_id 컬럼 포함
- 감사로그 목록에 작업 단위 링크 컬럼 추가
- 라우트: operation/{id}, batch-rollback 추가

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 11:22:09 +09:00

60 lines
1.4 KiB
PHP

<?php
namespace App\Models\Audit;
use Illuminate\Database\Eloquent\Model;
class TriggerAuditLog extends Model
{
protected $table = 'trigger_audit_logs';
public $timestamps = false;
protected $casts = [
'old_values' => 'array',
'new_values' => 'array',
'changed_columns' => 'array',
'created_at' => 'datetime',
];
/**
* changed_columns에서 NULL 값 제거
*/
public function getChangedColumnsAttribute($value): ?array
{
$decoded = is_string($value) ? json_decode($value, true) : $value;
if (! is_array($decoded)) {
return null;
}
return array_values(array_filter($decoded, fn ($v) => $v !== null));
}
/**
* session_info JSON → array
*/
public function getSessionInfoAttribute($value): ?array
{
if (! $value) {
return null;
}
return is_string($value) ? json_decode($value, true) : $value;
}
public function scopeForTable($query, string $tableName)
{
return $query->where('table_name', $tableName);
}
public function scopeForRecord($query, string $tableName, string $rowId)
{
return $query->where('table_name', $tableName)->where('row_id', $rowId);
}
public function scopeForOperation($query, string $operationId)
{
return $query->where('operation_id', $operationId);
}
}