Created
August 31, 2012 01:52
-
-
Save jonathaningram/3547674 to your computer and use it in GitHub Desktop.
Doctrine service method to create a user that inserts a user so should use master connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Service | |
{ | |
public function createUser(UserInterface $user) | |
{ | |
$em = $this->getEntityManager(); | |
$conn = $em->getConnection(); | |
$conn->beginTransaction(); | |
try { | |
$em->persist($user); | |
$em->flush(); | |
$conn->commit(); | |
} catch (\Exception $e) { | |
if ($conn->isTransactionActive()) { | |
$conn->rollback(); | |
} | |
$em->close(); | |
throw $e; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment