Skip to content

Instantly share code, notes, and snippets.

@MaximStrutinskiy
Last active October 10, 2017 12:31
Show Gist options
  • Save MaximStrutinskiy/30867353ec51f747182faf2b46e65a5a to your computer and use it in GitHub Desktop.
Save MaximStrutinskiy/30867353ec51f747182faf2b46e65a5a to your computer and use it in GitHub Desktop.
Doctrine Bulk Inserts
<?php
foreach ($nominals as $nominal) {
for ($i = 1; $i <= $nominal['code_count']; $i++) {
$code = new Code();
$code->setShop($shop);
$code->setCode($this->GenerateData($codeLength, $codeType, $codePrefix));
$code->setPincode($this->GenerateData($pincodeLength, $pincodeType));
$code->setCodeLiveCikle($codeLiveCikle);
$code->setMinDateActivity($minDateActivity);
$code->setMaxDateActivity($maxDateActivity);
$code->setDateCreated($dateCreate);
if ($nominalStatus) {
$code->setValue($nominal['code_nominal']);
} else {
$code->setValue(0);
};
$app['orm.em']->persist($code);
if (($i % $batchSize) === 0) {
$app['orm.em']->flush();
$app['orm.em']->clear();
}
}
$app['orm.em']->flush();
$app['orm.em']->clear();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment