mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-07 00:46:59 +01:00
* [ADD] Unit testing. Work in progress
* [MOD] Code refactoring
This commit is contained in:
@@ -299,7 +299,7 @@ class AccountService extends Service implements AccountServiceInterface
|
||||
$this->accountRepository->update($accountRequest);
|
||||
|
||||
$this->updateItems($accountRequest);
|
||||
}, $this->dic);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -392,7 +392,7 @@ class AccountService extends Service implements AccountServiceInterface
|
||||
$accountRequest->key = $pass['key'];
|
||||
|
||||
$this->accountRepository->editPassword($accountRequest);
|
||||
}, $this->dic);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -423,7 +423,7 @@ class AccountService extends Service implements AccountServiceInterface
|
||||
if (!$this->accountRepository->editRestore($historyId, $this->context->getUserData()->getId())) {
|
||||
throw new ServiceException(__u('Error al restaurar cuenta'));
|
||||
}
|
||||
}, $this->dic);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -245,7 +245,7 @@ class AuthTokenService extends Service
|
||||
$this->authTokenRepository->refreshVaultByUserId($itemData->getUserId(), $vault, Hash::hashKey($itemData->getHash()));
|
||||
|
||||
$this->update($itemData, $token);
|
||||
}, $this->dic);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,6 +29,7 @@ use Psr\Container\ContainerInterface;
|
||||
use SP\Config\Config;
|
||||
use SP\Core\Context\ContextInterface;
|
||||
use SP\Core\Events\EventDispatcher;
|
||||
use SP\Storage\Database\Database;
|
||||
|
||||
/**
|
||||
* Class Service
|
||||
@@ -74,4 +75,36 @@ abstract class Service
|
||||
$this->initialize();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bubbles a Closure in a database transaction
|
||||
*
|
||||
* @param \Closure $closure
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ServiceException
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function transactionAware(\Closure $closure)
|
||||
{
|
||||
$database = $this->dic->get(Database::class);
|
||||
|
||||
if ($database->beginTransaction()) {
|
||||
try {
|
||||
$result = $closure->call($this);
|
||||
|
||||
$database->endTransaction();
|
||||
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
$database->rollbackTransaction();
|
||||
|
||||
debugLog('Transaction:Rollback');
|
||||
|
||||
throw $e;
|
||||
}
|
||||
} else {
|
||||
throw new ServiceException(__u('No es posible iniciar una transacción'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,10 +24,8 @@
|
||||
|
||||
namespace SP\Services;
|
||||
|
||||
use DI\Container;
|
||||
use SP\Bootstrap;
|
||||
use SP\DataModel\DataModelInterface;
|
||||
use SP\Storage\Database\Database;
|
||||
|
||||
/**
|
||||
* Trait ServiceItemTrait
|
||||
@@ -54,37 +52,4 @@ trait ServiceItemTrait
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function getAllBasic();
|
||||
|
||||
/**
|
||||
* Bubbles a Closure in a database transaction
|
||||
*
|
||||
* @param \Closure $closure
|
||||
* @param Container $container
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ServiceException
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function transactionAware(\Closure $closure, Container $container)
|
||||
{
|
||||
$database = $container->get(Database::class);
|
||||
|
||||
if ($database->beginTransaction()) {
|
||||
try {
|
||||
$result = $closure->call($this);
|
||||
|
||||
$database->endTransaction();
|
||||
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
$database->rollbackTransaction();
|
||||
|
||||
debugLog('Rollback');
|
||||
|
||||
throw $e;
|
||||
}
|
||||
} else {
|
||||
throw new ServiceException(__u('No es posible iniciar una transacción'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user