public function addNewStatus(Line $line, TFLLine $TFLLine) { // get the original lineEntity out of the database $lineEntity = $this->entityManager->find('TubeService:Line', $line->getId()); // create a new status for this line $status = new StatusDb(); $status->setLine($lineEntity); $description = null; $descriptions = $TFLLine->getStatusDescriptions(); if ($descriptions) { $description = implode('|', $descriptions); } $status->setDescription($description); $status->setIsDisrupted($TFLLine->isDisrupted()); $status->setTitle($TFLLine->getStatusTitle()); $status->setShortTitle($TFLLine->getStatusShortTitle()); $this->entityManager->persist($status); $this->entityManager->flush(); // use the new status ID to update the line $lineEntity->setLatestStatus($status); $this->entityManager->persist($lineEntity); $this->entityManager->flush(); return $status; }