diff --git a/lib/SP/Services/Account/AccountService.php b/lib/SP/Services/Account/AccountService.php index 8f5b297f..1153b4eb 100644 --- a/lib/SP/Services/Account/AccountService.php +++ b/lib/SP/Services/Account/AccountService.php @@ -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); + }); } /** diff --git a/lib/SP/Services/AuthToken/AuthTokenService.php b/lib/SP/Services/AuthToken/AuthTokenService.php index 9dd17da1..6cdefa47 100644 --- a/lib/SP/Services/AuthToken/AuthTokenService.php +++ b/lib/SP/Services/AuthToken/AuthTokenService.php @@ -245,7 +245,7 @@ class AuthTokenService extends Service $this->authTokenRepository->refreshVaultByUserId($itemData->getUserId(), $vault, Hash::hashKey($itemData->getHash())); $this->update($itemData, $token); - }, $this->dic); + }); } /** diff --git a/lib/SP/Services/Service.php b/lib/SP/Services/Service.php index da164c5e..b4f903ac 100644 --- a/lib/SP/Services/Service.php +++ b/lib/SP/Services/Service.php @@ -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')); + } + } } \ No newline at end of file diff --git a/lib/SP/Services/ServiceItemTrait.php b/lib/SP/Services/ServiceItemTrait.php index af7940fe..e72bcde8 100644 --- a/lib/SP/Services/ServiceItemTrait.php +++ b/lib/SP/Services/ServiceItemTrait.php @@ -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')); - } - } } \ No newline at end of file