1

我有以下代码,有时会导致静默失败:

public function updateCoreGameTableIfNecessary($coreEm)
{   
    $game = $this->getCoreGameRecord($coreEm);

    if (!$game) {

        $game = new Game();
        $game->setHomeSchool($this->getHomeSchool()->getCoreSchool($coreEm));
        $game->setDatetime($this->getDatetime()->format('Y-m-d H:i:s'));
        $game->setDate($this->getDatetime()->getTimestamp());
        $game->setTime($this->getDatetime()->format('H:i:s'));
        $game->setSport($coreEm->getRepository('VNNCoreBundle:Sport')->findOneByName($this->getSport()->getName()));
        $game->setSeason($coreEm->getRepository('VNNCoreBundle:Season')->findCurrent());
        $game->setEventType(strtolower($this->getEventType()->getName()));
        $game->setMeetName($this->getMeetName());
        $game->setRemoteUnique(md5(rand(0, 100000)));
        $game->setNotes($this->getRecap());
        $game->setHomeConfId(0); // This field is no longer used, so value doesn't matter.
        $game->setAwayConfId(0); // This field is no longer used, so value doesn't matter.
        $game->setConfStatus(''); // This field is going away as well.
    }   

    if ($this->getEventType()->getName() == 'Game') {
        $game->setHomeScore($this->getHomeScore());
        $game->setAwayScore($this->getAwayScore());
        $game->setAwaySchool($this->getAwaySchool()->getCoreSchool($coreEm));
    } else {
        $game->setPlace($this->getPlace());
        $game->setPoints($this->getHomeScore());
    }   

    $game->setOwnerId($this->getUser()->getSchool()->getCoreSchool($coreEm)->getId());
    $coreEm->persist($game);
    $coreEm->flush();

    return $game->getId();
}   

它总是从一个$this已经保存的开始。对于某些实例$this(即数据库中的某些记录),$game不会被保存。我不会得到错误或类似的东西。它只会默默地失败。

有什么调试建议吗?我想我会尝试找出这些特定记录的不同之处,但无论出于何种原因,插入似乎都不应该默默地失败。

4

0 回答 0