Files
sam-api/app/Traits/LockCheckTrait.php

46 lines
1.3 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Traits;
use App\Exceptions\BusinessException;
use App\Models\ItemMaster\EntityRelationship;
/**
* LockCheckTrait - 엔티티 잠금 체크 공통 로직
*
* 연결(entity_relationships) is_locked가 true인 경우:
* - 해당 연결 해제 불가
* - 연결된 자식 엔티티 삭제 불가 (연결을 통한 보호)
*/
trait LockCheckTrait
{
/**
* 엔티티 삭제 가능 여부 체크
* 잠금된 연결이 있으면 삭제 불가
*
* @throws BusinessException 잠금된 연결이 있는 경우
*/
protected function checkCanDelete(string $entityType, int $entityId): void
{
if (EntityRelationship::hasLockedParentRelationship($entityType, $entityId)) {
throw new BusinessException(__('error.entity_protected_by_locked_relationship'));
}
}
/**
* 엔티티의 잠금 상태 조회 (API Response용)
*/
protected function getEntityLockStatus(string $entityType, int $entityId): array
{
return EntityRelationship::getChildLockStatus($entityType, $entityId);
}
/**
* 엔티티가 잠금 상태인지 확인 (연결을 통한 잠금 포함)
*/
protected function isEntityLocked(string $entityType, int $entityId): bool
{
return EntityRelationship::hasLockedParentRelationship($entityType, $entityId);
}
}