Skip to content

Instantly share code, notes, and snippets.

@dyangrev
Created March 26, 2014 19:46
Show Gist options
  • Save dyangrev/9791630 to your computer and use it in GitHub Desktop.
Save dyangrev/9791630 to your computer and use it in GitHub Desktop.
199 $em = $this->getEntityManager();
200 try {
201 $em->getConnection()->beginTransaction(); //according http://stackoverflow.com/a/16271223, transaction automatically releases row-level write lock
202 $stays = $this->findMatchingGuestStayImports($property, $importedGuestStay, true /* lock records */);
203 /**
204 * @var GuestStay $firstStay
205 */
206 $firstStay = reset($stays);
207 if (count($stays) > 1) {
208 $em->getConnection()->commit();
209 return self::STATUS_RECORD_NOT_CREATED;
210 } else if (count($stays) == 1) {
211 $status = self::STATUS_RECORD_NOT_CREATED;
212 $firstStay->updateFromNewGuestStay($importedGuestStay, $em);
213 $em->persist($firstStay);
214 $status = self::STATUS_RECORD_UPDATED; //todo - update should return bool of whether stay was updated
215 $em->getConnection()->commit();
216 $em->flush();
217 return $status;
218
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment