Created
April 9, 2015 03:33
-
-
Save jamost/c93c1c4f5f30ff473ef3 to your computer and use it in GitHub Desktop.
Entity Manager Simulate and Persist Implementation Template (Symfony/Doctrine)
This file contains hidden or 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 WhateverController extends Controller | |
| { | |
| protected $simulate = TRUE; | |
| // ... | |
| /** | |
| * @Route("/data/update") | |
| * @Template() | |
| */ | |
| public function updateDataAction() | |
| { | |
| // (get records and start looping...) | |
| // do stuff... | |
| // queue the updates | |
| $entityManager->persist($address); | |
| $entityManager->persist($addressLink); | |
| // only actually run the database transaction if | |
| // we're not in simulation mode | |
| if (!$this->simulate) | |
| { | |
| $entityManager->flush(); | |
| } | |
| // clear out the saved entities | |
| $entityManager->clear(); | |
| // (next item in loop) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment