instances added god may help
This commit is contained in:
@@ -39,7 +39,11 @@ class UserLifecycleAuditService
|
||||
'active_changed_at',
|
||||
];
|
||||
|
||||
public static function logDeactivate(
|
||||
public function __construct(private readonly UserLifecycleAuditRepository $userLifecycleAuditRepository)
|
||||
{
|
||||
}
|
||||
|
||||
public function logDeactivate(
|
||||
string $runUuid,
|
||||
string $triggerType,
|
||||
array $policy,
|
||||
@@ -49,7 +53,7 @@ class UserLifecycleAuditService
|
||||
?string $reasonCode = null
|
||||
): bool {
|
||||
try {
|
||||
return UserLifecycleAuditRepository::create(self::buildBaseRow(
|
||||
return $this->userLifecycleAuditRepository->create($this->buildBaseRow(
|
||||
$runUuid,
|
||||
'deactivate',
|
||||
$triggerType,
|
||||
@@ -64,7 +68,7 @@ class UserLifecycleAuditService
|
||||
}
|
||||
}
|
||||
|
||||
public static function logDeleteWithSnapshot(
|
||||
public function logDeleteWithSnapshot(
|
||||
string $runUuid,
|
||||
string $triggerType,
|
||||
array $policy,
|
||||
@@ -72,12 +76,12 @@ class UserLifecycleAuditService
|
||||
array $targetUser
|
||||
): int|false {
|
||||
try {
|
||||
$snapshot = self::buildSnapshot($targetUser);
|
||||
$snapshot = $this->buildSnapshot($targetUser);
|
||||
$json = json_encode($snapshot, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
if (!is_string($json) || $json === '') {
|
||||
if (!is_string($json)) {
|
||||
return false;
|
||||
}
|
||||
$row = self::buildBaseRow(
|
||||
$row = $this->buildBaseRow(
|
||||
$runUuid,
|
||||
'delete',
|
||||
$triggerType,
|
||||
@@ -89,13 +93,13 @@ class UserLifecycleAuditService
|
||||
);
|
||||
$row['snapshot_enc'] = Crypto::encryptString($json);
|
||||
$row['snapshot_version'] = self::SNAPSHOT_VERSION;
|
||||
return UserLifecycleAuditRepository::create($row);
|
||||
return $this->userLifecycleAuditRepository->create($row);
|
||||
} catch (\Throwable $exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function logDeleteFailure(
|
||||
public function logDeleteFailure(
|
||||
string $runUuid,
|
||||
string $triggerType,
|
||||
array $policy,
|
||||
@@ -104,7 +108,7 @@ class UserLifecycleAuditService
|
||||
string $reasonCode
|
||||
): bool {
|
||||
try {
|
||||
return UserLifecycleAuditRepository::create(self::buildBaseRow(
|
||||
return $this->userLifecycleAuditRepository->create($this->buildBaseRow(
|
||||
$runUuid,
|
||||
'delete',
|
||||
$triggerType,
|
||||
@@ -119,7 +123,7 @@ class UserLifecycleAuditService
|
||||
}
|
||||
}
|
||||
|
||||
public static function logRestore(
|
||||
public function logRestore(
|
||||
string $runUuid,
|
||||
string $triggerType,
|
||||
array $policy,
|
||||
@@ -129,7 +133,7 @@ class UserLifecycleAuditService
|
||||
?string $reasonCode = null
|
||||
): bool {
|
||||
try {
|
||||
return UserLifecycleAuditRepository::create(self::buildBaseRow(
|
||||
return $this->userLifecycleAuditRepository->create($this->buildBaseRow(
|
||||
$runUuid,
|
||||
'restore',
|
||||
$triggerType,
|
||||
@@ -144,31 +148,31 @@ class UserLifecycleAuditService
|
||||
}
|
||||
}
|
||||
|
||||
public static function markDeleteEventRestored(int $auditId, int $restoredByUserId, int $restoredUserId): bool
|
||||
public function markDeleteEventRestored(int $auditId, int $restoredByUserId, int $restoredUserId): bool
|
||||
{
|
||||
try {
|
||||
return UserLifecycleAuditRepository::markRestored($auditId, $restoredByUserId, $restoredUserId);
|
||||
return $this->userLifecycleAuditRepository->markRestored($auditId, $restoredByUserId, $restoredUserId);
|
||||
} catch (\Throwable $exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function listPaged(array $filters): array
|
||||
public function listPaged(array $filters): array
|
||||
{
|
||||
return UserLifecycleAuditRepository::listPaged($filters);
|
||||
return $this->userLifecycleAuditRepository->listPaged($filters);
|
||||
}
|
||||
|
||||
public static function find(int $id): ?array
|
||||
public function find(int $id): ?array
|
||||
{
|
||||
return UserLifecycleAuditRepository::find($id);
|
||||
return $this->userLifecycleAuditRepository->find($id);
|
||||
}
|
||||
|
||||
public static function findDeleteEventForRestore(int $id, bool $forUpdate = false): ?array
|
||||
public function findDeleteEventForRestore(int $id, bool $forUpdate = false): ?array
|
||||
{
|
||||
return UserLifecycleAuditRepository::findDeleteEventForRestore($id, $forUpdate);
|
||||
return $this->userLifecycleAuditRepository->findDeleteEventForRestore($id, $forUpdate);
|
||||
}
|
||||
|
||||
public static function decryptSnapshot(array $event): ?array
|
||||
public function decryptSnapshot(array $event): ?array
|
||||
{
|
||||
$enc = trim((string) ($event['snapshot_enc'] ?? ''));
|
||||
if ($enc === '') {
|
||||
@@ -183,21 +187,21 @@ class UserLifecycleAuditService
|
||||
}
|
||||
}
|
||||
|
||||
public static function updateStatus(int $id, string $status, ?string $reasonCode = null): bool
|
||||
public function updateStatus(int $id, string $status, ?string $reasonCode = null): bool
|
||||
{
|
||||
try {
|
||||
return UserLifecycleAuditRepository::updateStatus($id, $status, $reasonCode);
|
||||
return $this->userLifecycleAuditRepository->updateStatus($id, $status, $reasonCode);
|
||||
} catch (\Throwable $exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function purgeExpired(): int
|
||||
public function purgeExpired(): int
|
||||
{
|
||||
return UserLifecycleAuditRepository::purgeOlderThanDays(self::RETENTION_DAYS);
|
||||
return $this->userLifecycleAuditRepository->purgeOlderThanDays(self::RETENTION_DAYS);
|
||||
}
|
||||
|
||||
private static function buildBaseRow(
|
||||
private function buildBaseRow(
|
||||
string $runUuid,
|
||||
string $action,
|
||||
string $triggerType,
|
||||
@@ -226,14 +230,14 @@ class UserLifecycleAuditService
|
||||
'policy_delete_days' => max(0, (int) ($policy['delete_days'] ?? 0)),
|
||||
'actor_user_id' => ($actorUserId ?? 0) > 0 ? (int) $actorUserId : null,
|
||||
'target_user_id' => ((int) ($targetUser['id'] ?? 0)) > 0 ? (int) $targetUser['id'] : null,
|
||||
'target_user_uuid' => self::stringOrNull($targetUser['uuid'] ?? null),
|
||||
'target_user_email' => self::stringOrNull($targetUser['email'] ?? null),
|
||||
'target_user_uuid' => $this->stringOrNull($targetUser['uuid'] ?? null),
|
||||
'target_user_email' => $this->stringOrNull($targetUser['email'] ?? null),
|
||||
'snapshot_enc' => null,
|
||||
'snapshot_version' => self::SNAPSHOT_VERSION,
|
||||
];
|
||||
}
|
||||
|
||||
private static function buildSnapshot(array $targetUser): array
|
||||
private function buildSnapshot(array $targetUser): array
|
||||
{
|
||||
$snapshot = [];
|
||||
foreach (self::SNAPSHOT_FIELDS as $field) {
|
||||
@@ -242,10 +246,9 @@ class UserLifecycleAuditService
|
||||
return $snapshot;
|
||||
}
|
||||
|
||||
private static function stringOrNull(mixed $value): ?string
|
||||
private function stringOrNull(mixed $value): ?string
|
||||
{
|
||||
$value = trim((string) $value);
|
||||
return $value !== '' ? $value : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user