Doctrine2插入无声地失败,仅在某些记录上

时间:2012-08-28 18:24:36

标签: php mysql symfony doctrine-orm

我有以下代码,有时会导致无声失败:

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将不会被保存。我不会得到错误或类似的东西。它会默默地失败。

有任何调试建议吗?我想我会试着弄清楚那些特定记录的不同之处,但似乎插件永远不会因任何原因而无声地失败。

0 个答案:

没有答案