Skip to content

Instantly share code, notes, and snippets.

@diegograssato
Created January 21, 2015 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegograssato/d65daca49a91130f77de to your computer and use it in GitHub Desktop.
Save diegograssato/d65daca49a91130f77de to your computer and use it in GitHub Desktop.
loadFixture
use Doctrine\Common\DataFixtures\Loader;
use Doctrine\Common\DataFixtures\Executor\MongoDBExecutor;
use Doctrine\Common\DataFixtures\Purger\MongoDBPurger
public function loadAction()
{
$loader = new Loader();
$loader->loadFromDirectory('module/DTUXFixture/src/DTUXFixture/DataFixture');
$fixtures = $loader->getFixtures();
$entityManager = $this->getServiceLocator()->get('Doctrine\ODM\MongoDB\DocumentManager');
echo " Aplicando Fixtures";
$purger = new MongoDBPurger();
$executor = new MongoDBExecutor($entityManager , $purger);
$executor->execute($fixtures);
// - Preserva dados anteriores
//$executor->execute($fixtures, true);
$total = count($fixtures);
for ($i = 0; $i <= $total; $i++) {
if($i == $total){
echo "\n Fixtures 100% carregadas";
}else{
$sTotal = ($i+1);
echo "\n Carregando ".$sTotal ." - ".get_class($fixtures[$i]) ." : ";
echo ceil((($i/$total)*100))."%";
}
}
echo "\n######### Total de Fixtures aplicada(s): ${total} ##########\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment