I have a Symfony2 CLI script running which should update a timestamp each 3 seconds. The problem is: $this->em->persist($processInfo)
creates a new entry in the DB each time it is executed. I want it to UPDATE, not to CREATE on each cycle.
$processInfo = new ....ProcessInfo();
while(true){
$someObject = new ..();
$this->em()->persist($someObject);
$this->em()->clear(); // sorry forgot this line in my initial question
$processInfo->setLastCheckOn($now); // to know if the script is still running, we set a timestamp in the db
$this->em()->persist($processInfo);
$this->em()->flush();
sleep(3);
}
any ideas?
Use persist
only once. Then you need to commit the active transaction and start a new , in order to tell the database to save them and make a new transaction:
$processInfo = new ....ProcessInfo();
$this->em()->persist($processInfo);
$this->em()->getConnection()->commit();
while(true){
$processInfo->setLastCheckOn($now); // to know if the script is still running, we set a timestamp in the db
$this->em()->flush();
sleep(3);
}