From e5b8a293509d8a63f7b9a47b7138cc91404a6a28 Mon Sep 17 00:00:00 2001 From: Deni Date: Tue, 20 Mar 2012 11:19:22 +0400 Subject: [PATCH 1/4] Fix use statements --- DependencyInjection/SimpleThingsTransactionalExtension.php | 1 + SimpleThingsTransactionalBundle.php | 4 ++-- Transactions/Form/RollbackInvalidFormValidator.php | 6 +++--- Transactions/Http/HttpTransactionsListener.php | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/DependencyInjection/SimpleThingsTransactionalExtension.php b/DependencyInjection/SimpleThingsTransactionalExtension.php index 4a4d3f7..065707c 100644 --- a/DependencyInjection/SimpleThingsTransactionalExtension.php +++ b/DependencyInjection/SimpleThingsTransactionalExtension.php @@ -15,6 +15,7 @@ namespace SimpleThings\TransactionalBundle\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\Config\FileLocator; diff --git a/SimpleThingsTransactionalBundle.php b/SimpleThingsTransactionalBundle.php index 5ef2745..6480d47 100644 --- a/SimpleThingsTransactionalBundle.php +++ b/SimpleThingsTransactionalBundle.php @@ -16,7 +16,7 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; -use SimpleThings\TransactionalBundle\DependencyInjection\CompilerPass\DetectConnectionsPass; +use SimpleThings\TransactionalBundle\DependencyInjection\CompilerPass\DetectConnectionPass; class SimpleThingsTransactionalBundle extends Bundle { @@ -24,6 +24,6 @@ public function build(ContainerBuilder $container) { parent::build($container); - $container->addCompilerPass(new DetectConnectionsPass()); + $container->addCompilerPass(new DetectConnectionPass()); } } diff --git a/Transactions/Form/RollbackInvalidFormValidator.php b/Transactions/Form/RollbackInvalidFormValidator.php index 6cfce63..1cfda71 100644 --- a/Transactions/Form/RollbackInvalidFormValidator.php +++ b/Transactions/Form/RollbackInvalidFormValidator.php @@ -11,10 +11,10 @@ * to kontakt@beberlei.de so I can send you a copy immediately. */ -namespace SimpleThingsTransactionalBundle\Transactions\Form; +namespace SimpleThings\TransactionalBundle\Transactions\Form; use Symfony\Component\Form\FormValidatorInterface; -use Symfony\Component\Form\Form; +use Symfony\Component\Form\FormInterface; /** * "Missusing" the FormValidator to set transactions to rollback only when the validation failed. @@ -39,7 +39,7 @@ public function validate(FormInterface $form) } $request = $this->container->get('request'); - if ( ! $form->isValid( && $request->attributes->has('_transaction') ) { + if ( ! $form->isValid() && $request->attributes->has('_transaction') ) { $request->attributes->get('_transaction')->setRollBackOnly(true); } } diff --git a/Transactions/Http/HttpTransactionsListener.php b/Transactions/Http/HttpTransactionsListener.php index dc96edd..00b2ce2 100644 --- a/Transactions/Http/HttpTransactionsListener.php +++ b/Transactions/Http/HttpTransactionsListener.php @@ -19,7 +19,7 @@ use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Log\LoggerInterface; -use Symfony\Component\HttpFoundation\Exceptions\NotFoundHttpException; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use SimpleThings\TransactionalBundle\Transactions\TransactionsRegistry; /** From 4c036a3a6cc410cc2ce5e1ce095194201bf2d9c7 Mon Sep 17 00:00:00 2001 From: Deni Date: Tue, 20 Mar 2012 12:28:40 +0400 Subject: [PATCH 2/4] Extracted dependency of the validator, inject it through the constructor of the form extension --- Resources/config/services.xml | 5 +++++ Transactions/Form/RollbackInvalidFormExtension.php | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 6482de7..36f5f8d 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -35,7 +35,12 @@ + + + + + diff --git a/Transactions/Form/RollbackInvalidFormExtension.php b/Transactions/Form/RollbackInvalidFormExtension.php index 9e374bd..05a5317 100644 --- a/Transactions/Form/RollbackInvalidFormExtension.php +++ b/Transactions/Form/RollbackInvalidFormExtension.php @@ -15,13 +15,19 @@ use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\Form\FormBuilder; -use Symfony\Component\Form\AbstractExtension; -class RollbackInvalidFormExtension extends AbstractExtension +class RollbackInvalidFormExtension extends AbstractTypeExtension { + private $validator; + + public function __construct(RollbackInvalidFormValidator $rollbackValidator) + { + $this->validator = $rollbackValidator; + } + public function buildForm(FormBuilder $builder, array $options) { - $builder->addValidator(new RollbackInvalidFormValidator()); + $builder->addValidator($this->validator); } public function getExtendedType() From ce97a4b40aa94eff51e2322544daafd0fbc3ba0b Mon Sep 17 00:00:00 2001 From: Deni Date: Tue, 20 Mar 2012 14:06:12 +0400 Subject: [PATCH 3/4] Fixes some typo --- Doctrine/ObjectTransactionStatus.php | 2 +- Doctrine/OrmTransactionStatus.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doctrine/ObjectTransactionStatus.php b/Doctrine/ObjectTransactionStatus.php index 0823e6c..9af5c97 100644 --- a/Doctrine/ObjectTransactionStatus.php +++ b/Doctrine/ObjectTransactionStatus.php @@ -72,7 +72,7 @@ public function setRollBackOnly() */ public function isCompleted() { - return $this->isCompleted; + return $this->completed; } /** diff --git a/Doctrine/OrmTransactionStatus.php b/Doctrine/OrmTransactionStatus.php index f64f9b7..e2ec78f 100644 --- a/Doctrine/OrmTransactionStatus.php +++ b/Doctrine/OrmTransactionStatus.php @@ -70,7 +70,7 @@ public function setRollBackOnly() */ public function isCompleted() { - return $this->isCompleted; + return $this->completed; } /** From 2e27d913bf9d077ecbf137cc2d332414679d19dc Mon Sep 17 00:00:00 2001 From: Deni Date: Thu, 22 Mar 2012 12:08:37 +0400 Subject: [PATCH 4/4] Fixed commit ORM transaction --- Doctrine/OrmTransactionStatus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doctrine/OrmTransactionStatus.php b/Doctrine/OrmTransactionStatus.php index e2ec78f..d0e3fe1 100644 --- a/Doctrine/OrmTransactionStatus.php +++ b/Doctrine/OrmTransactionStatus.php @@ -110,8 +110,8 @@ public function commit() if ( ! $this->isRollBackOnly() && $this->manager->getConnection()->getTransactionNestingLevel() == 1) { $this->manager->flush(); + $this->manager->getConnection()->commit(); } - $this->manager->commit(); if ($this->manager->getConnection()->getTransactionNestingLevel() == 0) { $this->completed = true;