後,這是我在更新前甚至廣東話閃存更新前的事件
public function preUpdate(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof Order) {
if ($args->hasChangedField('status') && $args->getNewValue('status') == 'stock') {
$this->container->get('activity_logger')->writeLog($entity, 'purchase');
}
}
做到這一點,我有錯誤
FatalErrorException: Error: Maximum execution time of 60 seconds exceeded in /vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line 2498
public function writeLog ($object, $comment)
{
$entity = new Stock();
$entity->setCategory($object->getIsotope()->getCategory()->getId());
$entity->setComment($comment);
$entity->setDate(new \DateTime('now'));
$entity->setUser($object->getUser()->getId());
$entity->setChange(TRUE);
$this->em->persist($entity);
$this->em->flush();
}
有存儲新實體另一種方式?
覺得不是很好的解決方案(做手工),其保存和別碰事件
$sql = "INSERT INTO table (field1, field2) VALUES ('foo', 'var')";
$stmt = $em->getConnection()->prepare($sql);
$stmt->bindValue('invoice', $invoiceId);
$result = $stmt->execute();