Created
January 21, 2015 20:33
-
-
Save diegograssato/d65daca49a91130f77de to your computer and use it in GitHub Desktop.
loadFixture
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
use Doctrine\Common\DataFixtures\Loader; | |
use Doctrine\Common\DataFixtures\Executor\MongoDBExecutor; | |
use Doctrine\Common\DataFixtures\Purger\MongoDBPurger |
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
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