public function updatePerson($em, $entity) { if ($entity instanceof Cast || $entity instanceof Crew) { $id = $entity->getPersonId(); $people = $this->tmdb->load($id); if (!$this->existPerson($id, $em)) { $person = new Person(); $person->setId($people->getId())->setAdult($people->getAdult())->setAka($people->getAlsoKnownAs())->setBiography($people->getBiography())->setBirthday($people->getBirthday())->setDeathday($people->getDeathday())->setHomepage($people->getHomepage())->setName($people->getName())->setPlaceOfBirth($people->getPlaceOfBirth())->setProfilePath($people->getProfilePath()); $uow = $em->getUnitOfWork(); $cmf = $em->getMetadataFactory(); $meta = $cmf->getMetadataFor(get_class($person)); $em->persist($person); $uow->computeChangeSet($meta, $person); } } }
public function createPerson($peopleToAdd) { // Define the size of record, the frequency for persisting the data and the current index of records $batchSize = $this->getBatchSizePersonManager(); $i = 1; if (!empty($peopleToAdd)) { foreach ($peopleToAdd as $id => $name) { $tmdbPerson = $this->getTmdbPerson($id); $person = new Person(); $person->hydrate($tmdbPerson); $this->persist($person); // Each x import persisted we flush everything if ($i % $batchSize === 0) { $this->flush(); $this->clear($person); } $i++; } } }