major update

This commit is contained in:
2026-03-04 15:56:58 +01:00
parent 16759a2732
commit 8f4dd5840d
478 changed files with 24313 additions and 8201 deletions

View File

@@ -2,8 +2,8 @@
namespace MintyPHP\Service\Auth;
use MintyPHP\DB;
use MintyPHP\Repository\Auth\ApiTokenRepository;
use MintyPHP\Repository\Support\DatabaseSessionRepository;
use MintyPHP\Repository\User\UserReadRepository;
class ApiTokenService
@@ -14,7 +14,8 @@ class ApiTokenService
private readonly UserReadRepository $userReadRepository,
private readonly ApiTokenRepository $apiTokenRepository,
private readonly AuthSettingsGateway $settingsGateway,
private readonly AuthScopeGateway $scopeGateway
private readonly AuthScopeGateway $scopeGateway,
private readonly DatabaseSessionRepository $databaseSessionRepository
) {
}
@@ -139,20 +140,19 @@ class ApiTokenService
$tenantId = null;
}
$db = DB::handle();
$transactionStarted = false;
try {
$db->begin_transaction();
$this->databaseSessionRepository->beginTransaction();
$transactionStarted = true;
if (!$this->apiTokenRepository->revoke($currentTokenId)) {
$db->rollback();
$this->databaseSessionRepository->rollbackTransaction();
return ['ok' => false, 'error' => 'rotate_failed'];
}
$created = $this->create($userId, $name, $tenantId, $expiresAt, $userId);
if (!($created['ok'] ?? false)) {
$db->rollback();
$this->databaseSessionRepository->rollbackTransaction();
$error = (string) ($created['error'] ?? 'rotate_failed');
if ($error === 'invalid_expires_at') {
return ['ok' => false, 'error' => 'invalid_expires_at'];
@@ -163,13 +163,14 @@ class ApiTokenService
return ['ok' => false, 'error' => 'rotate_failed'];
}
$db->commit();
$this->databaseSessionRepository->commitTransaction();
$transactionStarted = false;
$created['tenant_id'] = $tenantId;
return $created;
} catch (\Throwable $exception) {
if ($transactionStarted) {
try {
$db->rollback();
$this->databaseSessionRepository->rollbackTransaction();
} catch (\Throwable $rollbackException) {
// Ignore rollback error and return rotate_failed below.
}