Skip to content

Instantly share code, notes, and snippets.

@jamost
Created April 9, 2015 03:33
Show Gist options
  • Select an option

  • Save jamost/c93c1c4f5f30ff473ef3 to your computer and use it in GitHub Desktop.

Select an option

Save jamost/c93c1c4f5f30ff473ef3 to your computer and use it in GitHub Desktop.
Entity Manager Simulate and Persist Implementation Template (Symfony/Doctrine)
<?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