Search code examples
modelsymfony1save

Symfony 1.0.22 object save fails - why? How to debug this?


  public function executeProductAllAccept()
  {
      $this->observation = ObservationPeer::retrieveByPK($this->getRequestParameter('id'));

      $this->forwardUnless((
            $this->observation
        ), 'observation', 'error');

      $this->redirectUnless((
            $this->product
        ), 'observation/error?flag=insufficientrights');    

      $currentTime = date('Y-m-d H:i:s');
      //echo $currentTime.'<br />';

      $this->observation->setIsSentBackToPM(0);
      //echo 'after setIsSentBackToPM'.'<br />';
      $this->observation->setIsPartAccepted(0);
      //echo 'after setIsPartAccepted'.'<br />';
      $this->observation->setIsHold(1);
      //echo 'after setIsHold'.'<br />';
      $this->observation->setCostAllAcceptanceTime($currentTime);
      //echo 'after setCostAllAcceptanceTime'.'<br />';
      $this->observation->save();
      //echo 'after save'.'<br />';
      //exit;
      return $this->redirect('observation/myObservations');
  }

This code returns a blank page. Tried in dev enviroment -> again blank page.

So I added some echo's to test where exacly it's failing. The output was:

2013-06-03 10:40:20
after setIsSentBackToPM
after setIsPartAccepted
after setIsHold
after setCostAllAcceptanceTime

So this clearly fails somewhere when executeing save().

Looked in symfony logs:

  • no errors
  • only [info] about SELECT queries
  • no [info] about SET query (so something fails in save() before symfony tries to execute query)

Looked in apache error logs -> no errors.

So I tried rebuilding the save method -> symfony propel-build-model. But the problem remained. I compared BaseObservation's save method to other model's save methods -> I did not see anything unusual.

I have no idea how to track this down. Any ideas?

EDIT: Updated test:

  public function executeProductAllAccept()
  {
      $this->observation = ObservationPeer::retrieveByPK($this->getRequestParameter('id'));

      echo 'before test plain save'.'<br />';
      $this->observation->save();
      echo 'after test plain save'.'<br />';

      $this->forwardUnless((
            $this->observation
        ), 'observation', 'error');

      $this->redirectUnless((
            $this->product
        ), 'observation/error?flag=insufficientrights');    

      $currentTime = date('Y-m-d H:i:s');
      echo $currentTime.'<br />';

      $this->observation->setIsSentBackToPM(0);
      echo 'after setIsSentBackToPM'.'<br />';
      $this->observation->setIsPartAccepted(0);
      echo 'after setIsPartAccepted'.'<br />';
      $this->observation->setIsHold(1);
      echo 'after setIsHold'.'<br />';
      $this->observation->setCostAllAcceptanceTime($currentTime);
      echo 'after setCostAllAcceptanceTime'.'<br />';
      $this->observation->save();
      echo 'after save'.'<br />';
      exit;
      return $this->redirect('observation/myObservations');
  }

Returns:

before test plain save
after test plain save
2013-06-03 10:40:20
after setIsSentBackToPM
after setIsPartAccepted
after setIsHold
after setCostAllAcceptanceTime

Solution

  • Ok, adding

    error_reporting(E_ALL);
    ini_set('display_errors',TRUE);
    

    Helped to resolve the problem.

    In my case the error was:

    Fatal error: Call to undefined method Observation::setCostAllAcceptanceTime() in /xxxxxxxxxxxxxx/modules/observation/actions/actions.class.php on line 792
    

    Seems like somewhere between update's 3 lines in schema were lost. When I generated new model then methods setCostAllAcceptanceTime (and 2 other) were not generated and that caused the error.