Skip to content

Commit

Permalink
Merge pull request #176 from gnat42/patch-7
Browse files Browse the repository at this point in the history
split out the code that updates an entity from writeItem function
  • Loading branch information
Baachi committed Mar 26, 2015
2 parents 9add5b2 + 02c45bb commit 57c19a2
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/Ddeboer/DataImport/Writer/DoctrineWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,25 @@ public function writeItem(array $item)
$entity = $this->findOrCreateItem($item);

$this->loadAssociationObjectsToEntity($item, $entity);
$this->updateEntity($item, $entity);

$this->entityManager->persist($entity);

if (($this->counter % $this->batchSize) == 0) {
$this->entityManager->flush();
$this->entityManager->clear($this->entityName);
}

return $this;
}

/**
*
* @param array $item
* @param object $entity
*/
protected function updateEntity(array $item, $entity)
{
$fieldNames = array_merge($this->entityMetadata->getFieldNames(), $this->entityMetadata->getAssociationNames());
foreach ($fieldNames as $fieldName) {

Expand All @@ -213,16 +231,7 @@ public function writeItem(array $item)
$setter = 'set' . ucfirst($fieldName);
$this->setValue($entity, $value, $setter);
}
}

$this->entityManager->persist($entity);

if (($this->counter % $this->batchSize) == 0) {
$this->entityManager->flush();
$this->entityManager->clear($this->entityName);
}

return $this;
}
}

/**
Expand Down

0 comments on commit 57c19a2

Please sign in to comment.